Skip to content

Merge pull request #10 from mrmuhammadazeemrao/master #11

Merge pull request #10 from mrmuhammadazeemrao/master

Merge pull request #10 from mrmuhammadazeemrao/master #11

name: Test and Deploy
on: [push]
jobs:
build:
name: build, test and deploy django app
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@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
- uses: actions/cache@v2
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 -r requirements.txt
- name: Run Tests
env:
USE_SQLITE3_DB: "0"
USE_SPACES: "0"
DJANGO_SECRET_KEY: CI_CD_TEST_KEY
POSTGRES_DB: testing_db
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
DEBUG: "0"
PRODUCTION: "1"
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 }}
# fingerprint: ${{ secrets.MY_SERVER_FINGERPRINT }}
# if a try to run the shell script I get: bash: /home/***/my_server_scripts/englishquiz/after_deployment.sh: Permission denied
# /home/${{ secrets.MY_SERVER_USERNAME }}/my_server_scripts/englishquiz/after_deployment.sh
script: |
cd /home/rami/englishquiz
git pull
source venv/bin/activate
python -m pip install --upgrade pip setuptools wheel pip-tools
pip-sync
python manage.py migrate