Sanity Check #5816
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 of our workflow | |
name: Sanity Check | |
# triggers for our workflow | |
on: | |
schedule: | |
- cron: "* */6 * * *" | |
# opening a pull request to master and develop branch will be a trigger | |
pull_request: | |
branches: ["master", "main"] | |
paths-ignore: ["docs/**"] # any code pushed to master and develop branch will also be a trigger | |
push: | |
branches: ["master", "main"] | |
paths-ignore: ["docs/**"] | |
# three job definition | |
jobs: | |
dev_sanity_test: # health check job for testing and code formatting check | |
runs-on: ubuntu-latest # os for running the job | |
services: | |
postgres: # we need a postgres docker image to be booted a side car service to run the tests that needs a db | |
image: postgres | |
env: # the environment variable must match with app/settings.py if block of DATBASES variable otherwise test will fail due to connectivity issue. | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: github-actions | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/github-actions | |
ports: | |
- 5432:5432 # exposing 5432 port for application to use | |
# needed because the postgres container does not provide a healthcheck | |
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
steps: | |
- name: Checkout code # checking our the code at current commit that triggers the workflow | |
uses: actions/checkout@v3 | |
- name: Cache dependency # caching dependency will make our build faster. | |
uses: actions/cache@v2 # for more info checkout pip section documentation at https://github.com/actions/cache | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Setup python environment # setting python environment to 3.x | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.8" # if you want multiple python version run just use matrix strategy in job config. See the documentation of GitHub Actions | |
- name: Check Python version # checking the python version to see if 3.x is installed. | |
run: python --version | |
- name: Install requirements # install application requirements | |
run: pip install cookiecutter | |
- name: Scaffold Project | |
working-directory: ./ | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install --upgrade setuptools | |
pip install --user cookiecutter | |
cp -r . /tmp/template | |
cookiecutter /tmp/template -o /tmp/project --no-input | |
cd /tmp/project && ls | |
- name: Setting up project | |
working-directory: /tmp/project/supercoolprojectname | |
run: | | |
pip install -r requirements.txt | |
pip install safety | |
- name: Running Dependency Check on installed packages | |
working-directory: /tmp/project/supercoolprojectname | |
run: | | |
pip check | |
- name: Running Safety Check on installed packages | |
working-directory: /tmp/project/supercoolprojectname | |
run: | | |
safety check | |
- name: Running project test cases | |
working-directory: /tmp/project/supercoolprojectname/app | |
run: | | |
python manage.py makemigrations | |
python manage.py migrate | |
python manage.py collectstatic --no-input | |
python manage.py test |