|
1 | | -// forked from https://github.com/elk-zone/elk/blob/main/scripts/release.ts |
| 1 | +// Forked from https://github.com/elk-zone/elk/blob/main/scripts/release.ts |
2 | 2 | // |
3 | | -// Runs after `bumpp` in `pnpm release`. It force-syncs `gh/release` to the |
4 | | -// commit being released and pushes the tag `bumpp` just made — the tag push is |
5 | | -// what triggers .github/workflows/release.yml, which is what actually publishes |
6 | | -// to npm. |
| 3 | +// Runs after `bumpp` in `pnpm release`. It pushes the tag `bumpp` just made — |
| 4 | +// that tag push is what triggers .github/workflows/release.yml, which is what |
| 5 | +// actually publishes to npm — and force-syncs the `release` branch to whatever |
| 6 | +// is now on npm's `latest`. |
7 | 7 | // |
8 | | -// Two rules here follow from `main` tracking the next major while the current |
9 | | -// major ships from its own maintenance line: |
| 8 | +// `release` means "the commit behind the current `latest`". Netlify builds from |
| 9 | +// it, so it must never point at anything a consumer of `npm i |
| 10 | +// web-component-base` would not get. |
| 11 | +// |
| 12 | +// Three rules follow from that, plus `main` tracking the next major while the |
| 13 | +// current major ships from its own maintenance line: |
10 | 14 | // |
11 | 15 | // 1. It mirrors HEAD, not `main`. Cutting a v6 patch from the `v6` branch |
12 | | -// used to force-push v7's `main` onto `gh/release`, and then leave you |
| 16 | +// used to force-push v7's `main` onto `release`, and then leave you |
13 | 17 | // checked out on `main` rather than the branch you released from. |
14 | | -// 2. It refuses to release a stable version from `main`, because the publish |
| 18 | +// 2. It only mirrors when this release actually takes `latest`. A prerelease |
| 19 | +// publishes to `beta`/`rc`/…, so `latest` is unchanged and `release` must |
| 20 | +// stay where it is. |
| 21 | +// 3. It refuses to release a stable version from `main`, because the publish |
15 | 22 | // workflow derives the dist-tag from the version alone: anything without a |
16 | 23 | // prerelease suffix goes to `latest`, in front of every |
17 | 24 | // `npm i web-component-base` user. |
| 25 | +// |
| 26 | +// The push is a plain refspec rather than a local `release` branch on purpose: |
| 27 | +// a temp branch by that name collides with any `release/*` branch (git cannot |
| 28 | +// have both a ref and a directory at `refs/heads/release`), and a failed |
| 29 | +// checkout leaves the working tree swapped to the old release commit. |
18 | 30 | import { readFileSync } from 'node:fs' |
19 | 31 | import { simpleGit } from 'simple-git' |
20 | 32 |
|
@@ -75,28 +87,16 @@ console.log( |
75 | 87 | `Releasing ${version} from ${branch} (${hash}) to dist-tag '${distTag}'` |
76 | 88 | ) |
77 | 89 |
|
78 | | -console.log(`Fetch remote ${remote} repo`) |
79 | | -await git.fetch(remote) |
80 | | - |
81 | | -console.log(`Checkout ${releaseBranch} branch`) |
82 | | -await git.checkout([ |
83 | | - '-b', |
84 | | - releaseBranch, |
85 | | - '--track', |
86 | | - `${remote}/${releaseBranch}`, |
87 | | -]) |
88 | | - |
89 | | -console.log(`Reset to ${branch} (${hash})`) |
90 | | -await git.reset(['--hard', hash]) |
91 | | - |
92 | | -console.log(`Push to ${releaseBranch} branch`) |
93 | | -await git.push(['--force', remote]) |
94 | | - |
95 | | -console.log(`Checkout ${branch} branch`) |
96 | | -await git.checkout(branch) |
97 | | - |
98 | | -console.log(`Deleting local ${releaseBranch} branch`) |
99 | | -await git.branch(['-D', releaseBranch]) |
| 90 | +// `release` tracks `latest`, so a prerelease must leave it alone — it is still |
| 91 | +// describing the last stable release, which is what consumers are installing. |
| 92 | +if (distTag === 'latest') { |
| 93 | + console.log(`Push ${branch} (${hash}) to ${releaseBranch} branch`) |
| 94 | + await git.push([remote, `HEAD:refs/heads/${releaseBranch}`, '--force']) |
| 95 | +} else { |
| 96 | + console.log( |
| 97 | + `Leaving ${releaseBranch} alone: ${version} publishes to '${distTag}', not 'latest'` |
| 98 | + ) |
| 99 | +} |
100 | 100 |
|
101 | 101 | // TODO: handle multiple remotes with a data structure |
102 | 102 | console.log('Push tags') |
|
0 commit comments