-
Notifications
You must be signed in to change notification settings - Fork 11
221 lines (195 loc) · 5.89 KB
/
python.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
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
name: Python package
on:
workflow_dispatch:
push:
paths:
- "Python/**"
- "src/**"
- ".github/workflows/python.yaml"
branches:
- master
tags:
- "[0-9]+.[0-9]+.[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+-rc[1-9]+"
- "[0-9]+.[0-9]+.[0-9]+rc[1-9]+"
- "[0-9]+.[0-9]+.[0-9]+-b[1-9]+"
- "[0-9]+.[0-9]+.[0-9]+b[1-9]+"
pull_request:
paths:
- "Python/**"
- "src/**"
- ".github/workflows/python.yaml"
jobs:
build_sdist:
name: sdist build
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: pip
cache-dependency-path: Python/ci-requirements.txt
- name: Install CI dependencies
working-directory: Python/
run: pip install -r ci-requirements.txt
- name: flake8
working-directory: Python/
run: |
python3 -m flake8
- name: bandit
working-directory: Python/
run: |
python3 -m bandit -r .
- name: isort
working-directory: Python/
run: |
python3 -m isort . --diff --check --color
- name: black
working-directory: Python/
run: |
python3 -m black . --check --diff --exclude extension
- name: Build
working-directory: Python/
run: |
python -m build --sdist
# Ensure exactly one artifact was produced.
[[ $(shopt -s nullglob; ls dist/*.tar.gz | wc -w) == 1 ]] || {
echo "Unexpected content in dist dir: '$(ls dist/*.tar.gz)'."
exit 1
}
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: sdist
path: Python/dist/*.tar.gz
build_linux_wheels:
name: linux wheels build
runs-on: ubuntu-latest
permissions:
packages: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build wheels
uses: pypa/cibuildwheel@v2.11.2
env:
CIBW_ARCHS: x86_64
CIBW_MANYLINUX_X86_64_IMAGE: ghcr.io/forestry-labs/rforestry/python_build_env:latest
CIBW_BUILD: cp38-manylinux* cp39-manylinux* cp310-manylinux* cp311-manylinux*
CIBW_TEST_EXTRAS: test
CIBW_TEST_COMMAND: pytest /project/Python/tests --cov-report xml:/host/coverage.xml
with:
package-dir: Python/
output-dir: Python/dist
# - name: Get Coverage
# if: github.event_name == 'pull_request'
# uses: petrovicboban/coverage@1.2
# with:
# coverageFile: /coverage.xml
# thresholdAll: 0.60
# thresholdModified: 0.60
# thresholdNew: 0.60
# token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: linux_wheels
path: Python/dist/*.whl
build_macos_wheels:
name: macos wheels build for ${{ matrix.config.arch }}
runs-on: macos-11
permissions:
packages: read
strategy:
fail-fast: false
matrix:
config:
- { arch: x86_64 }
- { arch: arm64 }
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build wheels
uses: pypa/cibuildwheel@v2.11.2
env:
CIBW_ARCHS: ${{ matrix.config.arch }}
CIBW_BUILD: cp38-* cp39-* cp310-* cp311-*
CIBW_TEST_EXTRAS: test
CIBW_TEST_COMMAND: pytest work/Rforestry/Rforestry/Python/tests -v --color=yes
with:
package-dir: Python/
output-dir: Python/dist
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: macos_${{ matrix.config.arch }}_wheels
path: Python/dist/*.whl
release:
needs: [build_sdist, build_linux_wheels, build_macos_wheels]
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- uses: actions/download-artifact@v3
with:
name: sdist
path: packages
- uses: actions/download-artifact@v3
with:
name: linux_wheels
path: packages
- uses: actions/download-artifact@v3
with:
name: macos_x86_64_wheels
path: packages
- uses: actions/download-artifact@v3
with:
name: macos_arm64_wheels
path: packages
- name: List
run: |
ls -alh packages
- name: Extract Tag
id: tag
uses: aaronbarnaby/get-tag@v1.0.0
- name: Parse tag
id: version
uses: akshens/semver-tag@v4
with:
version: ${{ steps.tag.outputs.tag }}
- name: Publish prerelease packages to Test PyPI
if: steps.version.outputs.is-prerelease == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
packages-dir: packages/
repository-url: https://test.pypi.org/legacy/
- name: Publish packages to PyPI
if: steps.version.outputs.is-prerelease == 'false'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: packages/
- name: Create Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: |
packages/*