Skip to content

CI

CI #594

Workflow file for this run

# This workflow runs on a `push` to any branch
name: CI
on:
workflow_dispatch:
push:
schedule:
- cron: '0 1 * * 6' # weekly run at 01:00 UTC on Saturday, dependency check
jobs:
# Lint and type checking
lint_and_type_check:
name: Lint and type check
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- name: Set up Python "3.10"
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies
run: |
pip install pre-commit
- name: Lint and type check
run: |
pre-commit run --all-files --verbose --show-diff-on-failure
# Unit test and coverage
test:
name: Test on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
needs: [ lint_and_type_check ]
strategy:
matrix:
python-version: [ "3.10", "3.11", "3.12"]
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 package with dependencies
run: |
pip install .[tests]
- name: Test with pytest
run: |
# grab the coverage output and also print it to the sreen
coverage run -m pytest
COVERAGE_REPORT=$(coverage report -m | tee /dev/stderr)
# extract the percentage of the total coverage, e.g. `75%`
COVERAGE_PCT=$(echo $COVERAGE_REPORT | \
grep -oP "TOTAL\s+\d+\s+\d+\s+(\d+%)" | grep -oP "\d+%")
# get only the coverage number without the percentage symbol
COVERAGE_NUM=$(echo $COVERAGE_PCT | grep -oP "\d+")
# get an indicative color
if (( COVERAGE_NUM <= 50 )); then
COVERAGE_COL="red"
elif (( COVERAGE_NUM <= 60 )); then
COVERAGE_COL="orange"
elif (( COVERAGE_NUM <= 70 )); then
COVERAGE_COL="yellow"
elif (( COVERAGE_NUM <= 80 )); then
COVERAGE_COL="yellowgreen"
elif (( COVERAGE_NUM <= 90 )); then
COVERAGE_COL="green"
else
COVERAGE_COL="brightgreen"
fi
# active branch name
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
# add them to the github env for later usage
echo "COVERAGE_PCT=$(echo $COVERAGE_PCT)" >> $GITHUB_ENV
echo "COVERAGE_COL=$(echo $COVERAGE_COL)" >> $GITHUB_ENV
echo "BRANCH_NAME=$(echo $BRANCH_NAME)" >> $GITHUB_ENV
# Upload the coverage value to gist only once
- if: ${{ matrix.python-version == '3.12' }}
name: Upload coverage to gist
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 5eb707145cc7d75de25b43d25b13c972
filename: probeye_${{ env.BRANCH_NAME }}_coverage.json
label: coverage
message: ${{ env.COVERAGE_PCT }}
color: ${{ env.COVERAGE_COL }}
# Run tests with the latest available version of all dependencies
# these latest versions might be beyond the versions specified in `setup.cfg`
# the goal of this job to catch errors with these latest versions
# [only for `main`]. Ideally, if this job succeeded with at least one major
# version number increased then the `setup.cfg` would be updated.
test_with_latest:
name: Test with latest dependencies on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
if: |
github.ref == 'refs/heads/main' &&
github.repository == 'BAMresearch/probeye' &&
github.event_name == 'schedule'
needs: [ lint_and_type_check ]
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
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 package with latest dependencies
run: |
python probeye/_setup_cfg.py
pip install .[tests]
- name: Test with pytest
run: |
pytest
# Release to GitHub and PyPi [only for `main`]
#release:
# name: Semantic Release
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/main' && github.repository == 'BAMresearch/probeye'
# concurrency: release
# needs: [ lint_and_type_check, test ]
# steps:
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0
# - name: Fetch main
# run: |
# git fetch --prune origin +refs/heads/main:refs/remotes/origin/main
# - name: Python semantic release
# uses: relekang/python-semantic-release@master
# with:
# github_token: ${{ secrets.TOKEN_GITHUB }}
# pypi_token: ${{ secrets.PYPI_TOKEN }}