-
Notifications
You must be signed in to change notification settings - Fork 13
265 lines (259 loc) · 13.8 KB
/
publish.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
name: Build and publish Python package
on:
workflow_call:
inputs:
targets:
description: List of build targets for cibuildwheel
required: false
default: |
- linux
- macos
- windows
type: string
sdist:
description: Whether to build a source distribution
required: false
default: true
type: boolean
test_extras:
description: Any extras_requires modifier that should be used to install the package for testing
required: false
default: ''
type: string
test_command:
description: The command to run to test the package (will be run in a temporary directory)
required: false
default: ''
type: string
env:
description: A map of environment variables to be available when building and testing
required: false
default: ''
type: string
libraries:
description: Packages needed to build the source distribution for testing (installed using apt)
required: false
default: ''
type: string
sdist-runs-on:
description: Which runner image to use to build and test the sdist
required: false
default: 'ubuntu-latest'
type: string
upload_to_pypi:
description: A condition specifying whether to upload to PyPI
required: false
default: 'refs/tags/v'
type: string
repository_url:
description: The PyPI repository URL to use
required: false
default: ''
type: string
upload_to_anaconda:
description: A condition specifying whether to upload to Anaconda.org
required: false
default: false
type: boolean
anaconda_user:
description: Anaconda.org user or organisation
required: false
default: ''
type: string
anaconda_package:
description: Anaconda.org package name
required: false
default: ''
type: string
anaconda_keep_n_latest:
description: If specified, only this number of the most recent versions are kept
required: false
default: -1
type: number
fail-fast:
description: Whether to cancel all in-progress jobs if any job fails
required: false
default: false
type: boolean
timeout-minutes:
description: The maximum number of minutes to let a build job run before GitHub automatically cancels it
required: false
default: 360
type: number
submodules:
description: Whether to checkout submodules
required: false
default: true
type: boolean
checkout_ref:
description: The ref to checkout
required: false
default: ''
type: string
secrets:
pypi_token:
required: false
anaconda_token:
required: false
jobs:
targets:
name: Load build targets
if: ${{ inputs.targets != '' }}
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-outputs.outputs.matrix }}
upload_to_pypi: ${{ steps.set-upload.outputs.upload_to_pypi }}
steps:
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- run: python -m pip install PyYAML click
- run: echo $LOAD_BUILD_TARGETS_SCRIPT | base64 --decode > load_build_targets.py
env:
LOAD_BUILD_TARGETS_SCRIPT: aW1wb3J0IGpzb24KaW1wb3J0IG9zCgppbXBvcnQgY2xpY2sKaW1wb3J0IHlhbWwKCk1BQ0hJTkVfVFlQRSA9IHsKICAgICJsaW51eCI6ICJ1YnVudHUtbGF0ZXN0IiwKICAgICJtYWNvcyI6ICJtYWNvcy1sYXRlc3QiLAogICAgIndpbmRvd3MiOiAid2luZG93cy1sYXRlc3QiLAp9CgpDSUJXX0JVSUxEID0gb3MuZW52aXJvbi5nZXQoIkNJQldfQlVJTEQiLCAiKiIpCkNJQldfQVJDSFMgPSBvcy5lbnZpcm9uLmdldCgiQ0lCV19BUkNIUyIsICJhdXRvIikKCgpAY2xpY2suY29tbWFuZCgpCkBjbGljay5vcHRpb24oIi0tdGFyZ2V0cyIsIGRlZmF1bHQ9IiIpCmRlZiBsb2FkX2J1aWxkX3RhcmdldHModGFyZ2V0cyk6CiAgICAiIiJTY3JpcHQgdG8gbG9hZCBjaWJ1aWxkd2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hcm02NCIsICJ1bml2ZXJzYWwyIl06CiAgICAgICAgaWYgdGFyZ2V0LmVuZHN3aXRoKGFyY2gpOgogICAgICAgICAgICByZXR1cm4gYXJjaAogICAgcmV0dXJuIENJQldfQVJDSFMKCgpkZWYgZ2V0X21hdHJpeF9pdGVtKHRhcmdldCk6CiAgICByZXR1cm4gewogICAgICAgICJ0YXJnZXQiOiB0YXJnZXQsCiAgICAgICAgIm9zIjogZ2V0X29zKHRhcmdldCksCiAgICAgICAgIkNJQldfQlVJTEQiOiBnZXRfY2lid19idWlsZCh0YXJnZXQpLAogICAgICAgICJDSUJXX0FSQ0hTIjogZ2V0X2NpYndfYXJjaHModGFyZ2V0KSwKICAgIH0KCgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgbG9hZF9idWlsZF90YXJnZXRzKCkK
- id: set-outputs
run: python load_build_targets.py --targets "${{ inputs.targets }}"
shell: sh
- id: set-upload
run: |
if [ $UPLOAD_TO_PYPI == "true" ] || [ $UPLOAD_TAG == "true" ];
then
echo "upload_to_pypi=true" >> $GITHUB_OUTPUT
else
echo "upload_to_pypi=false" >> $GITHUB_OUTPUT
fi
env:
UPLOAD_TO_PYPI: ${{ inputs.upload_to_pypi }}
UPLOAD_TAG: ${{ startsWith(inputs.upload_to_pypi, 'refs/tags/') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'release' || github.event_name == 'create') && startsWith(github.ref, inputs.upload_to_pypi) }}
build_wheels:
name: Build ${{ matrix.target }} wheels
needs: [targets]
runs-on: ${{ matrix.os }}
timeout-minutes: ${{ inputs.timeout-minutes }}
strategy:
fail-fast: ${{ inputs.fail-fast }}
matrix: ${{fromJSON(needs.targets.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
submodules: ${{ inputs.submodules }}
ref: ${{ inputs.checkout_ref }}
- name: Set up QEMU
if: ${{ matrix.CIBW_ARCHS == 'aarch64' }}
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Configure cibuildwheel
shell: bash
run: |
if [ -n "${{ inputs.test_extras }}" ];
then
echo "CIBW_TEST_EXTRAS=${{ inputs.test_extras }}" >> $GITHUB_ENV
fi
set +e
IFS='' read -r -d '' test_command <<"EOF"
${{ inputs.test_command }}
EOF
set -e
if [ -n "$test_command" ];
then
echo "CIBW_TEST_COMMAND<<EOF" >> $GITHUB_ENV
echo $(echo $test_command | tr -d '\n') >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
cat $GITHUB_ENV
- uses: actions/setup-python@v4
if: ${{ inputs.env != '' }}
with:
python-version: '3.9'
- id: set-env
if: ${{ inputs.env != '' }}
run: |
python -m pip install PyYAML
echo $SET_ENV_SCRIPT | base64 --decode > set_env.py
python set_env.py "${{ inputs.env }}"
rm set_env.py
shell: sh
env:
SET_ENV_SCRIPT: aW1wb3J0IGpzb24KaW1wb3J0IG9zCmltcG9ydCBzeXMKCmltcG9ydCB5YW1sCgpHSVRIVUJfRU5WID0gb3MuZ2V0ZW52KCJHSVRIVUJfRU5WIikKaWYgR0lUSFVCX0VOViBpcyBOb25lOgogICAgcmFpc2UgVmFsdWVFcnJvcigiR0lUSFVCX0VOViBub3Qgc2V0LiBNdXN0IGJlIHJ1biBpbnNpZGUgR2l0SHViIEFjdGlvbnMuIikKCkRFTElNSVRFUiA9ICJFT0YiCgoKZGVmIHNldF9lbnYoZW52KToKCiAgICBlbnYgPSB5YW1sLmxvYWQoZW52LCBMb2FkZXI9eWFtbC5CYXNlTG9hZGVyKQogICAgcHJpbnQoanNvbi5kdW1wcyhlbnYsIGluZGVudD0yKSkKCiAgICBpZiBub3QgaXNpbnN0YW5jZShlbnYsIGRpY3QpOgogICAgICAgIHRpdGxlID0gImBlbnZgIG11c3QgYmUgbWFwcGluZyIKICAgICAgICBtZXNzYWdlID0gZiJgZW52YCBtdXN0IGJlIG1hcHBpbmcgb2YgZW52IHZhcmlhYmxlcyB0byB2YWx1ZXMsIGdvdCB0eXBlIHt0eXBlKGVudil9IgogICAgICAgIHByaW50KGYiOjplcnJvciB0aXRsZT17dGl0bGV9Ojp7bWVzc2FnZX0iKQogICAgICAgIGV4aXQoMSkKCiAgICBmb3IgaywgdiBpbiBlbnYuaXRlbXMoKToKCiAgICAgICAgaWYgbm90IGlzaW5zdGFuY2Uodiwgc3RyKToKICAgICAgICAgICAgdGl0bGUgPSAiYGVudmAgdmFsdWVzIG11c3QgYmUgc3RyaW5ncyIKICAgICAgICAgICAgbWVzc2FnZSA9IGYiYGVudmAgdmFsdWVzIG11c3QgYmUgc3RyaW5ncywgYnV0IHZhbHVlIG9mIHtrfSBoYXMgdHlwZSB7dHlwZSh2KX0iCiAgICAgICAgICAgIHByaW50KGYiOjplcnJvciB0aXRsZT17dGl0bGV9Ojp7bWVzc2FnZX0iKQogICAgICAgICAgICBleGl0KDEpCgogICAgICAgIHYgPSB2LnNwbGl0KCJcbiIpCgogICAgICAgIHdpdGggb3BlbihHSVRIVUJfRU5WLCAiYSIpIGFzIGY6CiAgICAgICAgICAgIGlmIGxlbih2KSA9PSAxOgogICAgICAgICAgICAgICAgZi53cml0ZShmIntrfT17dlswXX1cbiIpCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBmb3IgbGluZSBpbiB2OgogICAgICAgICAgICAgICAgICAgIGFzc2VydCBsaW5lLnN0cmlwKCkgIT0gREVMSU1JVEVSCiAgICAgICAgICAgICAgICBmLndyaXRlKGYie2t9PDx7REVMSU1JVEVSfVxuIikKICAgICAgICAgICAgICAgIGZvciBsaW5lIGluIHY6CiAgICAgICAgICAgICAgICAgICAgZi53cml0ZShmIntsaW5lfVxuIikKICAgICAgICAgICAgICAgIGYud3JpdGUoZiJ7REVMSU1JVEVSfVxuIikKCiAgICAgICAgcHJpbnQoZiJ7a30gd3JpdHRlbiB0byBHSVRIVUJfRU5WIikKCgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgc2V0X2VudihzeXMuYXJndlsxXSkK
- name: Run cibuildwheel
uses: pypa/cibuildwheel@v2.15.0
with:
output-dir: dist
env:
CIBW_BUILD: ${{ matrix.CIBW_BUILD }}
CIBW_ARCHS: ${{ matrix.CIBW_ARCHS }}
- uses: actions/upload-artifact@v3
with:
path: dist/*
build_sdist:
name: Build source distribution
if: ${{ inputs.sdist }}
runs-on: ${{ inputs.sdist-runs-on }}
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- uses: actions/setup-python@v4
if: ${{ inputs.env != '' }}
with:
python-version: '3.9'
- id: set-env
if: ${{ inputs.env != '' }}
run: |
python -m pip install PyYAML
echo $SET_ENV_SCRIPT | base64 --decode > set_env.py
python set_env.py "${{ inputs.env }}"
rm set_env.py
shell: sh
env:
SET_ENV_SCRIPT: aW1wb3J0IGpzb24KaW1wb3J0IG9zCmltcG9ydCBzeXMKCmltcG9ydCB5YW1sCgpHSVRIVUJfRU5WID0gb3MuZ2V0ZW52KCJHSVRIVUJfRU5WIikKaWYgR0lUSFVCX0VOViBpcyBOb25lOgogICAgcmFpc2UgVmFsdWVFcnJvcigiR0lUSFVCX0VOViBub3Qgc2V0LiBNdXN0IGJlIHJ1biBpbnNpZGUgR2l0SHViIEFjdGlvbnMuIikKCkRFTElNSVRFUiA9ICJFT0YiCgoKZGVmIHNldF9lbnYoZW52KToKCiAgICBlbnYgPSB5YW1sLmxvYWQoZW52LCBMb2FkZXI9eWFtbC5CYXNlTG9hZGVyKQogICAgcHJpbnQoanNvbi5kdW1wcyhlbnYsIGluZGVudD0yKSkKCiAgICBpZiBub3QgaXNpbnN0YW5jZShlbnYsIGRpY3QpOgogICAgICAgIHRpdGxlID0gImBlbnZgIG11c3QgYmUgbWFwcGluZyIKICAgICAgICBtZXNzYWdlID0gZiJgZW52YCBtdXN0IGJlIG1hcHBpbmcgb2YgZW52IHZhcmlhYmxlcyB0byB2YWx1ZXMsIGdvdCB0eXBlIHt0eXBlKGVudil9IgogICAgICAgIHByaW50KGYiOjplcnJvciB0aXRsZT17dGl0bGV9Ojp7bWVzc2FnZX0iKQogICAgICAgIGV4aXQoMSkKCiAgICBmb3IgaywgdiBpbiBlbnYuaXRlbXMoKToKCiAgICAgICAgaWYgbm90IGlzaW5zdGFuY2Uodiwgc3RyKToKICAgICAgICAgICAgdGl0bGUgPSAiYGVudmAgdmFsdWVzIG11c3QgYmUgc3RyaW5ncyIKICAgICAgICAgICAgbWVzc2FnZSA9IGYiYGVudmAgdmFsdWVzIG11c3QgYmUgc3RyaW5ncywgYnV0IHZhbHVlIG9mIHtrfSBoYXMgdHlwZSB7dHlwZSh2KX0iCiAgICAgICAgICAgIHByaW50KGYiOjplcnJvciB0aXRsZT17dGl0bGV9Ojp7bWVzc2FnZX0iKQogICAgICAgICAgICBleGl0KDEpCgogICAgICAgIHYgPSB2LnNwbGl0KCJcbiIpCgogICAgICAgIHdpdGggb3BlbihHSVRIVUJfRU5WLCAiYSIpIGFzIGY6CiAgICAgICAgICAgIGlmIGxlbih2KSA9PSAxOgogICAgICAgICAgICAgICAgZi53cml0ZShmIntrfT17dlswXX1cbiIpCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBmb3IgbGluZSBpbiB2OgogICAgICAgICAgICAgICAgICAgIGFzc2VydCBsaW5lLnN0cmlwKCkgIT0gREVMSU1JVEVSCiAgICAgICAgICAgICAgICBmLndyaXRlKGYie2t9PDx7REVMSU1JVEVSfVxuIikKICAgICAgICAgICAgICAgIGZvciBsaW5lIGluIHY6CiAgICAgICAgICAgICAgICAgICAgZi53cml0ZShmIntsaW5lfVxuIikKICAgICAgICAgICAgICAgIGYud3JpdGUoZiJ7REVMSU1JVEVSfVxuIikKCiAgICAgICAgcHJpbnQoZiJ7a30gd3JpdHRlbiB0byBHSVRIVUJfRU5WIikKCgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgc2V0X2VudihzeXMuYXJndlsxXSkK
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
submodules: ${{ inputs.submodules }}
- name: Install dependencies
if: ${{ inputs.libraries != '' }}
uses: ConorMacBride/install-package@main
with:
apt: ${{ inputs.libraries }}
- id: build
uses: OpenAstronomy/build-python-dist@main
with:
test_extras: ${{ inputs.test_extras }}
test_command: ${{ inputs.test_command }}
pure_python_wheel: false
- uses: actions/upload-artifact@v3
with:
path: dist/*
upload:
name: Upload
needs: [targets, build_wheels, build_sdist]
runs-on: ubuntu-latest
if: |
always() &&
needs.targets.result == 'success' &&
( needs.targets.outputs.upload_to_pypi == 'true' ||
inputs.upload_to_anaconda ) &&
needs.build_wheels.result != 'failure' &&
needs.build_sdist.result != 'failure'
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
name: Upload to PyPI
if: ${{ needs.targets.outputs.upload_to_pypi == 'true' }}
with:
user: __token__
password: ${{ secrets.pypi_token }}
repository-url: ${{ inputs.repository_url }}
- uses: OpenAstronomy/publish-wheels-anaconda@main
if: ${{ inputs.upload_to_anaconda }}
with:
anaconda_user: ${{ inputs.anaconda_user }}
anaconda_package: ${{ inputs.anaconda_package }}
anaconda_token: ${{ secrets.anaconda_token }}
keep_n_latest: ${{ inputs.anaconda_keep_n_latest }}