@d-zero/release-automation 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/changelog.js +26 -0
- package/dist/classify.js +406 -0
- package/dist/cli.js +126 -0
- package/dist/commands/approve-renovate.js +35 -0
- package/dist/commands/context.js +139 -0
- package/dist/commands/generate.js +97 -0
- package/dist/commands/local.js +128 -0
- package/dist/commands/nightly.js +125 -0
- package/dist/commands/publish.js +246 -0
- package/dist/commands/release-pr.js +297 -0
- package/dist/commands/runs.js +21 -0
- package/dist/commands/verify-release-pr.js +116 -0
- package/dist/conventional-commit.js +35 -0
- package/dist/dist-tag.js +32 -0
- package/dist/guard.js +58 -0
- package/dist/io/exec.js +56 -0
- package/dist/io/git.js +78 -0
- package/dist/io/github.js +87 -0
- package/dist/io/npm.js +25 -0
- package/dist/io/repo.js +170 -0
- package/dist/lines-check.js +147 -0
- package/dist/next-version.js +88 -0
- package/dist/nightly.js +56 -0
- package/dist/pr-checks.js +64 -0
- package/dist/release-content.js +231 -0
- package/dist/release-pr-decision.js +67 -0
- package/dist/retry.js +32 -0
- package/dist/rotation.js +133 -0
- package/dist/semver.js +87 -0
- package/dist/support-end.js +26 -0
- package/dist/types.js +14 -0
- package/package.json +83 -5
package/dist/rotation.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { LOCKFILE_STOP_RULE } from './lines-check.js';
|
|
2
|
+
import { parseVersion } from './semver.js';
|
|
3
|
+
import { formatDate } from './support-end.js';
|
|
4
|
+
/** Days before a line's support end that its end-of-support Issue opens. */
|
|
5
|
+
export const EOL_NOTICE_DAYS = 14;
|
|
6
|
+
/**
|
|
7
|
+
* Lists the end-of-support Issues due: one per previous line whose support
|
|
8
|
+
* ends within {@link EOL_NOTICE_DAYS} days.
|
|
9
|
+
* @param lines - The lines
|
|
10
|
+
* @param now - The current time
|
|
11
|
+
* @returns The Issues to open (when not open yet)
|
|
12
|
+
* @example
|
|
13
|
+
* eolIssues(classify(facts).lines, new Date());
|
|
14
|
+
*/
|
|
15
|
+
export function eolIssues(lines, now) {
|
|
16
|
+
return lines.flatMap((line) => {
|
|
17
|
+
if (line.role !== 'previous' || line.supportEnd === null) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const notice = line.supportEnd.getTime() - EOL_NOTICE_DAYS * 24 * 60 * 60 * 1000;
|
|
21
|
+
if (now.getTime() < notice) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const end = formatDate(line.supportEnd);
|
|
25
|
+
const marker = `<!-- release-automation:eol:${line.branch}:${end} -->`;
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
marker,
|
|
29
|
+
title: `End of support for v${line.major} on ${end}`,
|
|
30
|
+
body: [
|
|
31
|
+
marker,
|
|
32
|
+
'',
|
|
33
|
+
`Support for v${line.major} (\`${line.branch}\`) ends on ${end}.`,
|
|
34
|
+
'',
|
|
35
|
+
'Prepare the changes with the `major-rotation` skill. Merge them and apply the repository settings on or after the end date, not before:',
|
|
36
|
+
'',
|
|
37
|
+
`- remove \`${line.branch}\` from \`.github/release-lines.json\`, Renovate, the workflows and \`SECURITY.md\``,
|
|
38
|
+
`- lock the \`${line.branch}\` branch and keep it and its tags`,
|
|
39
|
+
'',
|
|
40
|
+
'Close this Issue when every change is applied and verified.',
|
|
41
|
+
'',
|
|
42
|
+
].join('\n'),
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Tells whether a release is the first stable release of its major, which
|
|
49
|
+
* starts the rotation of the lines.
|
|
50
|
+
* @param version - The released version
|
|
51
|
+
* @param stableTags - The tags that existed before the release
|
|
52
|
+
* @returns Whether no stable release of the major existed before
|
|
53
|
+
* @example
|
|
54
|
+
* isFirstStableOfMajor('5.0.0', ['v4.2.0']); // true
|
|
55
|
+
*/
|
|
56
|
+
export function isFirstStableOfMajor(version, stableTags) {
|
|
57
|
+
const parsed = parseVersion(version);
|
|
58
|
+
if (parsed.pre !== null) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return !stableTags.some((tag) => new RegExp(String.raw `^v${parsed.major}\.\d+\.\d+$`).test(tag));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The Issue that asks for the rotation after the first stable release of a major.
|
|
65
|
+
* @param input - The release
|
|
66
|
+
* @param input.version - The released version
|
|
67
|
+
* @param input.publishedAt - When the publish was verified
|
|
68
|
+
* @param input.verified - What was verified, one line per package
|
|
69
|
+
* @param input.lockfileStop - The result of stopping the lock file maintenance of the older lines
|
|
70
|
+
* @returns The Issue
|
|
71
|
+
* @example
|
|
72
|
+
* rotationIssue({ version: '5.0.0', publishedAt: new Date(), verified: ['a@5.0.0 latest'], lockfileStop: 'stopped on v4' });
|
|
73
|
+
*/
|
|
74
|
+
export function rotationIssue(input) {
|
|
75
|
+
const major = parseVersion(input.version).major;
|
|
76
|
+
const marker = `<!-- release-automation:rotation:v${major} -->`;
|
|
77
|
+
return {
|
|
78
|
+
marker,
|
|
79
|
+
title: `Rotate the release lines after v${input.version}`,
|
|
80
|
+
body: [
|
|
81
|
+
marker,
|
|
82
|
+
'',
|
|
83
|
+
`v${input.version} was published on ${input.publishedAt.toISOString()}.`,
|
|
84
|
+
'',
|
|
85
|
+
'### Verified on the registry',
|
|
86
|
+
'',
|
|
87
|
+
...input.verified.map((entry) => `- ${entry}`),
|
|
88
|
+
'',
|
|
89
|
+
'### Lock file maintenance of the older lines',
|
|
90
|
+
'',
|
|
91
|
+
input.lockfileStop,
|
|
92
|
+
'',
|
|
93
|
+
'### What is left',
|
|
94
|
+
'',
|
|
95
|
+
'Hand this Issue to an agent with the `major-rotation` skill. It updates the lines file, Renovate, the workflows, the Nightly, `SECURITY.md`, the documents and the rulesets for the new lines.',
|
|
96
|
+
'',
|
|
97
|
+
'Close this Issue when every change is applied and verified.',
|
|
98
|
+
'',
|
|
99
|
+
].join('\n'),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns `renovate.json` with lock file maintenance stopped on the given
|
|
104
|
+
* branches (on top of the branches already stopped), through the rule
|
|
105
|
+
* {@link LOCKFILE_STOP_RULE}. Applying it twice gives the same result.
|
|
106
|
+
* @param renovate - The parsed `renovate.json`
|
|
107
|
+
* @param branches - The branches to stop
|
|
108
|
+
* @returns The new configuration
|
|
109
|
+
* @example
|
|
110
|
+
* withLockfileStop({ packageRules: [] }, ['v4']).packageRules;
|
|
111
|
+
* // [{ description: LOCKFILE_STOP_RULE, matchBaseBranches: ['v4'], matchUpdateTypes: ['lockFileMaintenance'], enabled: false }]
|
|
112
|
+
*/
|
|
113
|
+
export function withLockfileStop(renovate, branches) {
|
|
114
|
+
const rules = Array.isArray(renovate['packageRules'])
|
|
115
|
+
? renovate['packageRules']
|
|
116
|
+
: [];
|
|
117
|
+
const existing = rules.find((rule) => rule['description'] === LOCKFILE_STOP_RULE);
|
|
118
|
+
const stopped = Array.isArray(existing?.['matchBaseBranches'])
|
|
119
|
+
? existing['matchBaseBranches']
|
|
120
|
+
: [];
|
|
121
|
+
const rule = {
|
|
122
|
+
description: LOCKFILE_STOP_RULE,
|
|
123
|
+
matchBaseBranches: [...new Set([...stopped, ...branches])].toSorted(),
|
|
124
|
+
matchUpdateTypes: ['lockFileMaintenance'],
|
|
125
|
+
enabled: false,
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
...renovate,
|
|
129
|
+
packageRules: existing
|
|
130
|
+
? rules.map((r) => (r === existing ? rule : r))
|
|
131
|
+
: [...rules, rule],
|
|
132
|
+
};
|
|
133
|
+
}
|
package/dist/semver.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { PRERELEASE_IDS } from './types.js';
|
|
2
|
+
const VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+)(?:\.(0|[1-9]\d*))?)?$/;
|
|
3
|
+
/**
|
|
4
|
+
* Parses a version. Anything outside the shape release lines use (build
|
|
5
|
+
* metadata, unknown prerelease identifiers, a prerelease without a number
|
|
6
|
+
* other than a bare identifier) is rejected, because the dist-tag and the
|
|
7
|
+
* next version cannot be decided for it.
|
|
8
|
+
* @param text - The version, without a leading `v`
|
|
9
|
+
* @returns The parsed version
|
|
10
|
+
* @throws {Error} When the text is not such a version
|
|
11
|
+
* @example
|
|
12
|
+
* parseVersion('2.0.1-alpha.3'); // { major: 2, minor: 0, patch: 1, pre: { id: 'alpha', n: 3 } }
|
|
13
|
+
*/
|
|
14
|
+
export function parseVersion(text) {
|
|
15
|
+
const match = VERSION.exec(text);
|
|
16
|
+
if (!match) {
|
|
17
|
+
throw new Error(`Not a valid version: ${text}`);
|
|
18
|
+
}
|
|
19
|
+
const [, major, minor, patch, id, n] = match;
|
|
20
|
+
if (id === undefined) {
|
|
21
|
+
return {
|
|
22
|
+
major: Number(major),
|
|
23
|
+
minor: Number(minor),
|
|
24
|
+
patch: Number(patch),
|
|
25
|
+
pre: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (!PRERELEASE_IDS.includes(id)) {
|
|
29
|
+
throw new Error(`Unknown prerelease identifier "${id}" in ${text}`);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
major: Number(major),
|
|
33
|
+
minor: Number(minor),
|
|
34
|
+
patch: Number(patch),
|
|
35
|
+
pre: { id: id, n: n === undefined ? 0 : Number(n) },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Formats a version.
|
|
40
|
+
* @param version - The version
|
|
41
|
+
* @returns `X.Y.Z` or `X.Y.Z-<id>.<n>`
|
|
42
|
+
* @example
|
|
43
|
+
* formatVersion({ major: 1, minor: 0, patch: 0, pre: null }); // '1.0.0'
|
|
44
|
+
*/
|
|
45
|
+
export function formatVersion(version) {
|
|
46
|
+
const core = `${version.major}.${version.minor}.${version.patch}`;
|
|
47
|
+
return version.pre ? `${core}-${version.pre.id}.${version.pre.n}` : core;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Compares two versions by SemVer precedence.
|
|
51
|
+
* @param a - A version
|
|
52
|
+
* @param b - Another version
|
|
53
|
+
* @returns Negative when `a` is lower, positive when higher, `0` when equal
|
|
54
|
+
* @example
|
|
55
|
+
* compareVersions(parseVersion('1.0.0-rc.1'), parseVersion('1.0.0')); // negative
|
|
56
|
+
*/
|
|
57
|
+
export function compareVersions(a, b) {
|
|
58
|
+
const core = a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
|
59
|
+
if (core !== 0) {
|
|
60
|
+
return core;
|
|
61
|
+
}
|
|
62
|
+
if (a.pre === null || b.pre === null) {
|
|
63
|
+
return (a.pre === null ? 1 : 0) - (b.pre === null ? 1 : 0);
|
|
64
|
+
}
|
|
65
|
+
return (PRERELEASE_IDS.indexOf(a.pre.id) - PRERELEASE_IDS.indexOf(b.pre.id) ||
|
|
66
|
+
a.pre.n - b.pre.n);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parses a `v<version>` tag of a stable release.
|
|
70
|
+
* @param tag - A tag name
|
|
71
|
+
* @returns The version, or `null` when the tag is not `vX.Y.Z`
|
|
72
|
+
* @example
|
|
73
|
+
* stableTagVersion('v3.5.0'); // { major: 3, minor: 5, patch: 0, pre: null }
|
|
74
|
+
* stableTagVersion('v4.0.0-alpha.1'); // null
|
|
75
|
+
*/
|
|
76
|
+
export function stableTagVersion(tag) {
|
|
77
|
+
const match = /^v(\d+\.\d+\.\d+)$/.exec(tag);
|
|
78
|
+
if (!match?.[1]) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return parseVersion(match[1]);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds whole months to a date in UTC, clamping to the last day of the target
|
|
3
|
+
* month (2026-01-31 plus one month is 2026-02-28).
|
|
4
|
+
* @param date - The start
|
|
5
|
+
* @param months - Months to add
|
|
6
|
+
* @returns The date `months` later
|
|
7
|
+
* @example
|
|
8
|
+
* addMonths(new Date('2026-01-31T00:00:00Z'), 1).toISOString(); // '2026-02-28T00:00:00.000Z'
|
|
9
|
+
*/
|
|
10
|
+
export function addMonths(date, months) {
|
|
11
|
+
const year = date.getUTCFullYear();
|
|
12
|
+
const month = date.getUTCMonth() + months;
|
|
13
|
+
const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
|
14
|
+
return new Date(Date.UTC(year, month, Math.min(date.getUTCDate(), lastDay), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Formats a date as `YYYY-MM-DD` in UTC, the form `SECURITY.md` states
|
|
18
|
+
* support end dates in.
|
|
19
|
+
* @param date - The date
|
|
20
|
+
* @returns The date part of its ISO string
|
|
21
|
+
* @example
|
|
22
|
+
* formatDate(new Date('2027-03-01T12:00:00Z')); // '2027-03-01'
|
|
23
|
+
*/
|
|
24
|
+
export function formatDate(date) {
|
|
25
|
+
return date.toISOString().slice(0, 10);
|
|
26
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The default of {@link LinesFile.supportMonths}. */
|
|
2
|
+
export const DEFAULT_SUPPORT_MONTHS = 12;
|
|
3
|
+
/** The default of {@link LinesFile.securityBatchMinutes}. */
|
|
4
|
+
export const DEFAULT_SECURITY_BATCH_MINUTES = 60;
|
|
5
|
+
/** The branch the `current` line is published from. */
|
|
6
|
+
export const CURRENT_PUBLISH_BRANCH = 'main';
|
|
7
|
+
/** The branch the `current` line is developed on. */
|
|
8
|
+
export const CURRENT_BRANCH = 'dev';
|
|
9
|
+
/**
|
|
10
|
+
* The prerelease identifiers a version may carry.
|
|
11
|
+
* @example
|
|
12
|
+
* PRERELEASE_IDS.includes('beta'); // true
|
|
13
|
+
*/
|
|
14
|
+
export const PRERELEASE_IDS = ['alpha', 'beta', 'rc'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,84 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@d-zero/release-automation",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Release lines, Release PRs, nightly gates and publishing for D-ZERO repositories",
|
|
5
|
+
"author": "D-ZERO",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/d-zero-dev/release-automation.git"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=24.11.0"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"bin": "dist/cli.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
"./classify": {
|
|
21
|
+
"import": "./dist/classify.js",
|
|
22
|
+
"types": "./dist/classify.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./dist-tag": {
|
|
25
|
+
"import": "./dist/dist-tag.js",
|
|
26
|
+
"types": "./dist/dist-tag.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./next-version": {
|
|
29
|
+
"import": "./dist/next-version.js",
|
|
30
|
+
"types": "./dist/next-version.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./release-pr-decision": {
|
|
33
|
+
"import": "./dist/release-pr-decision.js",
|
|
34
|
+
"types": "./dist/release-pr-decision.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./types": {
|
|
37
|
+
"import": "./dist/types.js",
|
|
38
|
+
"types": "./dist/types.d.ts"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"clean": "tsc --build --clean",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"lint": "run-s lint:oxlint lint:textlint:fix lint:oxfmt lint:textlint:check",
|
|
49
|
+
"lint:check": "run-s lint:oxlint:check lint:oxfmt:check lint:textlint:check",
|
|
50
|
+
"lint:oxlint": "oxlint --type-aware --fix .",
|
|
51
|
+
"lint:oxlint:check": "oxlint --type-aware --deny-warnings .",
|
|
52
|
+
"lint:oxfmt": "oxfmt --write \"{*,**/*}.{md,json,js,cjs,mjs,ts,mts,yml,yaml}\"",
|
|
53
|
+
"lint:oxfmt:check": "oxfmt --check \"{*,**/*}.{md,json,js,cjs,mjs,ts,mts,yml,yaml}\"",
|
|
54
|
+
"lint:textlint:fix": "textlint --fix \"{*,**/*}.md\"",
|
|
55
|
+
"lint:textlint:check": "textlint \"{*,**/*}.md\"",
|
|
56
|
+
"postinstall": "husky",
|
|
57
|
+
"release-automation": "tsc && node dist/cli.js"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"yaml": "2.9.1"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@d-zero/commitlint-config": "6.0.0-alpha.3",
|
|
64
|
+
"@d-zero/lint-staged-config": "6.0.0-alpha.3",
|
|
65
|
+
"@d-zero/oxlint-config": "6.0.0-alpha.3",
|
|
66
|
+
"@d-zero/textlint-config": "6.0.0-alpha.3",
|
|
67
|
+
"@d-zero/tsconfig": "2.0.0",
|
|
68
|
+
"@types/node": "26.6.6",
|
|
69
|
+
"husky": "9.1.7",
|
|
70
|
+
"npm-run-all2": "9.1.0",
|
|
71
|
+
"oxfmt": "0.79.0",
|
|
72
|
+
"oxlint": "1.94.0",
|
|
73
|
+
"oxlint-tsgolint": "7.0.2008",
|
|
74
|
+
"textlint": "16.1.3",
|
|
75
|
+
"typescript": "7.0.2",
|
|
76
|
+
"vite": "8.3.8",
|
|
77
|
+
"vitest": "5.1.1"
|
|
78
|
+
},
|
|
79
|
+
"packageManager": "yarn@4.19.0",
|
|
80
|
+
"volta": {
|
|
81
|
+
"node": "26.13.1",
|
|
82
|
+
"yarn": "4.19.0"
|
|
83
|
+
}
|
|
84
|
+
}
|