|
| 1 | +name: Release |
| 2 | + |
| 3 | +run-name: "Release ${{ github.ref_name }} · @${{ github.actor }}" |
| 4 | + |
| 5 | +# Publishing to PyPI uses Trusted Publishing (OIDC) — no API token is stored. |
| 6 | +# A release manager pushes a `vMAJOR.MINOR.PATCH` tag; the `build` and |
| 7 | +# `smoke-test` jobs run automatically, then the `publish` job pauses on the |
| 8 | +# `pypi` GitHub environment until a *different* release manager approves it |
| 9 | +# (required reviewers + prevent self-review + wait timer are configured on the |
| 10 | +# environment). |
| 11 | +on: |
| 12 | + push: |
| 13 | + tags: |
| 14 | + # Strictly vMAJOR.MINOR.PATCH with numeric parts (e.g. v0.2.2). `[0-9]+` |
| 15 | + # excludes pre-releases (v1.2.3rc1) and other non-release tags so they |
| 16 | + # never start the release run. The `pypi` environment tag rule and |
| 17 | + # approval gate are secondary controls; the version guard below is the |
| 18 | + # final backstop. |
| 19 | + - "v[0-9]+.[0-9]+.[0-9]+" |
| 20 | + # Manual dry run: builds and smoke-tests the current ref but never publishes |
| 21 | + # (the publish job is gated to tag pushes). Trigger from the Actions tab |
| 22 | + # ("Release" -> "Run workflow") or `gh workflow run release.yml --ref <branch>`. |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +# Least privilege by default; the publish job opts into `id-token: write`. |
| 26 | +permissions: |
| 27 | + contents: read |
| 28 | + |
| 29 | +concurrency: |
| 30 | + # Serialize releases per tag and never cancel an in-flight publish. |
| 31 | + group: release-${{ github.ref }} |
| 32 | + cancel-in-progress: false |
| 33 | + |
| 34 | +jobs: |
| 35 | + # ── Build the exact wheel + sdist that will be smoke-tested and published. ── |
| 36 | + build: |
| 37 | + name: Build distributions |
| 38 | + runs-on: ubuntu-latest |
| 39 | + timeout-minutes: 15 |
| 40 | + steps: |
| 41 | + - name: Check out repository |
| 42 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 43 | + with: |
| 44 | + persist-credentials: false |
| 45 | + - name: Install uv |
| 46 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 47 | + with: |
| 48 | + enable-cache: false |
| 49 | + - name: Verify the tag matches the package version |
| 50 | + # The published version comes from src/coreai_opt/_about.py, not the tag. |
| 51 | + # Fail early if they disagree so we never publish a mismatched/duplicate |
| 52 | + # version (PyPI uploads are immutable and cannot be overwritten). |
| 53 | + # Skipped on manual dry runs, where the ref is a branch, not a vX.Y.Z tag. |
| 54 | + if: github.event_name == 'push' |
| 55 | + run: | |
| 56 | + tag="${GITHUB_REF_NAME}" |
| 57 | + version="$(python3 -c "import runpy; print(runpy.run_path('src/coreai_opt/_about.py')['__version__'])")" |
| 58 | + echo "tag=${tag} package version=${version}" |
| 59 | + if [ "${tag}" != "v${version}" ]; then |
| 60 | + echo "::error::Tag ${tag} does not match package version v${version} (src/coreai_opt/_about.py). Bump __version__ to match the release tag." |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + - name: Build wheel and sdist |
| 64 | + run: uv build |
| 65 | + - name: Upload distributions |
| 66 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 67 | + with: |
| 68 | + name: dist |
| 69 | + path: dist/ |
| 70 | + if-no-files-found: error |
| 71 | + |
| 72 | + # ── Smoke test the exact built wheel and sdist via `make test-smoke`. ── |
| 73 | + # Reuses the repo's smoke suite (ci/nox/noxfile.py → tests/test_smoke.py) but |
| 74 | + # points it at the pre-built artifact instead of rebuilding, so we test the |
| 75 | + # bytes we are about to publish. `make test-smoke` runs across every supported |
| 76 | + # Python version internally. |
| 77 | + smoke-test: |
| 78 | + name: Smoke test (${{ matrix.format }}, ${{ matrix.torch_group }}) |
| 79 | + needs: build |
| 80 | + runs-on: ubuntu-latest |
| 81 | + timeout-minutes: 60 |
| 82 | + env: |
| 83 | + INSTALL_PRECOMMIT: "false" |
| 84 | + strategy: |
| 85 | + fail-fast: false |
| 86 | + matrix: |
| 87 | + # Test both distribution formats against every supported torch version, |
| 88 | + # mirroring the PR CI smoke matrix (ci.yaml). |
| 89 | + format: [wheel, sdist] |
| 90 | + torch_group: [torch_2_8, torch_2_9, torch_2_10, torch_2_11] |
| 91 | + steps: |
| 92 | + - name: Check out repository |
| 93 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 94 | + with: |
| 95 | + persist-credentials: false |
| 96 | + - name: Install uv |
| 97 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 98 | + with: |
| 99 | + enable-cache: false |
| 100 | + - name: Download distributions |
| 101 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 102 | + with: |
| 103 | + name: dist |
| 104 | + path: dist/ |
| 105 | + - name: Smoke test the built ${{ matrix.format }} against ${{ matrix.torch_group }} |
| 106 | + run: | |
| 107 | + case "${{ matrix.format }}" in |
| 108 | + wheel) dist="$(echo dist/*.whl)" ;; |
| 109 | + sdist) dist="$(echo dist/*.tar.gz)" ;; |
| 110 | + esac |
| 111 | + test -f "${dist}" || { echo "::error::No ${{ matrix.format }} found in dist/"; exit 1; } |
| 112 | + echo "Smoke testing ${dist} against ${{ matrix.torch_group }}" |
| 113 | + make test-smoke SMOKE_TEST_DIST="${dist}" TORCH_GROUP="${{ matrix.torch_group }}" |
| 114 | +
|
| 115 | + # ── Publish to PyPI via Trusted Publishing. Only this job holds `id-token`. ── |
| 116 | + # It builds nothing and runs no project code: it just downloads the vetted |
| 117 | + # artifact and uploads it, keeping build/test dependencies out of the |
| 118 | + # OIDC-privileged job. |
| 119 | + publish: |
| 120 | + name: Publish to PyPI |
| 121 | + needs: [build, smoke-test] |
| 122 | + # Publish only on a tag push (never on a manual dry run) and never from forks. |
| 123 | + if: github.event_name == 'push' && github.repository == 'apple/coreai-optimization' |
| 124 | + runs-on: ubuntu-latest |
| 125 | + timeout-minutes: 15 |
| 126 | + environment: |
| 127 | + name: pypi |
| 128 | + url: https://pypi.org/p/coreai-opt |
| 129 | + permissions: |
| 130 | + id-token: write # mint the OIDC token PyPI validates for Trusted Publishing |
| 131 | + contents: read |
| 132 | + steps: |
| 133 | + - name: Install uv |
| 134 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 135 | + with: |
| 136 | + enable-cache: false |
| 137 | + - name: Download distributions |
| 138 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 139 | + with: |
| 140 | + name: dist |
| 141 | + path: dist/ |
| 142 | + - name: Publish to PyPI |
| 143 | + # `always` requires Trusted Publishing (OIDC) — no fallback to tokens. |
| 144 | + run: uv publish --trusted-publishing always |
0 commit comments