-
Notifications
You must be signed in to change notification settings - Fork 2
147 lines (118 loc) · 5.18 KB
/
push_tests.yml
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
141
142
143
144
145
146
147
name: tests
on:
push:
branches-ignore:
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Runs the workflow once per day at 3:15am
schedule:
- cron: '3 16 * * *'
env:
CACHE_NUMBER: 1 # increase to reset cache manually
jobs:
tests:
runs-on: ubuntu-latest
outputs:
branch_coverage: ${{ steps.pytest.outputs.coverage }}
coverage_report: ${{ steps.pytest.outputs.report }}
steps:
- name: checkout repo content
uses: actions/checkout@v2
- name: install-extra-deps
uses: ./.github/actions/install-extra-deps
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: fenicsxconcrete
use-mamba: true
- name: Set cache date
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
- uses: actions/cache@v2
with:
path: "/usr/share/miniconda3/envs/fenicsxconcrete"
key: conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
id: cache
- name: Update environment
run: mamba env update -n fenicsxconcrete -f environment.yml
if: steps.cache.outputs.cache-hit != 'true'
- name: pytest
id : pytest
shell: bash -l {0}
run: |
cd $GITHUB_WORKSPACE
# grab the coverage output and also print it to the screen
coverage run -m pytest -s -W error::UserWarning
coverage xml
COVERAGE_REPORT=$(coverage report -m | tee /dev/stderr)
# passing a multiline string to output to use it in next job
echo "report<<EOF" >> $GITHUB_OUTPUT
echo "$COVERAGE_REPORT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# 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+")
# active branch name
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
# add them to the github env for later usage
echo "COVERAGE_NUM=$(echo $COVERAGE_NUM)" >> $GITHUB_ENV
echo "coverage=$(echo $COVERAGE_NUM)" >> $GITHUB_OUTPUT # to be used in next job
echo "COVERAGE_PCT=$(echo $COVERAGE_PCT)" >> $GITHUB_ENV
# removing all possible slashes in file names, they seem to appear during Pull Requests
echo "BRANCH_NAME=$(echo $BRANCH_NAME | sed "s/\//_/g")" >> $GITHUB_ENV
- name: execute example scripts
shell: bash -l {0}
run: |
for file in docs/examples/*.py
do
python $file
done
- name: test docs
shell: bash -l {0}
run: |
cd docs
make html
- name: Create Coverage Badge
if: contains(env.BRANCH_NAME, 'main')
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: c10a5b6d0714b1fe2344eb60918e92f8
filename: fenicsxconcrete_${{ env.BRANCH_NAME }}_coverage.json
label: coverage
message: ${{ env.COVERAGE_PCT }}
valColorRange: ${{ env.COVERAGE_PCT }}
maxColorRange: 95 # value where ligth green starts
minColorRange: 50 # value where red starts
check_coverage:
needs: tests
runs-on: ubuntu-latest
steps:
- name: check coverage
run: |
# getting coverage number from output of first job for this branch
BRANCH_COVERAGE=${{ needs.tests.outputs.branch_coverage }}
echo "Coverage of current branch: $BRANCH_COVERAGE"
declare -i int_branch_coverage=$BRANCH_COVERAGE
# getting coverage number from gist for main branch
MAIN_DATA=$(curl -s -X GET "https://gist.githubusercontent.com/eriktamsen/c10a5b6d0714b1fe2344eb60918e92f8/raw/fenicsxconcrete_main_coverage.json")
MAIN_COVERAGE=$(echo $MAIN_DATA | grep -o -P 'message.{3,6}' | sed -e 's/"//g' | sed -e 's/://g' | sed -e 's/message//g' | sed -e 's/%//g' | sed -e 's/,//g')
echo "Coverage of main branch: $MAIN_COVERAGE"
declare -i int_main_coverage=$MAIN_COVERAGE
# compute difference
delta_coverage=$(( int_branch_coverage - int_main_coverage ))
echo "Increase in coverage: $delta_coverage"
echo "Coverage report:"
echo "-----------------------------------------------------------------------------------------------"
echo "${{ needs.tests.outputs.coverage_report }}"
echo "-----------------------------------------------------------------------------------------------"
if [[ $delta_coverage -lt 0 ]]
then
echo "The current branch has lower coverage than the main branch, please improve your code"
exit 1
fi
echo "Passing!!!"