Skip to content

Commit 29fa019

Browse files
authored
ci(python): Don't publish wheels automatically for pre-releases (#370)
* ci: Don't publish wheels automatically for pre-releases * add comment * clarify * remove test condition * wording * remove debug print
1 parent 0464ea1 commit 29fa019

File tree

5 files changed

+195
-6
lines changed

5 files changed

+195
-6
lines changed

.github/test_events/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# GitHub Test Events
2+
3+
This folder contains mock GitHub webhook events. They can be used as input to [nektos/act](https://github.com/nektos/act) to simulate what will happen for that event. This is useful for testing CI changes locally.
4+
5+
For example, to simulate what will happen in GitHub actions run when a Python pre-release is published, you can run:
6+
7+
```sh
8+
act release -n -e .github/test_events/prerelease_python.json
9+
```
10+
11+
These payloads are adapted from GitHub's examples in [Events that trigger workflows](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows).
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"action": "published",
3+
"release": {
4+
"url": "https://api.github.com/repos/octocat/Hello-World/releases/1",
5+
"html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
6+
"assets_url": "https://api.github.com/repos/octocat/Hello-World/releases/1/assets",
7+
"upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
8+
"tarball_url": "https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0",
9+
"zipball_url": "https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0",
10+
"discussion_url": "https://github.com/octocat/Hello-World/discussions/90",
11+
"id": 1,
12+
"node_id": "MDc6UmVsZWFzZTE=",
13+
"tag_name": "python/v1.0.0",
14+
"target_commitish": "master",
15+
"name": "v1.0.0",
16+
"body": "Description of the release",
17+
"draft": false,
18+
"prerelease": true,
19+
"created_at": "2013-02-27T19:35:32Z",
20+
"published_at": "2013-02-27T19:35:32Z",
21+
"author": {
22+
"login": "octocat",
23+
"id": 1,
24+
"node_id": "MDQ6VXNlcjE=",
25+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
26+
"gravatar_id": "",
27+
"url": "https://api.github.com/users/octocat",
28+
"html_url": "https://github.com/octocat",
29+
"followers_url": "https://api.github.com/users/octocat/followers",
30+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
31+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
32+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
33+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
34+
"organizations_url": "https://api.github.com/users/octocat/orgs",
35+
"repos_url": "https://api.github.com/users/octocat/repos",
36+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
37+
"received_events_url": "https://api.github.com/users/octocat/received_events",
38+
"type": "User",
39+
"site_admin": false
40+
},
41+
"assets": [
42+
{
43+
"url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1",
44+
"browser_download_url": "https://github.com/octocat/Hello-World/releases/download/v1.0.0/example.zip",
45+
"id": 1,
46+
"node_id": "MDEyOlJlbGVhc2VBc3NldDE=",
47+
"name": "example.zip",
48+
"label": "short description",
49+
"state": "uploaded",
50+
"content_type": "application/zip",
51+
"size": 1024,
52+
"download_count": 42,
53+
"created_at": "2013-02-27T19:35:32Z",
54+
"updated_at": "2013-02-27T19:35:32Z",
55+
"uploader": {
56+
"login": "octocat",
57+
"id": 1,
58+
"node_id": "MDQ6VXNlcjE=",
59+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
60+
"gravatar_id": "",
61+
"url": "https://api.github.com/users/octocat",
62+
"html_url": "https://github.com/octocat",
63+
"followers_url": "https://api.github.com/users/octocat/followers",
64+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
65+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
66+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
67+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
68+
"organizations_url": "https://api.github.com/users/octocat/orgs",
69+
"repos_url": "https://api.github.com/users/octocat/repos",
70+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
71+
"received_events_url": "https://api.github.com/users/octocat/received_events",
72+
"type": "User",
73+
"site_admin": false
74+
}
75+
}
76+
]
77+
}
78+
}
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"action": "published",
3+
"release": {
4+
"url": "https://api.github.com/repos/octocat/Hello-World/releases/1",
5+
"html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
6+
"assets_url": "https://api.github.com/repos/octocat/Hello-World/releases/1/assets",
7+
"upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
8+
"tarball_url": "https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0",
9+
"zipball_url": "https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0",
10+
"discussion_url": "https://github.com/octocat/Hello-World/discussions/90",
11+
"id": 1,
12+
"node_id": "MDc6UmVsZWFzZTE=",
13+
"tag_name": "python/v1.0.0",
14+
"target_commitish": "master",
15+
"name": "v1.0.0",
16+
"body": "Description of the release",
17+
"draft": false,
18+
"prerelease": false,
19+
"created_at": "2013-02-27T19:35:32Z",
20+
"published_at": "2013-02-27T19:35:32Z",
21+
"author": {
22+
"login": "octocat",
23+
"id": 1,
24+
"node_id": "MDQ6VXNlcjE=",
25+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
26+
"gravatar_id": "",
27+
"url": "https://api.github.com/users/octocat",
28+
"html_url": "https://github.com/octocat",
29+
"followers_url": "https://api.github.com/users/octocat/followers",
30+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
31+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
32+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
33+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
34+
"organizations_url": "https://api.github.com/users/octocat/orgs",
35+
"repos_url": "https://api.github.com/users/octocat/repos",
36+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
37+
"received_events_url": "https://api.github.com/users/octocat/received_events",
38+
"type": "User",
39+
"site_admin": false
40+
},
41+
"assets": [
42+
{
43+
"url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1",
44+
"browser_download_url": "https://github.com/octocat/Hello-World/releases/download/v1.0.0/example.zip",
45+
"id": 1,
46+
"node_id": "MDEyOlJlbGVhc2VBc3NldDE=",
47+
"name": "example.zip",
48+
"label": "short description",
49+
"state": "uploaded",
50+
"content_type": "application/zip",
51+
"size": 1024,
52+
"download_count": 42,
53+
"created_at": "2013-02-27T19:35:32Z",
54+
"updated_at": "2013-02-27T19:35:32Z",
55+
"uploader": {
56+
"login": "octocat",
57+
"id": 1,
58+
"node_id": "MDQ6VXNlcjE=",
59+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
60+
"gravatar_id": "",
61+
"url": "https://api.github.com/users/octocat",
62+
"html_url": "https://github.com/octocat",
63+
"followers_url": "https://api.github.com/users/octocat/followers",
64+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
65+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
66+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
67+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
68+
"organizations_url": "https://api.github.com/users/octocat/orgs",
69+
"repos_url": "https://api.github.com/users/octocat/repos",
70+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
71+
"received_events_url": "https://api.github.com/users/octocat/received_events",
72+
"type": "User",
73+
"site_admin": false
74+
}
75+
}
76+
]
77+
}
78+
}

