-
Notifications
You must be signed in to change notification settings - Fork 14
254 lines (246 loc) · 11 KB
/
build_wheels.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
name: Build PyPop
on:
workflow_dispatch:
pull_request:
paths-ignore:
- '**.md'
- '**.rst'
- 'CITATION.cff'
- '.zenodo.json'
- 'website/**'
- '.github/dependabot.yml'
- '.github/release-drafter.yml'
- '.github/ISSUE_TEMPLATE/**'
- '.github/workflows/documentation.yaml'
- '.github/workflows/buildjet_arm64.yml'
- '.github/workflows/release-drafter.yml'
- '.gitattributes'
push:
paths-ignore:
- '**.md'
- '**.rst'
- 'CITATION.cff'
- '.zenodo.json'
- 'website/**'
- '.github/dependabot.yml'
- '.github/release-drafter.yml'
- '.github/ISSUE_TEMPLATE/**'
- '.github/workflows/documentation.yaml'
- '.github/workflows/buildjet_arm64.yml'
- '.github/workflows/release-drafter.yml'
- '.gitattributes'
release:
types:
- published
jobs:
skip_publish_zenodo:
name: Non publication, Zenodo skip
runs-on: ubuntu-latest
# FIXME: this is the default action, the logical inverse of the
# below "if" in publish_zenodo: a bit hacky, but it works
if: (github.event_name == 'release' && github.event.action == 'published' && github.event.release.prerelease == false) == false
steps:
- name: Skip Zenodo step unless publishing release
run: |
echo "Not a publication release, skipping Zenodo"
echo "github.ref: ${{ toJson(github.ref) }}"
echo "github.event_name: ${{ toJson(github.event_name) }}"
echo "github.event.action: ${{ toJson(github.event.action) }}"
publish_zenodo:
name: Production release, Zenodo publication
runs-on: ubuntu-latest
# "else" we *are* publishing something, only works for non-pre-releases on the main branch
if: github.event.release.target_commitish == 'main' && github.event_name == 'release' && github.event.action == 'published' && github.event.release.prerelease == false
steps:
- name: Checkout the contents of your repository
uses: actions/checkout@v4
- name: Upsert the version and related ids in the metadata in .zenodo.json
run: |
echo "GITHUB_REF_NAME = $GITHUB_REF_NAME | GITHUB_REF = $GITHUB_REF | GITHUB_EVENT_PATH = $GITHUB_EVENT_PATH"
echo "github.event.release.target_commitish = ${{ github.event.release.target_commitish }}"
# convert semver to Python-style version
VERSION_PYTHON_STYLE=$(GITHUB_REF_NAME=$GITHUB_REF_NAME python -c 'import os; from packaging import version; print(str(version.Version(os.getenv("GITHUB_REF_NAME"))))')
echo "VERSION_PYTHON_STYLE = $VERSION_PYTHON_STYLE"
# cp .zenodo.json .zenodo.orig.json
# update the 'related_identifiers' to use exact tree and pypi packaage
cat .zenodo.json | jq "(.related_identifiers[] | (select (.relation == \"isSourceOf\" and .resource_type == \"software\")) | select (.identifier | startswith(\"https://pypi.org/project/pypop-genomics\")).identifier) |= \"https://pypi.org/project/pypop-genomics/$VERSION_PYTHON_STYLE\"" | jq "(.related_identifiers[] | (select (.relation == \"isSupplementTo\" and .resource_type == \"software\")) | select (.identifier | startswith(\"https://github.com/alexlancaster/pypop\")).identifier) |= \"https://github.com/alexlancaster/pypop/tree/$GITHUB_REF_NAME\"" > .zenodo.mod.json
# update the version number
echo "{\"version\": \"$GITHUB_REF_NAME\"}" | cat .zenodo.mod.json - | jq -s add > .zenodo.json
# debugging only
cat .zenodo.json
rm .zenodo.mod.json
- name: Upsert the version in the metadata in CITATION.cff
run: |
yq -i ".version = \"$GITHUB_REF_NAME\"" CITATION.cff
- name: Push changes back to repo files
run: |
git fetch origin
git config --global user.name "ci-pypop"
git config --global user.email "username@users.noreply.github.com"
git checkout -b $GITHUB_REF_NAME-with-upserting-changes-pre-upload
git add .zenodo.json CITATION.cff
git commit -m "Upserted version into CITATION.cff and into .zenodo.json"
git checkout ${{ github.event.release.target_commitish }}
git merge $GITHUB_REF_NAME-with-upserting-changes-pre-upload
git push origin ${{ github.event.release.target_commitish }}
# FIXME: removing files marked with 'export-ignore' 'set' in .gitattributes
# before zenodraft creates the zipball using https://stackoverflow.com/a/30573319
# to ensure that we handle filenames with potential ':' or newlines
git ls-files -z|git check-attr --stdin -z export-ignore |sed -zne 'x;n;n;s/^set$//;t print;b;:print;x;p'|xargs --null rm
# FIXME: need to also remove orphaned empty directories resulting from above
find . -empty -type d -delete
# git tag -d $GITHUB_REF_NAME
# git push --follow-tags origin :$GITHUB_REF
# git tag $GITHUB_REF_NAME
# git push origin $GITHUB_REF
# git ls-remote origin $GITHUB_REF
- name: Create a draft snapshot of your repository contents as a new
version in test collection on Zenodo using metadata
from repository file .zenodo.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ZENODO_ACCESS_TOKEN: ${{ secrets.ZENODO_ACCESS_TOKEN }}
# uses: zenodraft/action@0.10.0
uses: alexlancaster/zenodraft-action@0.10.2
with:
collection: 10080667
metadata: .zenodo.json
publish: false
sandbox: false
compression: zip
upsert-doi: true
upsert-location: doi
verbose: true
#
# FIXME: disabled the rest of these steps (already done by zenodraft)
#
- name: Get existing release
if: false
id: get_existing_release
uses: cardinalby/git-get-release-action@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
releaseId: ${{ github.event.release.id }}
- name: Delete old release
if: false
uses: liudonghua123/delete-release-action@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
release_id: ${{ github.event.release.id }}
- name: Recreate release with new tag
if: false
id: recreate_release
uses: joutvhu/create-release@v1
with:
tag_name: ${{ github.event.release.tag_name }}
name: ${{ steps.get_existing_release.outputs.name }}
body: ${{ steps.get_existing_release.outputs.body }}
# FIXME: have to set these both to false, because not copied
# from the original release properly
# draft: ${{ steps.get_existing_release.outputs.draft }}
# prerelease: ${{ steps.get_existing_release.outputs.draft }}
draft: false
prerelease: false
target_commitish: ${{ steps.get_existing_release.outputs.target_commitish }}
on_release_exists: update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.PYPOP_RELEASE_TOKEN }}
build_wheels:
name: Build wheels on ${{ matrix.os }}
# depend on zenodo, to make sure updated CITATION.cff gets into builds
# this only results in changes upon production releases
needs: [publish_zenodo, skip_publish_zenodo]
# trying solution here: https://github.com/actions/runner/issues/491#issuecomment-1507495166
# so that it works if either job in "needs" completes
if: always() && !cancelled() && !failure()
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-11, windows-2019]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# FIXME: if on a release, use the tag name, not original SHA because it might be changed (somewhat hacky)
ref: ${{ (github.event_name == 'release' && github.event.action == 'published') && github.ref_name || '' }}
- name: Build and test wheels
uses: pypa/cibuildwheel@v2.16.2
with:
package-dir: .
output-dir: wheelhouse
config-file: "{package}/pyproject.toml"
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl
# path: ./wheelhouse/* use if more than wheels are wanted
build_sdist:
name: Build source distribution
# depend on zenodo, to make sure updated CITATION.cff gets into builds
needs: [publish_zenodo, skip_publish_zenodo]
if: always() && !cancelled() && !failure()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: # FIXME: if on a release, use the tag name, not original SHA because it might be changed (somewhat hacky)
ref: ${{ (github.event_name == 'release' && github.event.action == 'published') && github.ref_name || '' }}
- name: Build sdist
run: pipx run build --sdist
- uses: actions/upload-artifact@v4
with:
path: dist/*.tar.gz
upload_gh_release:
name: Upload binary wheels and sdist to GH release page
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# alternatively, to publish when a GitHub Release is created, use the following rule:
if: github.event_name == 'release' && github.event.action == 'published' && always() && !cancelled() && !failure()
steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- uses: softprops/action-gh-release@v1
name: Uploading binaries to release page
with:
files: dist/*
upload_test_pypi:
name: Upload to Test_PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: test_pypi
permissions:
id-token: write
# drop requirement of 'main', release to test_pypi to test releases
if: github.event_name == 'release' && github.event.action == 'published' && always() && !cancelled() && !failure()
steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository_url: https://test.pypi.org/legacy/
upload_pypi:
name: Upload to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
if: github.event.release.target_commitish == 'main' && github.event_name == 'release' && github.event.action == 'published' && always() && !cancelled() && !failure()
steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1