name: Release on: push: branches: - main - stable # Allow manual triggering from the Actions tab. Useful for re-running the # release flow when a push from the default GITHUB_TOKEN (e.g. a clean # cherry-pick from the backport workflow, or a merged "Version Packages" # PR) does not automatically trigger this workflow. workflow_dispatch: concurrency: ${{ github.workflow }}-${{ github.ref }} permissions: contents: read jobs: release: name: Release runs-on: ubuntu-latest permissions: contents: write pull-requests: write id-token: write env: TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ vars.TURBO_TEAM }} # Main is currently the v5 release line. Stable should set this to 4; # future version branches should update it to their release major. RELEASE_VERSION: 5 steps: - name: Checkout Repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Configure Git identity run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" # Keep setup-node because registry-url configures npm publishing. pnpm/setup # handles the pnpm store cache after Node.js is available, and must not # install a second Node.js from `.node-version` (`node-version-file: false`). - name: Setup Node.js 24.x uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 24.x registry-url: 'https://registry.npmjs.org' - name: Setup pnpm uses: pnpm/setup@fa36a5ef7dcdefc3a7cb25655c122e00cf6e636e # v3.1.2 with: install: true require-lockfile: true cache: true node-version-file: false - name: Check package release major run: node .github/scripts/check-release-major.js "$RELEASE_VERSION" # changesets/action v2 pairs with @changesets/cli v3 (it refuses a v2 # CLI). It pushes the release commit and tags through the GitHub API, so # they are signed with GitHub's key as the branch rules require; there is # no `commitMode` input any more. # # These are its select-mode, publish and version sub-actions rather than # the combined `changesets/action`, which publishes only when no # changesets are pending. Under that rule a "Version Packages" PR merged # without every pending changeset strands its versions: every later run, # re-runs included, sees the leftover changeset and only versions. 5.2.0 # was stranded this way when the run that should have added #4733's # changeset to #4687 died on a GitHub 502 and #4687 was merged stale. It # was published by dispatching this workflow on #4687's head. A queued run # cancelled by a newer push (see `concurrency` above) strands a release # the same way with no outage at all. So the registry decides whether to # publish, and the release PR is still refreshed in the same run. - name: Select release mode id: mode uses: changesets/action/select-mode@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2 # `select-mode` asks the registry only when no changesets are pending. # Otherwise ask it here: `publish-plan` is the diff `changeset publish` # acts on, so it is empty on every commit except one a stale release PR # left behind. A registry error here must not turn an ordinary push red; # the verify step below retries and still reports any version missing. - name: Find versions on this commit that are not on npm id: unpublished if: steps.mode.outputs.mode != 'publish' continue-on-error: true run: | pnpm exec changeset publish-plan --output "$RUNNER_TEMP/publish-plan.json" missing=$(jq -r '[.plan[][] | select(.kind == "publish") | "\(.name)@\(.version)"] | join(" ")' "$RUNNER_TEMP/publish-plan.json") if [ -n "$missing" ]; then echo "::warning::Changesets are pending, but these versions on this commit were never published. Publishing them now: $missing" echo "stale=true" >> "$GITHUB_OUTPUT" else echo "stale=false" >> "$GITHUB_OUTPUT" fi # The action learns what the publish script published from an NDJSON file # it names in `CHANGESETS_OUTPUT`, which `pnpm ci:publish` inherits and # passes on to `changeset publish`; without it the action sees nothing # published and skips the release. Note the output is # `published-packages`, not `publishedPackages`. - name: Publish to npm id: publish if: steps.mode.outputs.mode == 'publish' || steps.unpublished.outputs.stale == 'true' uses: changesets/action/publish@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2 with: script: pnpm ci:publish create-github-releases: false # `changeset publish` runs one `pnpm publish` per package and one failure # leaves the release half-shipped, with `workflow` possibly pointing at a # `@workflow/core` that is not on npm yet. 5.0.0-beta.48 shipped 7 of 21 # packages on its first attempt, and the failure that stopped it crashed # the publish loop before naming the packages it took down. Cross-check # every publishable manifest on this commit against the registry, whatever # the publish step's outcome, so the job says exactly what is missing. - name: Verify every package version on this commit is on npm if: ${{ !cancelled() && steps.mode.outcome == 'success' }} run: node scripts/check-published.mjs - name: Create GitHub Release if: steps.publish.outputs.published == 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PUBLISHED_PACKAGES: ${{ steps.publish.outputs.published-packages }} run: | # Generate release notes (PUBLISHED_PACKAGES filters to only include packages from this release) RELEASE_JSON=$(node scripts/generate-release-notes.mjs) TAG=$(echo "$RELEASE_JSON" | jq -r '.tag') TITLE=$(echo "$RELEASE_JSON" | jq -r '.title') BODY=$(echo "$RELEASE_JSON" | jq -r '.body') # Prerelease is derived from the published version rather than the # branch: a version carrying a prerelease identifier (5.1.0-beta.1) # is a prerelease wherever it was cut, and `main` publishes GA # versions from 5.0.0 on. VERSION="${TAG##*@}" if [ "$VERSION" != "${VERSION#*-}" ]; then PRERELEASE="true" else PRERELEASE="false" fi # GitHub's "Latest" marker belongs to the current GA line, which # lives on `main`. Maintenance branches (`stable` = 4.x) publish # GA versions too, but must never claim the marker. if [ "$PRERELEASE" = "false" ] && [ "$GITHUB_REF_NAME" = "main" ]; then LATEST_FLAG="--latest" else LATEST_FLAG="--latest=false" fi # Check if a release with this tag already exists if gh release view "$TAG" &>/dev/null; then echo "Release $TAG already exists, updating..." gh release edit "$TAG" \ --title "$TITLE" \ --notes "$BODY" \ $LATEST_FLAG \ --prerelease=$PRERELEASE else echo "Creating new release $TAG..." gh release create "$TAG" \ --target "${{ github.sha }}" \ --title "$TITLE" \ --notes "$BODY" \ $LATEST_FLAG \ --prerelease=$PRERELEASE fi # A broken Slack token must not turn a successful release red: the Aug 26 # and Aug 31 releases published every package and still failed here # (`token_expired`, then `invalid_auth`), which taught people to read a # red Release job as noise. Surface it as a warning instead. - name: Post release notes to Slack if: steps.publish.outputs.published == 'true' continue-on-error: true env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} SLACK_RELEASE_CHANNEL_ID: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }} PUBLISHED_PACKAGES: ${{ steps.publish.outputs.published-packages }} run: | if [ -z "$SLACK_BOT_TOKEN" ] || [ -z "$SLACK_RELEASE_CHANNEL_ID" ]; then echo "Missing Slack secrets: SLACK_BOT_TOKEN and/or SLACK_RELEASE_CHANNEL_ID" exit 1 fi # Post to Slack via chat.postMessage (payload is chunked to Slack limits) node scripts/generate-release-slack-payload.mjs --post # The version sub-action commits every file that differs from this # commit, untracked ones included, to the release PR branch, and # `changeset version` rewrites the CHANGELOGs and manifests that the # release-notes steps above read. So it runs last, on a tree reset to this # commit: a publish above leaves build output behind, and a publish that # failed partway can leave a `prepack` copy its `postpack` never removed. # It runs even when an earlier step failed, so a failed publish does not # also leave the release PR behind main. - name: Reset the working tree to this commit id: reset if: ${{ !cancelled() && steps.mode.outputs.mode == 'version' }} run: git reset --hard HEAD && git clean -fd - name: Create or update the release pull request if: ${{ !cancelled() && steps.reset.outcome == 'success' }} uses: changesets/action/version@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2 with: script: pnpm ci:version