.github/workflows/release-python.yml

+24-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,27 @@ on:
55
types: [published]
66
workflow_dispatch:
77
description: "Manually publish release"
8+
inputs:
9+
publishWheels:
10+
description: "Build and publish wheels to PyPI"
11+
type: boolean
12+
default: false
813

914
jobs:
1015
is-python-release:
11-
if: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.event.release.tag_name, 'python/v') }}
16+
if: github.event_name == 'workflow_dispatch' || startsWith(github.event.release.tag_name, 'python/v')
1217
runs-on: ubuntu-latest
1318
steps:
1419
- run: echo "Release tag starts with python/v, proceeding with release"
20+
should-publish-wheels:
21+
if: (github.event_name == 'workflow_dispatch' && inputs.publishWheels) || (github.event_name == 'release' && !github.event.release.prerelease)
22+
runs-on: ubuntu-latest
23+
steps:
24+
- run: echo "Publishing wheels"
1525

1626
macos:
1727
runs-on: macos-12
18-
needs: is-python-release
28+
needs: [is-python-release, should-publish-wheels]
1929
env:
2030
CXXFLAGS: "-std=c++11 -stdlib=libc++"
2131
strategy:
@@ -54,7 +64,7 @@ jobs:
5464

5565
linux:
5666
runs-on: ubuntu-latest
57-
needs: is-python-release
67+
needs: [is-python-release, should-publish-wheels]
5868
env:
5969
CXXFLAGS: "-std=c++11"
6070
strategy:
@@ -91,6 +101,7 @@ jobs:
91101

92102
windows:
93103
runs-on: windows-latest
104+
needs: [is-python-release, should-publish-wheels]
94105
strategy:
95106
matrix:
96107
python-version: ['3.8', '3.9', '3.10', '3.11']
@@ -155,13 +166,20 @@ jobs:
155166
name: wheels
156167
path: dist
157168

158-
release:
159-
name: Release
169+
publish:
160170
runs-on: ubuntu-latest
171+
# `needs` forces this job to wait until all specified jobs
172+
# are finished to run. Typically, those jobs would all have
173+
# to be successful, but when combined with `if: always()`,
174+
# this job is allowed to run after all the needed jobs
175+
# finish, regardless of their outcome. In this case, we
176+
# still make sure that at least a source distribution
177+
# can be published.
161178
needs: [ macos, linux, windows, sdist ]
179+
if: always() && needs.sdist.result == 'success'
162180
steps:
163181
- uses: actions/download-artifact@v3
164-
- name: Publish to PyPi
182+
- name: Publish to PyPI
165183
env:
166184
MATURIN_USERNAME: ${{ secrets.PYPI_USERNAME }}
167185
MATURIN_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ To release, manually run the `Prepare Release` workflow in GitHub Actions.
5353

5454
Pre-releases for both the library crate and Python package happen automatically on merge to main.
5555

56+
## CI
57+
58+
This repository uses GitHub actions for its CI. If you are making changes to a workflow, consider using our [test events](.github/test_events/README.md) to help validate the changes.
59+
5660
[cargo-make]: https://sagiegurari.github.io/cargo-make/
5761
[Quantum Cloud Services]: https://docs.rigetti.com/qcs/
5862
[Quil]: https://github.com/quil-lang/quil

0 commit comments

Comments
 (0)