Skip to content

Commit 087337f

Browse files
committed
build: check npm before the tag-is-tip check in the release gate
Sitting on master just after a release trips both: the version is published and the tag is behind the new commits. The tag message told you to force-move the tag, which is wrong once the version is spent. Checking npm first gives the answer that actually applies, which is to cut a new version.
1 parent bcbaa8e commit 087337f

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

scripts/check-release.cjs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,28 @@ if (branch !== 'master') {
5151
);
5252
}
5353

54-
// ── 3. The tag exists and is exactly HEAD ────────────────────────────────────
54+
// ── 3. The version is not already on npm ─────────────────────────────────────
55+
// Deliberately ahead of the tag checks. Sitting on master just after a release
56+
// trips "the tag is not the tip" too, but that is not the useful advice there:
57+
// the version is spent, so the answer is to cut a new one, not to move the tag.
58+
let published = '';
59+
try {
60+
published = execFileSync('npm', ['view', `${pkg.name}@${pkg.version}`, 'version'], {
61+
encoding: 'utf8',
62+
stdio: ['ignore', 'pipe', 'ignore'],
63+
}).trim();
64+
} catch {
65+
// npm exits non-zero with E404 when the version does not exist, which is the
66+
// state we want. Anything else surfaces at `npm publish` a moment later.
67+
}
68+
if (published) {
69+
fail(
70+
`${pkg.name}@${pkg.version} is already published`,
71+
'make release-patch to cut a new version'
72+
);
73+
}
74+
75+
// ── 4. The tag exists and is exactly HEAD ────────────────────────────────────
5576
let tagged;
5677
try {
5778
tagged = git('rev-parse', '--verify', '--quiet', `${tag}^{commit}`);
@@ -70,7 +91,7 @@ if (tagged !== head) {
7091
);
7192
}
7293

73-
// ── 4. The push must fast-forward ────────────────────────────────────────────
94+
// ── 5. The push must fast-forward ────────────────────────────────────────────
7495
try {
7596
git('fetch', '--quiet', 'origin');
7697
} catch {
@@ -88,24 +109,6 @@ if (remote !== head) {
88109
}
89110
}
90111

91-
// ── 5. The version is not already on npm ─────────────────────────────────────
92-
let published = '';
93-
try {
94-
published = execFileSync('npm', ['view', `${pkg.name}@${pkg.version}`, 'version'], {
95-
encoding: 'utf8',
96-
stdio: ['ignore', 'pipe', 'ignore'],
97-
}).trim();
98-
} catch {
99-
// npm exits non-zero with E404 when the version does not exist, which is the
100-
// state we want. Anything else surfaces at `npm publish` a moment later.
101-
}
102-
if (published) {
103-
fail(
104-
`${pkg.name}@${pkg.version} is already published`,
105-
'make release-patch to cut a new version'
106-
);
107-
}
108-
109112
console.log(
110113
`✓ release check OK: ${tag} == HEAD == ${short(head)}, clean tree on master, ` +
111114
`origin fast-forwards, ${pkg.version} not yet on npm`

0 commit comments

Comments
 (0)