-
Notifications
You must be signed in to change notification settings - Fork 41
304 lines (255 loc) · 8.85 KB
/
build-test-deploy.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
name: "Build"
on: [push, workflow_dispatch]
jobs:
codeanalysis:
name: "Code Quality"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Black
uses: psf/black@stable
with:
src: "./src ./tests"
test:
name: "Test"
runs-on: ${{ matrix.os-version }}
env:
LANG: en_US.UTF-8
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
os-version: ['ubuntu-20.04', 'windows-latest', 'macos-latest']
# Pinned Ubuntu version to 20.04 since no Python 3.6 builds available on ubuntu-latest (22.04) as of 2022-12-7.
# os-version: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies (Ubuntu)
if: startsWith(matrix.os-version, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install build-essential libkrb5-dev
- name: Install dependencies (Common)
run: |
# Setup tox & code coverage
pip install --upgrade pip
pip install tox tox-gh-actions pytest pytest-cov 'scikit-learn<=1.5.0' 'numpy<2.0.0'
- name: Run Tests
run: |
tox
# Separate upload task for unit test coverage allows for flagged analysis of test coverage
- name: Upload Unit Test Coverage
if: startsWith(matrix.os-version, 'ubuntu')
uses: codecov/codecov-action@v3
with:
directory: ./.reports/
fail_ci_if_error: false
file: unit.xml
flags: unit
verbose: true
# Separate upload task for integration test coverage allows for flagged analysis of test coverage
- name: Upload Integration Test Coverage
if: startsWith(matrix.os-version, 'ubuntu')
uses: codecov/codecov-action@v3
with:
directory: ./.reports/
fail_ci_if_error: false
file: integration.xml
flags: integration
verbose: true
# Uncomment when scenario test cases are working again
# Separate upload task for scenario test coverage allows for flagged analysis of test coverage
# - name: Upload Scenario Test Coverage
# if: matrix.os-version == 'ubuntu-latest'
# uses: codecov/codecov-action@v3
# with:
# directory: ./.reports/
# fail_ci_if_error: true
# file: scenarios.xml
# flags: scenarios
# verbose: true
gh-pages:
name: "Build Documentation"
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags/') # run only on tagged commits
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Setup environment
run: |
mv doc docs
sudo apt-get install build-essential
pip install sphinx six pyyaml pandas pydata-sphinx-theme numpydoc
- name: Check documentation
uses: ammaraskar/sphinx-problem-matcher@master
- name: Build documentation
run: sphinx-build -Ean -b html -j auto -D todo_include_todos=0 ./docs ./docs/_build/html
- name: Archive artifacts
uses: actions/upload-artifact@v2
with:
name: html-docs
path: ./docs/_build/html
# Build a package for distribution through PyPI.org (pip install sasctl)
build_pypi:
name: "Build PyPI Package"
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags/') # run only on tagged commits
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
- name: Install dependencies
run: |
pip install --upgrade pip
pip install setuptools wheel twine
- name: Build Package
run: |
python setup.py sdist bdist_wheel
- name: Extract Changes
shell: python
run: |
import os, re
tag_name = os.environ['GITHUB_REF'].replace('refs/tags/', '')
changes = ''
with open('CHANGELOG.md') as f:
lines = f.read()
match = re.search('%s [()\d\-\s]*' % tag_name, lines)
if match:
lines = lines[match.end():]
changes = re.split('-----+', lines)[0].split('\n')
changes = '\n'.join(changes[:-2])
with open('release_notes.md', 'w') as f:
f.write(changes)
- name: Archive distribution artifacts
# Archive distribution files for use by auto (or manual) PyPI upload
uses: actions/upload-artifact@v3
with:
name: pypi-dist
path: ./dist
- name: Archive changelog artifacts
uses: actions/upload-artifact@v3
with:
name: release_notes
path: release_notes.md
# Build a package for distribution through Anaconda.org (conda install sasctl)
build_conda:
name: "Build Conda Package"
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags/') # run only on tagged commits
steps:
# Setup Miniconda
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
- name: Install conda-build
shell: bash -l {0}
run: |
conda install conda-build
- name: Checkout repository
uses: actions/checkout@v3
# Build package and store results in .build folder
- name: Build package
shell: bash -l {0}
run: |
conda build --output-folder .build .conda
# Archive distribution files. Will upload in a downstream job.
- name: Archive distribution artifacts
uses: actions/upload-artifact@v3
with:
name: conda-dist
path: .build
# Publishes the new package to PyPI, uploads the latest documentation to GitHub Pages
# and creates a new release with change notes on GitHub.
publish:
name: "Publish"
runs-on: ubuntu-latest
needs: [gh-pages, build_pypi, build_conda]
steps:
- name: Download documentation
uses: actions/download-artifact@v3
with:
name: html-docs
path: ./html-docs
- name: Download release
uses: actions/download-artifact@v3
with:
name: pypi-dist
path: ./dist
- name: Download release notes
uses: actions/download-artifact@v3
with:
name: release_notes
- name: Zip Documentation
run: zip -r documentation.zip ./html-docs
- name: Display structure of downloaded files
run: ls -R
# Create a draft release on GitHub
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
draft: true
body_path: release_notes.md
body: ""
files: documentation.zip
# Publish the documentation to GitHub Pages
- name: Deploy documentation
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./html-docs
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
# Publish the release on GitHub (remove draft status)
- name: Publish release
uses: StuYarrow/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
id: ${{ steps.create_release.outputs.id }}
# Uploads the package to Anaconda.
# NOTE: could be merged with `publish` job above. Left as a separate, final job since it
# involves multiple steps to setup the environment and if this job fails, the package
# has already been made available through pip, and the release info published.
upload_conda:
name: "Upload Conda Package"
runs-on: ubuntu-latest
needs: [publish]
steps:
# Setup Miniconda
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
# Setup Anaconda client (required for upload)
- name: Install anaconda client
shell: bash -l {0}
run: |
conda install anaconda-client
# Download release files
- name: Download release
uses: actions/download-artifact@v3
with:
name: conda-dist
path: ./dist
# Upload release to Anaconda.org
- name: Upload release
shell: bash -l {0}
run: |
anaconda -t ${{ secrets.ANACONDA_TOKEN }} upload -u sas-institute ./dist/noarch/sasctl-*.tar.bz2