Skip to content

Update coverage-workflow.yml #20

Update coverage-workflow.yml

Update coverage-workflow.yml #20

name: Production Deployment Workflow
on:
push:
branches:
- gargi-production # Trigger only for production branch
jobs:
deploy:
runs-on: self-hosted
env:
REPO_NAME: ${{ github.event.repository.name }}
COMPOSE_FILE: docker-compose.yml
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