Repository navigation
102 lines (92 loc) · 4.44 KB
/
Copy pathrelease.yml
File metadata and controls
102 lines (92 loc) · 4.44 KB
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
name: Release
on:
push:
branches: [main]
# Only one release run at a time: two concurrent runs would race to open or
# update the same "Version Packages" pull request.
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Changesets needs the history to work out what has already shipped.
fetch-depth: 0
# Publishing uses npm trusted publishing (OIDC), not a stored token: the
# registry trusts this repository's `release.yml` and nothing else, so
# there is no long-lived credential to leak or rotate, and provenance is
# attached automatically. It needs Node >= 22.14 and npm >= 11.5.1. Node
# 22 ships npm 10, so npm is pinned explicitly below. See "Releasing" in
# CONTRIBUTING.md for the one-time setup, and for why the first publish
# of each package is done by hand.
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 22
cache: npm
registry-url: https://registry.npmjs.org
- name: Install the npm that supports trusted publishing
run: npm install -g npm@11.21.0
# npm does not validate a trusted-publisher setup when it is saved, only
# when a publish is attempted, so a too-old npm would surface as an
# opaque auth failure in the middle of a release. Fail here instead.
- name: Check npm is new enough for trusted publishing
run: |
node -e '
const [a, b, c] = process.argv[1].split(".").map(Number);
if (a < 11 || (a === 11 && (b < 5 || (b === 5 && c < 1)))) {
console.error(`npm ${process.argv[1]} cannot do trusted publishing (need >= 11.5.1)`);
process.exit(1);
}
' "$(npm --version)"
- run: npm ci
# A release must not be the first time the build is exercised. CI runs
# these on the pull request too; repeating them here is what stops a
# green PR merged next to a red main from publishing anyway.
- run: npm run lint
- run: npm run typecheck
- run: npm run test
- run: npm run build
# Opens (or updates) a "Version Packages" pull request applying the
# pending changesets. Merging that PR is the release — versions bump,
# changelogs are written, and this workflow runs again on the merge
# commit with no changesets left, at which point `publish` runs instead.
#
# While a package is still `"private": true` — the deliberate hold on its
# first publish — `changeset version` still bumps it and writes its
# changelog, and `changeset publish` tags it but skips the registry
# (`privatePackages: { version: true, tag: true }` in
# .changeset/config.json). Removing `private` is not enough on its own:
# trusted publishing can only be configured for a package that already
# exists, so each package's first publish is done by hand, with
# `private` removed in that same pull request, and this workflow
# publishes it from the next release on. See "How publishing is
# authorised" in CONTRIBUTING.md.
#
# `version:packages` is `changeset version` plus `build:preview`, not
# `changeset version` alone. reference/preview.jsx is a committed
# artefact that quotes the package version, and CI fails any pull
# request where it has drifted — so a version bump that did not
# regenerate it would open a release pull request that cannot go green
# without a hand-pushed commit. Regenerating derived files is what the
# version script is for.
- name: Version or publish
uses: changesets/action@a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d # v1.9.0
with:
version: npm run version:packages
publish: npx changeset publish
commit: "chore: version packages"
title: "chore: version packages"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# No NODE_AUTH_TOKEN or NPM_TOKEN on purpose: `npm publish` exchanges
# this job's OIDC token (`id-token: write` above) for a short-lived
# publish credential. Adding a token here would make npm use it
# instead and quietly turn trusted publishing off.