You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
name: Docker Build and Test
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- master
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# Checkout the repository
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v2
|
|
|
|
# Set up Docker Buildx (optional, for multi-platform support)
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
# Cache Docker layers to speed up builds (optional)
|
|
- name: Cache Docker layers
|
|
uses: actions/cache@v2
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-
|
|
|
|
# Build Docker image from the root directory
|
|
- name: Build Docker image
|
|
id: build_image
|
|
run: |
|
|
IMAGE_TAG="test-runner:swarm-testing-${GITHUB_SHA}"
|
|
docker build -t $IMAGE_TAG .
|
|
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
|
|
|
|
# Ensure logs directory exists and has correct permissions
|
|
- name: Ensure logs directory exists
|
|
run: |
|
|
mkdir -p ${{ github.workspace }}/logs
|
|
chmod -R 777 ${{ github.workspace }}/logs
|
|
|
|
# Run Docker container with OpenAI API Key securely and capture test logs
|
|
- name: Run Docker container with OpenAI API Key
|
|
run: |
|
|
docker run -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
|
|
-v ${{ github.workspace }}/logs:/usr/src/app/logs \
|
|
${{ env.IMAGE_TAG }} \
|
|
bash -c "pytest /usr/src/app/tests --continue-on-collection-errors --tb=short --disable-warnings | tee /usr/src/app/logs/test_logs.txt"
|
|
|
|
# Print the test logs to the console
|
|
- name: Print test logs
|
|
run: |
|
|
cat ${{ github.workspace }}/logs/test_logs.txt || echo "No test logs found"
|