@d-zero/release-automation 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/commands/publish.js +40 -16
- package/dist/commands/release-pr.js +4 -2
- package/dist/commands/verify-release-pr.js +3 -1
- package/dist/dist-tag-name.js +18 -0
- package/dist/dist-tag.js +27 -1
- package/dist/io/repo.js +4 -0
- package/dist/needs-publish.js +21 -0
- package/dist/retry.js +7 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ yarn add -D @d-zero/release-automation@<version>
|
|
|
29
29
|
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
30
30
|
| `lines[].role` | `current`(`dev`で開発し`main`から公開)、`next`(次メジャー。`v<N>`で開発・公開)、`previous`(旧メジャー。`v<N>`で保守・公開) |
|
|
31
31
|
| `lines[].successorStable` | 旧系列の後継メジャーの正式版の公開日。省略時はタグから読む |
|
|
32
|
+
| `lines[].distTag` | その系列の公開に付ける dist-tag(1つだけ)。省略時は版と役割で自動に決める。`next`と、旧メジャーが`latest`を奪う公開は拒否する |
|
|
32
33
|
| `supportMonths` | 旧系列のサポート期間。既定は12 |
|
|
33
34
|
| `securityBatchMinutes` | セキュリティ修正をまとめる時間。既定は60 |
|
|
34
35
|
| `publishCommand` | npm 公開しないリポジトリの公開コマンド。`DIST_TAG`環境変数を受け取る |
|
package/dist/commands/publish.js
CHANGED
|
@@ -3,8 +3,9 @@ import { runShell } from '../io/exec.js';
|
|
|
3
3
|
import { GitHubError } from '../io/github.js';
|
|
4
4
|
import { fetchPackument } from '../io/npm.js';
|
|
5
5
|
import { publicPackages, publishModeAt, readLinesFile, versionAt } from '../io/repo.js';
|
|
6
|
+
import { needsPublish } from '../needs-publish.js';
|
|
6
7
|
import { releasePrOrigin } from '../pr-checks.js';
|
|
7
|
-
import { PUBLISH_ATTEMPTS, retry } from '../retry.js';
|
|
8
|
+
import { PUBLISH_ATTEMPTS, REGISTRY_VERIFY_ATTEMPTS, retry } from '../retry.js';
|
|
8
9
|
import { isFirstStableOfMajor, rotationIssue } from '../rotation.js';
|
|
9
10
|
import { classifiedLines, ensureIssue, github, localGit, RELEASE_LABEL, requireEnv, summary, VERIFY_CHECK, } from './context.js';
|
|
10
11
|
import { lineMarker } from './release-pr.js';
|
|
@@ -13,8 +14,10 @@ const CI_OK = 'ci-ok';
|
|
|
13
14
|
/**
|
|
14
15
|
* Publishes the release a merged Release PR carries, when the pushed commit
|
|
15
16
|
* is the merge of one; otherwise does nothing. In order: verify the Release
|
|
16
|
-
* PR, tag the merge commit (as the Publish App), publish with retries
|
|
17
|
-
* every package
|
|
17
|
+
* PR, tag the merge commit (as the Publish App), publish with retries (skipped
|
|
18
|
+
* when every package is already on the registry, so that a run started again
|
|
19
|
+
* after the registry took them goes on to the verification), verify every
|
|
20
|
+
* package and dist-tag on the registry, bring the release back to
|
|
18
21
|
* `dev` (current line only), and open the rotation Issue after the first
|
|
19
22
|
* stable release of a major. Any failure stops the rest.
|
|
20
23
|
* @param options - Flags
|
|
@@ -62,22 +65,40 @@ export async function publishCommand(options) {
|
|
|
62
65
|
const stableTagsBefore = git.tags('HEAD').filter((tag) => /^v\d+\.\d+\.\d+$/.test(tag));
|
|
63
66
|
const unpublished = await unpublishedPackages(packages);
|
|
64
67
|
const version = versionAt(git, 'HEAD');
|
|
65
|
-
|
|
68
|
+
// Nothing to publish: a run that starts again after the registry took the
|
|
69
|
+
// packages goes on with the verification instead of publishing over them.
|
|
70
|
+
// The dist-tag is still decided and checked, for every package, because the
|
|
71
|
+
// earlier run may have died before the tag was right.
|
|
72
|
+
const publishNeeded = needsPublish({ mode, unpublishedCount: unpublished.length });
|
|
73
|
+
const released = publishNeeded ? unpublished : packages;
|
|
74
|
+
const linesFile = readLinesFile(git, 'HEAD');
|
|
75
|
+
const tag = await decideDistTag({
|
|
76
|
+
mode,
|
|
77
|
+
line,
|
|
78
|
+
lines,
|
|
79
|
+
released,
|
|
80
|
+
version,
|
|
81
|
+
override: linesFile?.lines.find(({ branch }) => branch === line.branch)?.distTag,
|
|
82
|
+
});
|
|
66
83
|
const tags = mode === 'lerna-independent'
|
|
67
|
-
?
|
|
84
|
+
? released.map((pkg) => `${pkg.name}@${pkg.version}`)
|
|
68
85
|
: [`v${version ?? ''}`];
|
|
69
|
-
await summary(
|
|
86
|
+
await summary(publishNeeded
|
|
87
|
+
? `#${pr.number}: publishing ${tags.join(', ')} with dist-tag ${tag}`
|
|
88
|
+
: `#${pr.number}: ${tags.join(', ')} is already on the registry; publishing nothing, checking dist-tag ${tag}`);
|
|
70
89
|
if (options.dryRun) {
|
|
71
90
|
return;
|
|
72
91
|
}
|
|
73
92
|
for (const name of tags) {
|
|
74
93
|
await ensureTag(publishGh, name, sha);
|
|
75
94
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
if (publishNeeded) {
|
|
96
|
+
const command = publishCommandFor(mode, tag, linesFile?.publishCommand);
|
|
97
|
+
await retry(async (attempt) => {
|
|
98
|
+
await summary(`publish attempt ${attempt}: ${command}`);
|
|
99
|
+
runShell(command, git.cwd);
|
|
100
|
+
}, { attempts: PUBLISH_ATTEMPTS, baseDelayMs: 30_000 });
|
|
101
|
+
}
|
|
81
102
|
const verified = [];
|
|
82
103
|
if (mode !== 'custom') {
|
|
83
104
|
await retry(async () => {
|
|
@@ -87,14 +108,16 @@ export async function publishCommand(options) {
|
|
|
87
108
|
if (!packument?.versions.includes(pkg.version)) {
|
|
88
109
|
throw new Error(`${pkg.name}@${pkg.version} is not on the registry`);
|
|
89
110
|
}
|
|
90
|
-
if (
|
|
111
|
+
if (released.includes(pkg) && packument.distTags[tag] !== pkg.version) {
|
|
91
112
|
throw new Error(`${pkg.name}: ${tag} points at ${packument.distTags[tag] ?? 'nothing'}, not ${pkg.version}`);
|
|
92
113
|
}
|
|
93
114
|
verified.push(`${pkg.name}@${pkg.version} (${tag})`);
|
|
94
115
|
}
|
|
95
|
-
}, { attempts:
|
|
116
|
+
}, { attempts: REGISTRY_VERIFY_ATTEMPTS, baseDelayMs: 10_000 });
|
|
96
117
|
}
|
|
97
|
-
await summary(
|
|
118
|
+
await summary(mode === 'custom'
|
|
119
|
+
? 'published with the custom command; the registry was not checked'
|
|
120
|
+
: `${publishNeeded ? 'published' : 'already published'} and verified:\n${verified.map((entry) => `- ${entry}`).join('\n')}`);
|
|
98
121
|
if (line.role === 'current') {
|
|
99
122
|
await syncToDev(git, publishGh, sha);
|
|
100
123
|
}
|
|
@@ -137,8 +160,8 @@ async function unpublishedPackages(packages) {
|
|
|
137
160
|
async function decideDistTag(input) {
|
|
138
161
|
const successorStablePublished = input.line.successorStable !== null;
|
|
139
162
|
const versions = input.mode === 'lerna-independent'
|
|
140
|
-
? input.
|
|
141
|
-
: [{ version: input.version ?? '', name: input.
|
|
163
|
+
? input.released.map((pkg) => ({ version: pkg.version, name: pkg.name }))
|
|
164
|
+
: [{ version: input.version ?? '', name: input.released[0]?.name ?? null }];
|
|
142
165
|
const tags = new Set();
|
|
143
166
|
for (const { version, name } of versions) {
|
|
144
167
|
const packument = name === null ? null : await fetchPackument(name);
|
|
@@ -148,6 +171,7 @@ async function decideDistTag(input) {
|
|
|
148
171
|
independent: input.mode === 'lerna-independent',
|
|
149
172
|
successorStablePublished,
|
|
150
173
|
latestOnRegistry: packument?.distTags['latest'] ?? null,
|
|
174
|
+
...(input.override === undefined ? {} : { override: input.override }),
|
|
151
175
|
}));
|
|
152
176
|
}
|
|
153
177
|
if (tags.size !== 1) {
|
|
@@ -249,7 +249,9 @@ async function publishIncomplete(git, line, mode) {
|
|
|
249
249
|
*/
|
|
250
250
|
async function pushRelease(input) {
|
|
251
251
|
const { git } = input;
|
|
252
|
-
|
|
252
|
+
// On a local branch named like the line, not detached: `lerna version`
|
|
253
|
+
// refuses a detached HEAD, and its `allowBranch` names the line's branch.
|
|
254
|
+
git.raw('checkout', '--force', '-B', input.line.branch, `origin/${input.line.branch}`);
|
|
253
255
|
runShell('yarn install --immutable', git.cwd);
|
|
254
256
|
const generated = generateRelease({
|
|
255
257
|
git,
|
|
@@ -261,7 +263,7 @@ async function pushRelease(input) {
|
|
|
261
263
|
now: input.now,
|
|
262
264
|
});
|
|
263
265
|
if (!generated.ok) {
|
|
264
|
-
git.raw('checkout', '--force', '
|
|
266
|
+
git.raw('checkout', '--force', '-B', input.line.branch, `origin/${input.line.branch}`);
|
|
265
267
|
return generated;
|
|
266
268
|
}
|
|
267
269
|
const appSlug = requireEnv('RELEASE_APP_SLUG');
|
|
@@ -83,7 +83,9 @@ export async function verifyReleasePrCommand(options) {
|
|
|
83
83
|
throw new Error(`Never published, so no trusted publisher can be set: ${never.join(', ')}. Publish a placeholder by hand and set its trusted publisher first`);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
// On a local branch named like the line, not detached: `lerna version`
|
|
87
|
+
// refuses a detached HEAD, and its `allowBranch` names the line's branch.
|
|
88
|
+
git.raw('checkout', '--force', '-B', line.branch, parent);
|
|
87
89
|
runShell('yarn install --immutable', git.cwd);
|
|
88
90
|
const generated = generateRelease({
|
|
89
91
|
git,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a value can name the dist-tag of a line in the lines file: a string
|
|
3
|
+
* that starts with a letter (so it is not a number or a version, which npm
|
|
4
|
+
* refuses as a dist-tag), has only letters, digits, `.`, `_` and `-`, does not
|
|
5
|
+
* begin like a version (`v1.2.3`), and is not `next`, which rule 43 forbids.
|
|
6
|
+
* @param value - The value to check
|
|
7
|
+
* @returns Whether it is a usable dist-tag name
|
|
8
|
+
* @example
|
|
9
|
+
* isDistTagName('v3-legacy'); // true
|
|
10
|
+
* isDistTagName('next'); // false
|
|
11
|
+
* isDistTagName('1.0.0'); // false
|
|
12
|
+
*/
|
|
13
|
+
export function isDistTagName(value) {
|
|
14
|
+
return (typeof value === 'string' &&
|
|
15
|
+
/^[A-Za-z][\w.-]*$/.test(value) &&
|
|
16
|
+
!/^v\d+\.\d+\.\d+/.test(value) &&
|
|
17
|
+
value !== 'next');
|
|
18
|
+
}
|
package/dist/dist-tag.js
CHANGED
|
@@ -3,7 +3,10 @@ import { parseVersion } from './semver.js';
|
|
|
3
3
|
* Decides the dist-tag of a release: `alpha`, `beta` and `rc` for those
|
|
4
4
|
* prereleases, `latest` for a stable release of the current line, and
|
|
5
5
|
* `v<major>` for a stable release of a previous line once a later major is
|
|
6
|
-
* stable. `next` is never used.
|
|
6
|
+
* stable. `next` is never used. A line that names a dist-tag is published
|
|
7
|
+
* under that one in place of the decided one; the checks that refuse a
|
|
8
|
+
* release still apply to it, so the name never lets a stable release of the
|
|
9
|
+
* next-major line through, and `latest` never moves to an older major.
|
|
7
10
|
* @param input - The release
|
|
8
11
|
* @returns The dist-tag
|
|
9
12
|
* @throws {Error} For a version that is not valid, an unknown prerelease
|
|
@@ -14,6 +17,29 @@ import { parseVersion } from './semver.js';
|
|
|
14
17
|
* distTag({ version: '3.5.1', role: 'previous', independent: false, successorStablePublished: true, latestOnRegistry: '4.2.0' }); // 'v3'
|
|
15
18
|
*/
|
|
16
19
|
export function distTag(input) {
|
|
20
|
+
const decided = decidedDistTag(input);
|
|
21
|
+
if (input.override === undefined) {
|
|
22
|
+
return decided;
|
|
23
|
+
}
|
|
24
|
+
if (input.override === 'next') {
|
|
25
|
+
throw new Error('next is never used as a dist-tag');
|
|
26
|
+
}
|
|
27
|
+
if (input.override === 'latest' &&
|
|
28
|
+
!input.independent &&
|
|
29
|
+
input.latestOnRegistry !== null) {
|
|
30
|
+
const latest = parseVersion(input.latestOnRegistry);
|
|
31
|
+
if (latest.major > parseVersion(input.version).major) {
|
|
32
|
+
throw new Error(`${input.version} would move latest from ${input.latestOnRegistry} to an older major`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return input.override;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @param input - The release
|
|
39
|
+
* @returns The dist-tag the version and the role decide
|
|
40
|
+
* @throws {Error} As {@link distTag} does
|
|
41
|
+
*/
|
|
42
|
+
function decidedDistTag(input) {
|
|
17
43
|
const version = parseVersion(input.version);
|
|
18
44
|
if (version.pre !== null) {
|
|
19
45
|
return version.pre.id;
|
package/dist/io/repo.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { isDistTagName } from '../dist-tag-name.js';
|
|
3
4
|
import { CURRENT_BRANCH } from '../types.js';
|
|
4
5
|
/** Where the lines file lives in a repository. */
|
|
5
6
|
export const LINES_FILE = '.github/release-lines.json';
|
|
@@ -21,6 +22,9 @@ export function parseLinesFile(text) {
|
|
|
21
22
|
!['current', 'next', 'previous'].includes(line.role)) {
|
|
22
23
|
throw new TypeError(`${LINES_FILE}: each line needs "branch" and a "role" of current, next or previous`);
|
|
23
24
|
}
|
|
25
|
+
if (line.distTag !== undefined && !isDistTagName(line.distTag)) {
|
|
26
|
+
throw new TypeError(`${LINES_FILE}: ${line.branch}: "distTag" must be a dist-tag name that starts with a letter and is not next`);
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
for (const key of ['supportMonths', 'securityBatchMinutes']) {
|
|
26
30
|
const value = data[key];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decides whether the publish command has to run. A run of `publish` that
|
|
3
|
+
* starts again after the registry took the packages (for example because the
|
|
4
|
+
* registry was slow to show them) must not publish over them: `npm publish`
|
|
5
|
+
* fails on a version that exists, so only the Lerna modes would survive a
|
|
6
|
+
* second run. Nothing to publish means the command is
|
|
7
|
+
* skipped and the run goes on with the verification and the return to `dev`.
|
|
8
|
+
* The registry says nothing about a custom command, so it always runs.
|
|
9
|
+
* Implements the idempotent re-run of rule 26.
|
|
10
|
+
* @param input - What the registry showed before the publish
|
|
11
|
+
* @param input.mode - The publishing mode
|
|
12
|
+
* @param input.unpublishedCount - How many public packages are not on the registry at their version
|
|
13
|
+
* @returns Whether to run the publish command
|
|
14
|
+
* @example
|
|
15
|
+
* needsPublish({ mode: 'npm-single', unpublishedCount: 0 }); // false
|
|
16
|
+
* needsPublish({ mode: 'npm-single', unpublishedCount: 1 }); // true
|
|
17
|
+
* needsPublish({ mode: 'custom', unpublishedCount: 0 }); // true
|
|
18
|
+
*/
|
|
19
|
+
export function needsPublish(input) {
|
|
20
|
+
return input.mode === 'custom' || input.unpublishedCount > 0;
|
|
21
|
+
}
|
package/dist/retry.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/** How many times a publish is tried in all. */
|
|
2
2
|
export const PUBLISH_ATTEMPTS = 3;
|
|
3
|
+
/**
|
|
4
|
+
* How many times the check that the registry shows a published version is
|
|
5
|
+
* made in all. The registry can take minutes to show a version it accepted, so
|
|
6
|
+
* with the waits doubling from 10 seconds the check gives up after about ten
|
|
7
|
+
* minutes.
|
|
8
|
+
*/
|
|
9
|
+
export const REGISTRY_VERIFY_ATTEMPTS = 7;
|
|
3
10
|
/**
|
|
4
11
|
* Runs a task until it succeeds, at most `attempts` times, waiting longer
|
|
5
12
|
* between each try (`baseDelayMs`, then twice that, and so on).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/release-automation",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Release lines, Release PRs, nightly gates and publishing for D-ZERO repositories",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@d-zero/oxlint-config": "6.0.0-alpha.3",
|
|
66
66
|
"@d-zero/textlint-config": "6.0.0-alpha.3",
|
|
67
67
|
"@d-zero/tsconfig": "2.0.0",
|
|
68
|
-
"@types/node": "26.6.
|
|
68
|
+
"@types/node": "26.6.7",
|
|
69
69
|
"husky": "9.1.7",
|
|
70
70
|
"npm-run-all2": "9.1.0",
|
|
71
71
|
"oxfmt": "0.80.0",
|