fix to build and run ci/cd, 6th attempt #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Build and Test | |
on: | |
push: | |
branches: | |
- main | |
- master # Added to include the master branch as well | |
pull_request: | |
branches: | |
- main | |
- master # Added to include pull requests targeting the main/master branch | |
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 in the GitHub workspace | |
- name: Ensure logs directory exists | |
run: | | |
mkdir -p ${{ github.workspace }}/logs | |
# Run Docker container with OpenAI API Key securely and append test results to 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 >> /usr/src/app/logs/test_logs.txt 2>&1" |