-
Notifications
You must be signed in to change notification settings - Fork 6
140 lines (130 loc) · 4.84 KB
/
push.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# This workflow runs on a `push` to any branch
name: CI
on:
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.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- 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.7", "3.8", "3.9", "3.10" ]
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.9' }}
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.7", "3.8", "3.9", "3.10" ]
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 }}