Skip to content

Merge pull request #234 from antaliadom-team/feature/jwt_lifetime #244

Merge pull request #234 from antaliadom-team/feature/jwt_lifetime

Merge pull request #234 from antaliadom-team/feature/jwt_lifetime #244

Workflow file for this run

name: Tests, Codecov reports, Deploy to the test server
on:
pull_request:
types: [closed]
branches:
- dev
- main
push:
branches:
- dev
- main
jobs:
tests:
name: Pytests with coverage
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
python-version: [ "3.10", "3.11" ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
cache: 'pip'
cache-dependency-path: './req-prod.txt'
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: |
pip install -r req-prod.txt
pip install pytest pytest-cov pytest-django pytest-mock
- name: Run tests
run: |
python -m pytest --cov --verbose --color=yes --cov-report=xml .
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: /home/runner/work/backend/backend/coverage.xml
build_and_push_to_docker_hub:
name: Push Docker image to Docker Hub
runs-on: ubuntu-20.04
needs: tests
if: github.event.pull_request.merged == true
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_NAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Push to Docker Hub
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ secrets.DOCKER_HUB_NAME }}/antalyadom-backend:latest
deploy_to_test_server:
name: Deploy backend to the test server
runs-on: ubuntu-20.04
needs: build_and_push_to_docker_hub
if: github.event.pull_request.merged == true
steps:
- name: SSH commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_HOST }}
username: ${{ secrets.DEV_USER }}
key: ${{ secrets.DEV_KEY }}
port: ${{ secrets.DEV_PORT }}
script: |
cd ./antalyadom
docker pull ${{ secrets.DOCKER_HUB_NAME }}/antalyadom-backend:latest
docker-compose stop
docker-compose down
docker volume rm antalyadom_project_value
docker-compose up -d --build