-
Notifications
You must be signed in to change notification settings - Fork 13
273 lines (267 loc) · 14.5 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
266
267
268
269
270
271
272
273
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@v5
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: aW1wb3J0IGpzb24KaW1wb3J0IG9zCmltcG9ydCByZQoKaW1wb3J0IGNsaWNrCmltcG9ydCB5YW1sCgpNQUNISU5FX1RZUEUgPSB7CiAgICAibGludXgiOiAidWJ1bnR1LWxhdGVzdCIsCiAgICAibWFjb3MiOiAibWFjb3MtbGF0ZXN0IiwKICAgICJ3aW5kb3dzIjogIndpbmRvd3MtbGF0ZXN0IiwKfQoKQ0lCV19CVUlMRCA9IG9zLmVudmlyb24uZ2V0KCJDSUJXX0JVSUxEIiwgIioiKQpDSUJXX0FSQ0hTID0gb3MuZW52aXJvbi5nZXQoIkNJQldfQVJDSFMiLCAiYXV0byIpCgoKQGNsaWNrLmNvbW1hbmQoKQpAY2xpY2sub3B0aW9uKCItLXRhcmdldHMiLCBkZWZhdWx0PSIiKQpkZWYgbG9hZF9idWlsZF90YXJnZXRzKHRhcmdldHMpOgogICAgIiIiU2Nya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b3IgYXJjaCBpbiBbImFhcmNoNjQiLCAiYXJtNjQiLCAidW5pdmVyc2FsMiJdOgogICAgICAgIGlmIHRhcmdldC5lbmRzd2l0aChhcmNoKToKICAgICAgICAgICAgcmV0dXJuIGFyY2gKICAgIHJldHVybiBDSUJXX0FSQ0hTCgoKZGVmIGdldF9hcnRpZmFjdF9uYW1lKHRhcmdldCk6CiAgICBhcnRpZmFjdF9uYW1lID0gcmUuc3ViKHIiW1xcIC86PD58Kj9cIiddIiwgIi0iLCB0YXJnZXQpCiAgICBhcnRpZmFjdF9uYW1lID0gcmUuc3ViKHIiLSsiLCAiLSIsIGFydGlmYWN0X25hbWUpCiAgICByZXR1cm4gYXJ0aWZhY3RfbmFtZQoKCmRlZiBnZXRfbWF0cml4X2l0ZW0odGFyZ2V0KToKICAgIHJldHVybiB7CiAgICAgICAgInRhcmdldCI6IHRhcmdldCwKICAgICAgICAib3MiOiBnZXRfb3ModGFyZ2V0KSwKICAgICAgICAiQ0lCV19CVUlMRCI6IGdldF9jaWJ3X2J1aWxkKHRhcmdldCksCiAgICAgICAgIkNJQldfQVJDSFMiOiBnZXRfY2lid19hcmNocyh0YXJnZXQpLAogICAgICAgICJhcnRpZmFjdC1uYW1lIjogZ2V0X2FydGlmYWN0X25hbWUodGFyZ2V0KSwKICAgIH0KCgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgbG9hZF9idWlsZF90YXJnZXRzKCkK
- 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@v3
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@v5
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.16.4
with:
output-dir: dist
env:
CIBW_BUILD: ${{ matrix.CIBW_BUILD }}
CIBW_ARCHS: ${{ matrix.CIBW_ARCHS }}
- uses: actions/upload-artifact@v4
if: |
needs.targets.outputs.upload_to_pypi == 'true' || inputs.upload_to_anaconda
with:
name: "dist-${{ matrix.artifact-name }}"
path: dist/*
build_sdist:
name: Build source distribution
needs: [targets]
if: ${{ inputs.sdist }}
runs-on: ${{ inputs.sdist-runs-on }}
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- uses: actions/setup-python@v5
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@v4
if: |
needs.targets.outputs.upload_to_pypi == 'true' || inputs.upload_to_anaconda
with:
name: dist-sdist
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@v4
with:
pattern: dist-*
path: dist
merge-multiple: true
- 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 }}