.github/workflows/build.yml
name: Build, Test, Cover and Deploy
on:
push:
branches:
- main
- beta
pull_request:
jobs:
lint:
name: Linting
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Cancel previous running workflows
uses: fkirc/skip-duplicate-actions@master
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --statistics
- name: Lint commit message
uses: wagoid/commitlint-github-action@v2
test:
name: Test
runs-on: ubuntu-20.04
services:
postgres:
image: postgres
env:
POSTGRES_DB: django_forest
POSTGRES_USER: forest
POSTGRES_PASSWORD: secret
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
django-version: [3.2, 4.0, 4.1, 4.2]
python-version: [3.8, 3.9, '3.10', 3.11]
include:
- django-version: 3.2
python-version: 3.6
- django-version: 3.2
python-version: 3.7
needs: [lint]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
id: pip-cache
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ env.pythonLocation }}-pip-
- name: Install dependencies
if: steps.pip-cache.outputs.cache-hit != 'true'
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install django==${{matrix.django-version}}
- name: Test with pytest
run: coverage run -m pytest
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
- name: Archive code coverage results
uses: actions/upload-artifact@v2
with:
name: code-coverage-report.${{ matrix.python-version }}
path: .coverage
coverage:
name: Coverage
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
needs: [test]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install coverage
- name: Download all coverage reports
uses: actions/download-artifact@v2
- name: Combine reports
run: |
coverage combine ./code-coverage-report.*/.coverage
- name: Send coverage
uses: paambaati/codeclimate-action@v2.7.4
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageCommand: coverage xml
deploy:
name: Release package
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
needs: [test]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta')
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false # GITHUB_TOKEN must not be set for the semantic release
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install setuptools
run: python -m pip install --upgrade setuptools wheel twine
- uses: actions/setup-node@v1
with:
node-version: 14.17.6
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: install dependencies
run: yarn install --frozen-lockfile --non-interactive --production=false
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
with:
semantic_version: 17.3.0
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}