Skip to content

Commit

Permalink
feat: add auto-deploy job in actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gray-Advantage committed Apr 10, 2024
1 parent c6949d0 commit 1df71b0
Showing 1 changed file with 55 additions and 19 deletions.
74 changes: 55 additions & 19 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,63 @@ permissions:
contents: read

jobs:
build:
flake8-test:
runs-on: ubuntu-latest
container: python:3.10
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: pip install -r requirements/test.txt
- name: Check code formatting with flake8
run: flake8 ./datanar/ --config=.flake8

black-test:
runs-on: ubuntu-latest
container: python:3.10
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: pip install black
- name: Check code formatting with black
run: black ./datanar/ --check --verbose --diff --line-length 79

django-test:
runs-on: ubuntu-latest
container: python:3.10
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v3
- uses: actions/checkout@v3
- name: Install dependencies
run: pip install -r requirements/dev.txt
- name: Run Django tests
run: |
cd ./datanar
python manage.py test
deploy:
if: github.ref == 'refs/heads/main'
needs: [black-test, flake8-test, django-test]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Deploy to server
uses: appleboy/ssh-action@master
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/dev.txt
- name: Lint with flake8
run: |
flake8 ./datanar/ --config=.flake8
- name: Lint with black
run: |
black ./datanar/ --check --verbose --diff --line-length 79
- name: Django testing
run: |
cd ./datanar
python manage.py test
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
sudo supervisorctl stop all
cd ~/datanar
git reset --hard HEAD
git pull
source venv/bin/activate
pip install -r requirements/dev.txt
cd ~/datanar/datanar
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --no-input
deactivate
cd ~
sudo supervisorctl start all

0 comments on commit 1df71b0

Please sign in to comment.