Skip to content

Commit

Permalink
Update coverage-workflow.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Garima Ketan Chauhan authored and GitHub Enterprise committed Apr 2, 2025
1 parent 5e04722 commit ac612d3
Showing 1 changed file with 39 additions and 66 deletions.
105 changes: 39 additions & 66 deletions .github/workflows/coverage-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,47 @@
name: Coverage workflow
name: Backend Test with Coverage

on:
push:
branches:
- gargi-production # Trigger only for production branch
branches: gargi-production
pull_request:
branches: gargi-production

jobs:
deploy:
test:
runs-on: self-hosted
env:
REPO_NAME: ${{ github.event.repository.name }}
COMPOSE_FILE: docker-compose.yml
defaults:
run:
working-directory: ./backend # All commands run from here

steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v3

# Step 2: Dotenv Action
- name: Dotenv Action
uses: falti/dotenv-action@v1.1.4
with:
export-variables: true
keys-case: bypass

# Step 3: Build Docker image for tests
- name: Build Docker image for tests
working-directory: backend
run: |
docker build -t coverage-test -f tests/Dockerfile.test .
# Step 4: Run tests in Docker container
- name: Run tests with coverage
run: |
docker run coverage-test
# Step 5: Upload coverage results
- name: Upload coverage results
uses: actions/upload-artifact@v3
with:
name: coverage-results
path: backend/tests/coverage.xml

# Step 6: Set up test containers for staging
- name: Set up test containers
run: docker compose -f docker-compose.stag.yml up --build -d

# Step 7: Run backend unit tests in staging
- name: Run backend unit tests
run: docker exec secfit_stag_backend python manage.py test tests

# Step 8: Tear down test containers
- name: Tear down test containers
run: docker compose -f docker-compose.stag.yml down

# Step 9: Tear down previous production containers
- name: Tear down previous production containers (if any)
run: docker compose -f $COMPOSE_FILE down || true

# Step 10: Build and run production containers
- name: Build and run docker image
run: docker compose -f $COMPOSE_FILE up --force-recreate --build -d

# Step 11: Print deployment message
- name: Print deployment message
run: |
echo "Code has been updated and deployed to the server!"
echo "Commit hash: ${{ github.sha }}"
echo "Branch: ${{ github.ref }}"
# Step 12: Verify gateway availability
- name: Verify that gateway is available
run: docker ps
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build test image
run: docker build -f tests/Dockerfile.test -t backend-test .

- name: Run tests with coverage
id: coverage
run: |
docker run --name test-container backend-test
# Copy coverage files to backend/ directory
docker cp test-container:/app/coverage.xml . || true
docker cp test-container:/app/htmlcov ./htmlcov || true
docker rm test-container
- name: Upload coverage report (XML)
uses: actions/upload-artifact@v3
with:
name: coverage-xml
path: backend/coverage.xml
if: always() && exists('backend/coverage.xml')

- name: Upload HTML coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-html
path: backend/htmlcov/
if: always() && exists('backend/htmlcov')

0 comments on commit ac612d3

Please sign in to comment.