From 29fa019f46a05a15e3000da5f7fc5c94c7ed8d24 Mon Sep 17 00:00:00 2001 From: Marquess Valdez Date: Thu, 28 Sep 2023 10:25:30 -0700 Subject: [PATCH] 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 --- .github/test_events/README.md | 11 +++ .github/test_events/python_prerelease.json | 78 ++++++++++++++++++++++ .github/test_events/python_release.json | 78 ++++++++++++++++++++++ .github/workflows/release-python.yml | 30 +++++++-- README.md | 4 ++ 5 files changed, 195 insertions(+), 6 deletions(-) create mode 100644 .github/test_events/README.md create mode 100644 .github/test_events/python_prerelease.json create mode 100644 .github/test_events/python_release.json diff --git a/.github/test_events/README.md b/.github/test_events/README.md new file mode 100644 index 000000000..d6b476037 --- /dev/null +++ b/.github/test_events/README.md @@ -0,0 +1,11 @@ +# GitHub Test Events + +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. + +For example, to simulate what will happen in GitHub actions run when a Python pre-release is published, you can run: + +```sh +act release -n -e .github/test_events/prerelease_python.json +``` + +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). diff --git a/.github/test_events/python_prerelease.json b/.github/test_events/python_prerelease.json new file mode 100644 index 000000000..90c8bc277 --- /dev/null +++ b/.github/test_events/python_prerelease.json @@ -0,0 +1,78 @@ +{ + "action": "published", + "release": { + "url": "https://api.github.com/repos/octocat/Hello-World/releases/1", + "html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0", + "assets_url": "https://api.github.com/repos/octocat/Hello-World/releases/1/assets", + "upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}", + "tarball_url": "https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0", + "discussion_url": "https://github.com/octocat/Hello-World/discussions/90", + "id": 1, + "node_id": "MDc6UmVsZWFzZTE=", + "tag_name": "python/v1.0.0", + "target_commitish": "master", + "name": "v1.0.0", + "body": "Description of the release", + "draft": false, + "prerelease": true, + "created_at": "2013-02-27T19:35:32Z", + "published_at": "2013-02-27T19:35:32Z", + "author": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "assets": [ + { + "url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1", + "browser_download_url": "https://github.com/octocat/Hello-World/releases/download/v1.0.0/example.zip", + "id": 1, + "node_id": "MDEyOlJlbGVhc2VBc3NldDE=", + "name": "example.zip", + "label": "short description", + "state": "uploaded", + "content_type": "application/zip", + "size": 1024, + "download_count": 42, + "created_at": "2013-02-27T19:35:32Z", + "updated_at": "2013-02-27T19:35:32Z", + "uploader": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + } + } + ] + } +} diff --git a/.github/test_events/python_release.json b/.github/test_events/python_release.json new file mode 100644 index 000000000..6792f3d52 --- /dev/null +++ b/.github/test_events/python_release.json @@ -0,0 +1,78 @@ +{ + "action": "published", + "release": { + "url": "https://api.github.com/repos/octocat/Hello-World/releases/1", + "html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0", + "assets_url": "https://api.github.com/repos/octocat/Hello-World/releases/1/assets", + "upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}", + "tarball_url": "https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0", + "discussion_url": "https://github.com/octocat/Hello-World/discussions/90", + "id": 1, + "node_id": "MDc6UmVsZWFzZTE=", + "tag_name": "python/v1.0.0", + "target_commitish": "master", + "name": "v1.0.0", + "body": "Description of the release", + "draft": false, + "prerelease": false, + "created_at": "2013-02-27T19:35:32Z", + "published_at": "2013-02-27T19:35:32Z", + "author": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "assets": [ + { + "url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1", + "browser_download_url": "https://github.com/octocat/Hello-World/releases/download/v1.0.0/example.zip", + "id": 1, + "node_id": "MDEyOlJlbGVhc2VBc3NldDE=", + "name": "example.zip", + "label": "short description", + "state": "uploaded", + "content_type": "application/zip", + "size": 1024, + "download_count": 42, + "created_at": "2013-02-27T19:35:32Z", + "updated_at": "2013-02-27T19:35:32Z", + "uploader": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + } + } + ] + } +} diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml index fec5a2e6d..aa32d1b03 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/release-python.yml @@ -5,17 +5,27 @@ on: types: [published] workflow_dispatch: description: "Manually publish release" + inputs: + publishWheels: + description: "Build and publish wheels to PyPI" + type: boolean + default: false jobs: is-python-release: - if: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.event.release.tag_name, 'python/v') }} + if: github.event_name == 'workflow_dispatch' || startsWith(github.event.release.tag_name, 'python/v') runs-on: ubuntu-latest steps: - run: echo "Release tag starts with python/v, proceeding with release" + should-publish-wheels: + if: (github.event_name == 'workflow_dispatch' && inputs.publishWheels) || (github.event_name == 'release' && !github.event.release.prerelease) + runs-on: ubuntu-latest + steps: + - run: echo "Publishing wheels" macos: runs-on: macos-12 - needs: is-python-release + needs: [is-python-release, should-publish-wheels] env: CXXFLAGS: "-std=c++11 -stdlib=libc++" strategy: @@ -54,7 +64,7 @@ jobs: linux: runs-on: ubuntu-latest - needs: is-python-release + needs: [is-python-release, should-publish-wheels] env: CXXFLAGS: "-std=c++11" strategy: @@ -91,6 +101,7 @@ jobs: windows: runs-on: windows-latest + needs: [is-python-release, should-publish-wheels] strategy: matrix: python-version: ['3.8', '3.9', '3.10', '3.11'] @@ -155,13 +166,20 @@ jobs: name: wheels path: dist - release: - name: Release + publish: runs-on: ubuntu-latest + # `needs` forces this job to wait until all specified jobs + # are finished to run. Typically, those jobs would all have + # to be successful, but when combined with `if: always()`, + # this job is allowed to run after all the needed jobs + # finish, regardless of their outcome. In this case, we + # still make sure that at least a source distribution + # can be published. needs: [ macos, linux, windows, sdist ] + if: always() && needs.sdist.result == 'success' steps: - uses: actions/download-artifact@v3 - - name: Publish to PyPi + - name: Publish to PyPI env: MATURIN_USERNAME: ${{ secrets.PYPI_USERNAME }} MATURIN_PASSWORD: ${{ secrets.PYPI_PASSWORD }} diff --git a/README.md b/README.md index c1a39e260..f4f87d35d 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ To release, manually run the `Prepare Release` workflow in GitHub Actions. Pre-releases for both the library crate and Python package happen automatically on merge to main. +## CI + +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. + [cargo-make]: https://sagiegurari.github.io/cargo-make/ [Quantum Cloud Services]: https://docs.rigetti.com/qcs/ [Quil]: https://github.com/quil-lang/quil