Skip to content

github

github #325

name: Test and Deploy
on: [push]
jobs:
build:
name: build, test and deploy django app
if: contains(github.event.head_commit.message, '--ga')
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: testing_db
ports:
- 5432:5432
# needed because the postgres container does not provide a health check
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- uses: actions/cache@v3
name: Configure pip caching
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test
- name: Deploy to server, executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.MY_SERVER_HOST }}
username: ${{ secrets.MY_SERVER_USERNAME }}
key: ${{ secrets.MY_SERVER_KEY }}
port: ${{ secrets.MY_SERVER_PORT }}
script: |
cd /home/${{ secrets.MY_SERVER_USERNAME }}/nicecv
git pull
source venv/bin/activate
python -m pip install --upgrade pip setuptools wheel pip-tools
pip-sync
python manage.py collectstatic --noinput
python manage.py migrate
systemctl --user restart celerybeat_nicecv.service
systemctl --user restart celery_nicecv.service
systemctl --user restart gunicorn_nicecv.service