Skip to content

ci(.github): run CI checks on pushes on main and manual dispatch #5

ci(.github): run CI checks on pushes on main and manual dispatch

ci(.github): run CI checks on pushes on main and manual dispatch #5

Workflow file for this run

name: sibilant
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
jobs:
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Run pre-commit
run: |
git switch -C ${{ github.base_ref }} --track origin/${{ github.base_ref }}
git switch -C ${{ github.head_ref }} --track origin/${{ github.head_ref }}
pre-commit run --from-ref ${{ github.base_ref }} --to-ref ${{ github.head_ref }}
unit-tests:
name: tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Run tests
run: pytest --no-cov
coverage:
name: coverage
runs-on: ubuntu-latest
steps:
- name: Set values
id: values
run: echo "cov_req=80" >> $GITHUB_OUTPUT
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Run coverage
id: coverage
continue-on-error: true
run: |
pwd
ls -la
pytest --cov
coverage report
COV_POST=`coverage report --precision=2 | awk '$1 == "TOTAL" {print $NF+0}'`
COV_BELOW=`echo "$COV_POST" | awk '{print ($1 < ${{ steps.values.outputs.cov_req }})}'`
git switch -C ${{ github.base_ref }} --track origin/${{ github.base_ref }}
pytest --cov
COV_PRE=`coverage report --precision=2 | awk '$1 == "TOTAL" {print $NF+0}'`
COV_DECREASE=`echo "$COV_POST $COV_PRE" | awk '{print ($1 < $2)}'`
echo "cov_post=$COV_POST" >> $GITHUB_OUTPUT
echo "cov_pre=$COV_PRE" >> $GITHUB_OUTPUT
echo "cov_below=$COV_BELOW" >> $GITHUB_OUTPUT
echo "cov_decrease=$COV_DECREASE" >> $GITHUB_OUTPUT
- name: Check coverage
uses: actions/github-script@v6
with:
script: |
const cov_req = ${{ steps.values.outputs.cov_req }}
const cov_post = ${{ steps.coverage.outputs.cov_post }}
const cov_pre = ${{ steps.coverage.outputs.cov_pre }}
const cov_diff = cov_post - cov_pre
cov_post >= cov_req
? core.notice(`Current coverage: ${cov_post}%`)
: core.warning(`Coverage is below ${cov_req}%, current coverage ${cov_post}%`)
cov_diff >= 0.0
? core.notice(`Coverage has increased from ${cov_pre}% to ${cov_post}% (+${cov_diff.toFixed(2)}%)`)
: core.setFailed(`Coverage has decreased from ${cov_pre}% to ${cov_post}% (${cov_diff.toFixed(2)}%)`)