Create test_deploy.yml #1
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: Django Project Test and Deploy | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
Test: | |
name: Test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Docker-Compose | |
run: docker-compose up -d | |
- name: Run Tests | |
run: docker exec backend sh -c "flake8 && pytest ." | |
Deploy: | |
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }} | |
name: Deploy | |
needs: Test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Connect and Execute Commands | |
uses: appleboy/ssh-action@master | |
with: | |
username: ${{secrets.USERNAME}} | |
password: ${{secrets.PASSWORD}} | |
host: ${{secrets.HOST}} | |
port: ${{secrets.PORT}} | |
script: | | |
cd ${{secrets.PROJECT_PATH}} | |
docker-compose -f docker-compose-stage.yml stop | |
git pull | |
docker-compose -f docker-compose-stage.yml restart | |