Skip to content

Commit a2aa13b

Browse files
ayob0tayo-run
andcommitted
fix(release): keep the release branch on latest, drop the temp branch
Co-authored-by: Ayo <ayo@ayco.io> Reviewed-on: https://git.ayo.run/ayo/wcb/pulls/37 Co-authored-by: ayobot <agent@ayo.run> Co-committed-by: ayobot <agent@ayo.run> Signed-off-by: Ayo <ayo@ayco.io>
1 parent 8d6da84 commit a2aa13b

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ coverage
2020
# storybook (all generated: `pnpm -F storybook analyze` / `build`)
2121
storybook/storybook-static
2222

23-
# VS Code HTML custom data, emitted to the repo root by the same analyze run
24-
# so `html.customData` in .vscode/settings.json can resolve it
23+
# pre-v7 artifacts
24+
storybook/custom-elements.json
2525
vscode.html-custom-data.json
2626
vscode.css-custom-data.json
2727

28-
# `cem analyze` outputs using `wcb` plugins
28+
# v7 collected artifacts
2929
.wcb

scripts/release.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
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
22
//
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`.
77
//
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:
1014
//
1115
// 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
1317
// 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
1522
// workflow derives the dist-tag from the version alone: anything without a
1623
// prerelease suffix goes to `latest`, in front of every
1724
// `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.
1830
import { readFileSync } from 'node:fs'
1931
import { simpleGit } from 'simple-git'
2032

@@ -75,28 +87,16 @@ console.log(
7587
`Releasing ${version} from ${branch} (${hash}) to dist-tag '${distTag}'`
7688
)
7789

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+
}
100100

101101
// TODO: handle multiple remotes with a data structure
102102
console.log('Push tags')

0 commit comments

Comments
 (0)