Skip to content

Instantly share code, notes, and snippets.

@nashmaniac
Last active June 7, 2020 17:36
Show Gist options
  • Save nashmaniac/10791911cf1d9a3eb18bea59d8063381 to your computer and use it in GitHub Desktop.
Save nashmaniac/10791911cf1d9a3eb18bea59d8063381 to your computer and use it in GitHub Desktop.
# contents-truncated
# three job definition
jobs:
health-check-job: # 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
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@v2
- 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@v2
with:
python-version: '3.x' # 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 -r requirements.txt
- name: Check Syntax # check code formatting
run: pycodestyle --statistics .
- name: Run Migrations # run migrations to create table in side car db container
run: python manage.py migrate
- name: Run Test # running tests
run: pip manage.py test # we intentionally made an error. Instead of python we used pip.
- uses: nashmaniac/[email protected]
if: ${{ failure() }} # only run when this job is failed.
name: Create Issue Action
with:
title: Build Failed
token: ${{secrets.GITHUB_TOKEN}}
assignees: ${{github.actor}}
labels: worflow-failed
body: Workflow failed for commit ${{github.sha}}
package-job: # package job for building and publishing docker images
# contents-truncated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment