-
Notifications
You must be signed in to change notification settings - Fork 32
191 lines (163 loc) · 5.75 KB
/
CI.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main and develop branches.
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
generate:
name: Generate comparison results
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
- name: Set up latest Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: 'pip'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
- name: Generate comparison results
run: |
python3 -m test.simple_ci --generate
- name: Upload results
uses: actions/upload-artifact@v3
with:
name: test-data
path: test/data
package:
name: Test package (${{ matrix.py }} on ${{ matrix.os }})
needs: generate
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
py:
- "3.11"
- "3.10"
- "3.9"
- "3.8"
os:
- ubuntu-latest
- macos-latest
- windows-latest
exclude:
# Issue with python build
- os: windows-latest
py: "3.8"
# Intermittent CI test failures
- os: windows-latest
py: "3.11"
steps:
- uses: actions/checkout@v3
- name: Set up latest Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
cache: 'pip'
- name: Build and install package
shell: bash
run: |
python3 -m pip install --upgrade pip
python3 -m pip install build
python3 -m build
python3 -m pip install dist/curvesim*.whl
# ensure tests hit installed package
rm -r curvesim
- name: Download comparison results
uses: actions/download-artifact@v3
with:
name: test-data
path: test/data
- name: Hello world test
run: |
python3 -m curvesim
- name: End-to-end tests
run: |
python3 -m test.simple_ci
source:
name: Test source with coverage
needs: generate
runs-on: ubuntu-latest
permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
# Gives the action the necessary permissions for pushing data to the
# python-coverage-comment-action branch, and for editing existing
# comments (to avoid publishing multiple comments in the same PR)
contents: write
steps:
- uses: actions/checkout@v3
- name: Set up latest Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: 'pip'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
- name: Unit tests
run: |
pytest --cov -n auto --cov-report=
- name: Download comparison results
uses: actions/download-artifact@v3
with:
name: test-data
path: test/data
- name: End-to-end tests
run: |
coverage run -m test.simple_ci
- name: Download coverage badge
uses: chanhosuh/get-gist-action@master
id: covbadge
with:
gistURL: "https://gist.github.com/chanhosuh/3da3c072e081f4509ebdd09c63e6ede5"
- name: Coverage report
run: |
# combine coverage results from the previous steps
# and checks if score decreased since last CI run
coverage combine --append
BADGE_JSON=`cat ${{ steps.covbadge.outputs.file }}`
OLD_SCORE=$(python3 -c "import json; score=json.loads('${BADGE_JSON}')['message'].rstrip('%'); print(score)")
# Use a "band" around the old score to account for fluctuations
OLD_SCORE_LOWER=$((OLD_SCORE-1))
OLD_SCORE_UPPER=$((OLD_SCORE+1))
# Use low bound to test score doesn't decrease significantly
coverage report --fail-under="${OLD_SCORE_LOWER:-0}"
NEW_SCORE=$(coverage report --format=total)
# Save upper bound for comparison: only save score if increase is significant
echo "OLD_COVERAGE_SCORE=${OLD_SCORE_UPPER}" >> $GITHUB_ENV
echo "COVERAGE_SCORE=${NEW_SCORE}" >> $GITHUB_ENV
- name: Upload coverage badge
uses: schneegans/dynamic-badges-action@v1.6.0
if: ${{ github.ref == 'refs/heads/main' && env.COVERAGE_SCORE > env.OLD_COVERAGE_SCORE }}
with:
auth: ${{ secrets.GIST_TOKEN }} # personal access token with scope "gist"
gistID: 3da3c072e081f4509ebdd09c63e6ede5 # id of previously created gist
filename: curvesim_coverage_badge.json
label: Coverage
message: ${{ env.COVERAGE_SCORE }}%
minColorRange: 50
maxColorRange: 90
valColorRange: ${{ env.COVERAGE_SCORE }}%
- name: Commit coverage report
id: coverage_comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
- name: Store PR comment for posting
uses: actions/upload-artifact@v3
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly
name: python-coverage-comment-action
# If you use a different name, update COMMENT_FILENAME accordingly
path: python-coverage-comment-action.txt