@d-zero/release-automation 0.0.1 → 0.0.3
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 +26 -13
- package/dist/audit.js +129 -0
- package/dist/cli.js +21 -2
- package/dist/commands/context.js +29 -0
- package/dist/commands/nightly.js +32 -28
- package/dist/commands/release-pr.js +3 -2
- package/dist/commands/runs.js +22 -1
- package/dist/issue-body.js +23 -0
- package/dist/nightly.js +12 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,19 +35,32 @@ yarn add -D @d-zero/release-automation@<version>
|
|
|
35
35
|
|
|
36
36
|
## コマンド
|
|
37
37
|
|
|
38
|
-
| コマンド
|
|
39
|
-
|
|
|
40
|
-
| `classify [--json]`
|
|
41
|
-
| `lines-check`
|
|
42
|
-
| `guard`
|
|
43
|
-
| `commit-check --base <branch>`
|
|
44
|
-
| `release-pr [--line] [--manual] [--promote] [--dry-run]`
|
|
45
|
-
| `verify-release-pr --pr <n>`
|
|
46
|
-
| `publish [--dry-run]`
|
|
47
|
-
| `nightly-dispatch [--force]`
|
|
48
|
-
| `nightly-report`
|
|
49
|
-
| `audit-report --line <branch> --file <path
|
|
50
|
-
| `approve-renovate --pr <n>`
|
|
38
|
+
| コマンド | 実行場所 | 内容 |
|
|
39
|
+
| -------------------------------------------------------------- | ------------------------ | ---------------------------------------------------------------------------- |
|
|
40
|
+
| `classify [--json]` | ローカル | 系列・公開方式・レビュー方式を判定し、エラーとセットアップの作業を表示する |
|
|
41
|
+
| `lines-check` | CI | Renovate・ワークフロー・`SECURITY.md`・pre-commit が系列と一致するか検査する |
|
|
42
|
+
| `guard` | pre-commit | 系列のブランチと`main`への直接コミットを拒否する |
|
|
43
|
+
| `commit-check --base <branch>` | PR の CI | マージ先の系列が受け付けない破壊的変更を拒否する |
|
|
44
|
+
| `release-pr [--line] [--manual] [--promote] [--dry-run]` | 定期実行・手動 | 各系列の Release PR を作成・更新・差し替えする |
|
|
45
|
+
| `verify-release-pr --pr <n>` | `pull_request_target` | Release PR が自動生成されたものか検証する |
|
|
46
|
+
| `publish [--dry-run]` | 公開ブランチへの push | Release PR のマージを公開し、`dev`へ反映する |
|
|
47
|
+
| `nightly-dispatch [--force]` | 定期実行 | 各系列の Full CI を起動する(同じコミットの成功は再利用) |
|
|
48
|
+
| `nightly-report` | 定期実行・Full CI 完了時 | `release-blocker`・サポート終了・年齢ゲート例外の Issue を管理する |
|
|
49
|
+
| `audit-report --line <branch> --file <path> [--exit-code <n>]` | 定期実行 | 依存の脆弱性の監査結果を系列の Issue にする(下記) |
|
|
50
|
+
| `approve-renovate --pr <n>` | `pull_request_target` | 自動マージ対象の Renovate の PR を Approve する |
|
|
51
|
+
|
|
52
|
+
### `audit-report`
|
|
53
|
+
|
|
54
|
+
`--file`には`yarn npm audit --all --recursive --json`の標準出力を、`--exit-code`にはその終了コードを渡す。非推奨パッケージの告知は脆弱性ではないので数えない。
|
|
55
|
+
|
|
56
|
+
| 監査の結果 | 系列の Issue |
|
|
57
|
+
| ------------------------------------- | -------------------------------------------------------------------- |
|
|
58
|
+
| 脆弱性がある | 作る。開いていれば、内容が変わったときに本文を書き換えてコメントする |
|
|
59
|
+
| 脆弱性がなく、終了コードが 0 | 閉じる |
|
|
60
|
+
| 脆弱性がなく、終了コードが 0 以外 | そのまま。コマンドは終了コード 1 で失敗する |
|
|
61
|
+
| 脆弱性がなく、`--exit-code`の指定なし | そのまま(問題なしと失敗を区別できないため) |
|
|
62
|
+
|
|
63
|
+
Issue の本文は監査のたびに書き換わるので、メモはコメントに書く。
|
|
51
64
|
|
|
52
65
|
## 環境変数
|
|
53
66
|
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the output of `yarn npm audit --json` (one JSON object per line).
|
|
3
|
+
* Lines that are not JSON objects with a package name are skipped. Deprecation
|
|
4
|
+
* notices are counted but not taken as findings: rule 36 asks for an audit of
|
|
5
|
+
* vulnerabilities, and a notice never clears while the package stays. A line
|
|
6
|
+
* that starts with `{` but is not JSON throws, since skipping it could make a
|
|
7
|
+
* failed audit look clean.
|
|
8
|
+
* @param output - The audit output
|
|
9
|
+
* @returns The findings, in the order of the output, and the number of deprecation notices
|
|
10
|
+
* @example
|
|
11
|
+
* parseAudit('{"value":"tmp","children":{"ID":1,"Issue":"Path traversal","Severity":"high"}}');
|
|
12
|
+
* // { findings: [{ name: 'tmp', issue: 'Path traversal', severity: 'high', url: '' }], deprecations: 0 }
|
|
13
|
+
*/
|
|
14
|
+
export function parseAudit(output) {
|
|
15
|
+
const entries = output
|
|
16
|
+
.split('\n')
|
|
17
|
+
.map((line, index) => ({ line, number: index + 1 }))
|
|
18
|
+
.filter(({ line }) => line.trim().startsWith('{'))
|
|
19
|
+
.map(({ line, number }) => {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(line);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error(`Cannot read line ${number} of the audit output`, {
|
|
25
|
+
cause: error,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.flatMap((entry) => entry.value === undefined ? [] : [{ name: entry.value, children: entry.children }]);
|
|
30
|
+
const deprecations = entries.filter((entry) => isDeprecation(entry.children?.['ID']));
|
|
31
|
+
return {
|
|
32
|
+
findings: entries
|
|
33
|
+
.filter((entry) => !deprecations.includes(entry))
|
|
34
|
+
.map((entry) => ({
|
|
35
|
+
name: entry.name,
|
|
36
|
+
issue: text(entry.children?.['Issue']),
|
|
37
|
+
severity: text(entry.children?.['Severity']),
|
|
38
|
+
url: text(entry.children?.['URL']),
|
|
39
|
+
})),
|
|
40
|
+
deprecations: deprecations.length,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Decides what an audit means (rule 36), in this order:
|
|
45
|
+
* 1. findings are reported, whatever the exit code
|
|
46
|
+
* 2. without the exit code, nothing more can be told
|
|
47
|
+
* 3. exit code 0 is clean
|
|
48
|
+
* 4. deprecation notices alone are clean: Yarn exits with 1 on them, and they
|
|
49
|
+
* show that the audit reached the registry
|
|
50
|
+
* 5. otherwise the audit failed. `yarn npm audit` prints nothing to standard
|
|
51
|
+
* output both when it is clean and when it fails (for example, the registry
|
|
52
|
+
* is unreachable), so only the exit code tells them apart
|
|
53
|
+
* @param result - The result from {@link parseAudit}
|
|
54
|
+
* @param exitCode - The exit code of `yarn npm audit`, or null when the workflow did not pass it
|
|
55
|
+
* @returns The outcome
|
|
56
|
+
* @example
|
|
57
|
+
* auditOutcome({ findings: [], deprecations: 0 }, 0); // 'clean'
|
|
58
|
+
* auditOutcome({ findings: [], deprecations: 0 }, 1); // 'failed'
|
|
59
|
+
*/
|
|
60
|
+
export function auditOutcome(result, exitCode) {
|
|
61
|
+
if (result.findings.length > 0) {
|
|
62
|
+
return 'report';
|
|
63
|
+
}
|
|
64
|
+
if (exitCode === null) {
|
|
65
|
+
return 'unknown';
|
|
66
|
+
}
|
|
67
|
+
if (exitCode === 0 || result.deprecations > 0) {
|
|
68
|
+
return 'clean';
|
|
69
|
+
}
|
|
70
|
+
return 'failed';
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The audit Issue of a line (rule 36). The body holds the latest findings,
|
|
74
|
+
* sorted so that it depends only on the line and the findings, not on the
|
|
75
|
+
* order of the audit output: an unchanged audit gives an unchanged body, and
|
|
76
|
+
* the Nightly rewrites the Issue only when the findings change.
|
|
77
|
+
* @param line - The branch the audit ran on
|
|
78
|
+
* @param findings - The findings
|
|
79
|
+
* @returns The Issue
|
|
80
|
+
* @example
|
|
81
|
+
* auditIssue('dev', parseAudit(output)).marker; // '<!-- release-automation:audit:dev -->'
|
|
82
|
+
*/
|
|
83
|
+
export function auditIssue(line, findings) {
|
|
84
|
+
const marker = auditMarker(line);
|
|
85
|
+
const lines = findings
|
|
86
|
+
.map((finding) => `- \`${finding.name}\`: ${finding.issue} (${finding.severity}) ${finding.url}`.trimEnd())
|
|
87
|
+
.toSorted();
|
|
88
|
+
return {
|
|
89
|
+
marker,
|
|
90
|
+
title: `Vulnerable dependencies on ${line}`,
|
|
91
|
+
body: [
|
|
92
|
+
marker,
|
|
93
|
+
'',
|
|
94
|
+
`The dependency audit of \`${line}\` found:`,
|
|
95
|
+
'',
|
|
96
|
+
...lines,
|
|
97
|
+
'',
|
|
98
|
+
'This list is rewritten with each audit. Write notes in comments, not here.',
|
|
99
|
+
'',
|
|
100
|
+
'Fix them on the line (a vulnerability fix PR, `resolutions`, or the age gate exception of the repository policy), then this Issue closes after a clean audit.',
|
|
101
|
+
'',
|
|
102
|
+
].join('\n'),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The marker of a line's audit Issue.
|
|
107
|
+
* @param line - The branch
|
|
108
|
+
* @returns The marker
|
|
109
|
+
* @example
|
|
110
|
+
* auditMarker('v3'); // '<!-- release-automation:audit:v3 -->'
|
|
111
|
+
*/
|
|
112
|
+
export function auditMarker(line) {
|
|
113
|
+
return `<!-- release-automation:audit:${line} -->`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Yarn gives a deprecation notice the ID `<name> (deprecation)`, and an
|
|
117
|
+
* advisory a number.
|
|
118
|
+
* @param id - The `ID` of an entry
|
|
119
|
+
*/
|
|
120
|
+
function isDeprecation(id) {
|
|
121
|
+
return typeof id === 'string' && id.endsWith('(deprecation)');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A field as text, empty when missing.
|
|
125
|
+
* @param value - The field
|
|
126
|
+
*/
|
|
127
|
+
function text(value) {
|
|
128
|
+
return typeof value === 'string' ? value : '';
|
|
129
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -26,7 +26,11 @@ const COMMANDS = {
|
|
|
26
26
|
publish: { 'dry-run': { type: 'boolean' } },
|
|
27
27
|
'nightly-dispatch': { force: { type: 'boolean' } },
|
|
28
28
|
'nightly-report': {},
|
|
29
|
-
'audit-report': {
|
|
29
|
+
'audit-report': {
|
|
30
|
+
line: { type: 'string' },
|
|
31
|
+
file: { type: 'string' },
|
|
32
|
+
'exit-code': { type: 'string' },
|
|
33
|
+
},
|
|
30
34
|
'approve-renovate': { pr: { type: 'string' } },
|
|
31
35
|
};
|
|
32
36
|
const PROMOTIONS = new Set(['beta', 'rc', 'stable']);
|
|
@@ -53,6 +57,20 @@ function prNumber(values) {
|
|
|
53
57
|
}
|
|
54
58
|
return value;
|
|
55
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* @param values - The parsed flags
|
|
62
|
+
* @returns The value of `--exit-code` as a number, or null when it is not given
|
|
63
|
+
*/
|
|
64
|
+
function exitCode(values) {
|
|
65
|
+
const value = values['exit-code'];
|
|
66
|
+
if (value === undefined) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if (typeof value !== 'string' || !/^\d+$/.test(value)) {
|
|
70
|
+
throw new Error(`--exit-code takes the exit code of yarn npm audit, but got ${JSON.stringify(value)}`);
|
|
71
|
+
}
|
|
72
|
+
return Number(value);
|
|
73
|
+
}
|
|
56
74
|
try {
|
|
57
75
|
const [command, ...rest] = process.argv.slice(2);
|
|
58
76
|
if (command === undefined || !Object.hasOwn(COMMANDS, command)) {
|
|
@@ -108,9 +126,10 @@ try {
|
|
|
108
126
|
break;
|
|
109
127
|
}
|
|
110
128
|
case 'audit-report': {
|
|
111
|
-
await auditReportCommand({
|
|
129
|
+
process.exitCode = await auditReportCommand({
|
|
112
130
|
line: required(flags, 'line'),
|
|
113
131
|
output: readFileSync(required(flags, 'file'), 'utf8'),
|
|
132
|
+
exitCode: exitCode(flags),
|
|
114
133
|
});
|
|
115
134
|
break;
|
|
116
135
|
}
|
package/dist/commands/context.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { classify } from '../classify.js';
|
|
2
|
+
import { issuesToRewrite } from '../issue-body.js';
|
|
2
3
|
import { createGit } from '../io/git.js';
|
|
3
4
|
import { createGitHub } from '../io/github.js';
|
|
4
5
|
import { readFacts } from '../io/repo.js';
|
|
@@ -12,6 +13,8 @@ export const BLOCKER_LABEL = 'release-blocker';
|
|
|
12
13
|
export const VERIFY_CHECK = 'release-pr-verified';
|
|
13
14
|
/** The file name of the Full CI workflow the Nightly dispatches. */
|
|
14
15
|
export const FULL_CI_WORKFLOW = 'full-ci.yml';
|
|
16
|
+
/** The file name of the Nightly workflow, whose schedule starts the Full CI of each line. */
|
|
17
|
+
export const NIGHTLY_WORKFLOW = 'nightly.yml';
|
|
15
18
|
/**
|
|
16
19
|
* Reads an environment variable that must be set.
|
|
17
20
|
* @param name - The variable
|
|
@@ -102,6 +105,32 @@ export async function ensureIssue(gh, issue, labels) {
|
|
|
102
105
|
});
|
|
103
106
|
return true;
|
|
104
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Opens an Issue, or rewrites the body of the open Issues with the same
|
|
110
|
+
* marker when it differs and comments on them. For Issues that report the
|
|
111
|
+
* latest state, unlike {@link ensureIssue}, which keeps the first report.
|
|
112
|
+
* The comment is there because editing a body notifies no one. The title and
|
|
113
|
+
* the labels of an open Issue are left as they are.
|
|
114
|
+
* @param gh - The client
|
|
115
|
+
* @param issue - The Issue
|
|
116
|
+
* @param comment - The comment left on each rewritten Issue
|
|
117
|
+
* @example
|
|
118
|
+
* await upsertIssue(gh, auditIssue('dev', findings), 'The audit of `dev` changed.');
|
|
119
|
+
*/
|
|
120
|
+
export async function upsertIssue(gh, issue, comment) {
|
|
121
|
+
const open = await openIssuesWith(gh, issue.marker);
|
|
122
|
+
if (open.length === 0) {
|
|
123
|
+
await gh.rest('POST', '/repos/{repo}/issues', {
|
|
124
|
+
title: issue.title,
|
|
125
|
+
body: issue.body,
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
for (const number of issuesToRewrite(open, issue.body)) {
|
|
130
|
+
await gh.rest('PATCH', `/repos/{repo}/issues/${number}`, { body: issue.body });
|
|
131
|
+
await gh.rest('POST', `/repos/{repo}/issues/${number}/comments`, { body: comment });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
105
134
|
/**
|
|
106
135
|
* Closes the open Issues with a marker.
|
|
107
136
|
* @param gh - The client
|
package/dist/commands/nightly.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { parse as parseYaml } from 'yaml';
|
|
2
|
+
import { auditIssue, auditMarker, auditOutcome, parseAudit } from '../audit.js';
|
|
2
3
|
import { fetchPackument } from '../io/npm.js';
|
|
3
4
|
import { blockerMarker, isBlocked, nightlyAction } from '../nightly.js';
|
|
4
5
|
import { eolIssues } from '../rotation.js';
|
|
5
|
-
import { BLOCKER_LABEL, classifiedLines, closeIssuesWith, ensureIssue, FULL_CI_WORKFLOW, github, localGit, summary, } from './context.js';
|
|
6
|
+
import { BLOCKER_LABEL, classifiedLines, closeIssuesWith, ensureIssue, FULL_CI_WORKFLOW, github, localGit, summary, upsertIssue, } from './context.js';
|
|
6
7
|
import { nightlyRuns } from './runs.js';
|
|
7
8
|
/** How long a version stays behind the age gate. */
|
|
8
9
|
const AGE_GATE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
@@ -88,38 +89,41 @@ export async function nightlyReportCommand() {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
/**
|
|
91
|
-
* Turns the output of `yarn npm audit --json` on a line into
|
|
92
|
-
*
|
|
93
|
-
*
|
|
92
|
+
* Turns the output of `yarn npm audit --json` on a line into the line's audit
|
|
93
|
+
* Issue, by the outcome of {@link auditOutcome}: opens the Issue or rewrites it
|
|
94
|
+
* with the latest findings and a comment, closes it when the audit is clean,
|
|
95
|
+
* and keeps it when the audit failed or its exit code is unknown.
|
|
96
|
+
* @param options - The line and the audit
|
|
94
97
|
* @param options.line - The branch the audit ran on
|
|
95
98
|
* @param options.output - The audit output (one JSON object per line)
|
|
99
|
+
* @param options.exitCode - The exit code of `yarn npm audit`, or null when unknown
|
|
100
|
+
* @returns The exit code of the command: 1 when the audit failed
|
|
96
101
|
* @example
|
|
97
|
-
* await auditReportCommand({ line: 'v3', output: readFileSync('audit.json', 'utf8') });
|
|
102
|
+
* await auditReportCommand({ line: 'v3', output: readFileSync('audit.json', 'utf8'), exitCode: 1 });
|
|
98
103
|
*/
|
|
99
104
|
export async function auditReportCommand(options) {
|
|
100
105
|
const gh = github('GITHUB_TOKEN');
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
const result = parseAudit(options.output);
|
|
107
|
+
const marker = auditMarker(options.line);
|
|
108
|
+
switch (auditOutcome(result, options.exitCode)) {
|
|
109
|
+
case 'report': {
|
|
110
|
+
await upsertIssue(gh, auditIssue(options.line, result.findings), `This Issue was rewritten with the latest audit of \`${options.line}\`.`);
|
|
111
|
+
await summary(`${options.line}: ${result.findings.length} findings`);
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
case 'clean': {
|
|
115
|
+
await closeIssuesWith(gh, marker, `The audit of \`${options.line}\` is clean.`);
|
|
116
|
+
await summary(`${options.line}: the audit is clean`);
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
case 'failed': {
|
|
120
|
+
await summary(`${options.line}: yarn npm audit failed with exit code ${options.exitCode}; the audit Issue is left as it is`);
|
|
121
|
+
return 1;
|
|
122
|
+
}
|
|
123
|
+
case 'unknown': {
|
|
124
|
+
// The workflow command makes the warning visible on the run, not only in its log.
|
|
125
|
+
await summary(`::warning::${options.line}: no findings, but without --exit-code a clean audit cannot be told from a failed one; the audit Issue is left as it is`);
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
110
128
|
}
|
|
111
|
-
await ensureIssue(gh, {
|
|
112
|
-
marker,
|
|
113
|
-
title: `Vulnerable dependencies on ${options.line}`,
|
|
114
|
-
body: [
|
|
115
|
-
marker,
|
|
116
|
-
'',
|
|
117
|
-
`The dependency audit of \`${options.line}\` found:`,
|
|
118
|
-
'',
|
|
119
|
-
...findings.map((finding) => `- \`${finding.value}\`: ${finding.children?.['Issue'] ?? ''} (${finding.children?.['Severity'] ?? ''}) ${finding.children?.['URL'] ?? ''}`),
|
|
120
|
-
'',
|
|
121
|
-
'Fix them on the line (a vulnerability fix PR, `resolutions`, or the age gate exception of the repository policy), then this Issue closes after a clean audit.',
|
|
122
|
-
'',
|
|
123
|
-
].join('\n'),
|
|
124
|
-
}, []);
|
|
125
129
|
}
|
|
@@ -7,7 +7,7 @@ import { releaseContent } from '../release-content.js';
|
|
|
7
7
|
import { DEFAULT_SECURITY_BATCH_MINUTES } from '../types.js';
|
|
8
8
|
import { classifiedLines, ensureIssue, github, localGit, RELEASE_LABEL, REPLACED_LABEL, requireEnv, summary, } from './context.js';
|
|
9
9
|
import { generateRelease } from './generate.js';
|
|
10
|
-
import { nightlyRuns } from './runs.js';
|
|
10
|
+
import { nightlyAddedAt, nightlyRuns } from './runs.js';
|
|
11
11
|
/** The label of a pull request that fixes a vulnerability. */
|
|
12
12
|
export const SECURITY_LABEL = 'security';
|
|
13
13
|
/**
|
|
@@ -83,9 +83,10 @@ export async function releasePrCommand(options) {
|
|
|
83
83
|
}
|
|
84
84
|
const prs = await gh.paginate('/repos/{repo}/pulls?state=all&sort=updated&direction=desc');
|
|
85
85
|
const releasePrs = prs.filter((pr) => pr.labels.some(({ name }) => name === RELEASE_LABEL));
|
|
86
|
+
const nightlyAdded = await nightlyAddedAt(gh);
|
|
86
87
|
for (const line of targets) {
|
|
87
88
|
const runs = await nightlyRuns(gh, line.branch);
|
|
88
|
-
if (isStale(runs, now)) {
|
|
89
|
+
if (isStale(runs, now, nightlyAdded)) {
|
|
89
90
|
await ensureIssue(gh, {
|
|
90
91
|
marker: `<!-- release-automation:nightly-stale:${line.branch} -->`,
|
|
91
92
|
title: `The Nightly of ${line.branch} stopped running`,
|
package/dist/commands/runs.js
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GitHubError } from '../io/github.js';
|
|
2
|
+
import { FULL_CI_WORKFLOW, NIGHTLY_WORKFLOW } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads when the Nightly workflow was added to the repository, which
|
|
5
|
+
* {@link isStale} counts from while a line has no finished run.
|
|
6
|
+
* @param gh - The client
|
|
7
|
+
* @returns The time, or undefined when the repository has no Nightly workflow
|
|
8
|
+
* @example
|
|
9
|
+
* isStale(runs, new Date(), await nightlyAddedAt(gh));
|
|
10
|
+
*/
|
|
11
|
+
export async function nightlyAddedAt(gh) {
|
|
12
|
+
try {
|
|
13
|
+
const workflow = await gh.rest('GET', `/repos/{repo}/actions/workflows/${NIGHTLY_WORKFLOW}`);
|
|
14
|
+
return new Date(workflow.created_at);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof GitHubError && error.status === 404) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
2
23
|
/**
|
|
3
24
|
* Reads the finished Nightly runs of a line: the Full CI runs started by
|
|
4
25
|
* `workflow_dispatch` on the line's branch, newest first. A run that was
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picks the open Issues whose body differs from the latest report, for the
|
|
3
|
+
* Issues that are rewritten with each run. Line endings and trailing
|
|
4
|
+
* whitespace are ignored, since GitHub may store the body with CRLF or trim it.
|
|
5
|
+
* @param open - The open Issues with the report's marker
|
|
6
|
+
* @param body - The latest body
|
|
7
|
+
* @returns The numbers of the Issues to rewrite
|
|
8
|
+
* @example
|
|
9
|
+
* issuesToRewrite([{ number: 1, body: 'old' }], 'new\n'); // [1]
|
|
10
|
+
*/
|
|
11
|
+
export function issuesToRewrite(open, body) {
|
|
12
|
+
const latest = normalize(body);
|
|
13
|
+
return open
|
|
14
|
+
.filter((issue) => normalize(issue.body ?? '') !== latest)
|
|
15
|
+
.map((issue) => issue.number);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The body with LF line endings and no trailing whitespace.
|
|
19
|
+
* @param body - The body
|
|
20
|
+
*/
|
|
21
|
+
function normalize(body) {
|
|
22
|
+
return body.replaceAll('\r\n', '\n').trimEnd();
|
|
23
|
+
}
|
package/dist/nightly.js
CHANGED
|
@@ -31,18 +31,22 @@ export function isBlocked(runs) {
|
|
|
31
31
|
/** How long without a finished Nightly before it counts as stopped. */
|
|
32
32
|
export const NIGHTLY_STALE_MS = 2 * 24 * 60 * 60 * 1000;
|
|
33
33
|
/**
|
|
34
|
-
* Tells whether the Nightly of a line stopped running. GitHub
|
|
35
|
-
* schedule of a public repository after 60 days without
|
|
36
|
-
* stopped Nightly would leave the gate on stale results.
|
|
34
|
+
* Tells whether the Nightly of a line stopped running (rule 35). GitHub
|
|
35
|
+
* disables the schedule of a public repository after 60 days without
|
|
36
|
+
* activity, and a stopped Nightly would leave the gate on stale results.
|
|
37
|
+
* The time counts from the newest finished run; when the line has none, from
|
|
38
|
+
* when the Nightly workflow was added, so a Nightly set up a moment ago is not
|
|
39
|
+
* taken as stopped while one that never ran is.
|
|
37
40
|
* @param runs - The finished runs of the line, newest first
|
|
38
41
|
* @param now - The current time
|
|
39
|
-
* @
|
|
42
|
+
* @param since - When the Nightly workflow was added; without it, a line with no run counts as stopped
|
|
43
|
+
* @returns Whether more than {@link NIGHTLY_STALE_MS} passed since the newest run, or since `since` when there is no run
|
|
40
44
|
* @example
|
|
41
|
-
* isStale([], new Date()); //
|
|
45
|
+
* isStale([], new Date('2026-11-27T12:00:00Z'), new Date('2026-11-27T00:00:00Z')); // false
|
|
42
46
|
*/
|
|
43
|
-
export function isStale(runs, now) {
|
|
44
|
-
const
|
|
45
|
-
return
|
|
47
|
+
export function isStale(runs, now, since) {
|
|
48
|
+
const from = runs[0]?.finishedAt ?? since;
|
|
49
|
+
return from === undefined || now.getTime() - from.getTime() > NIGHTLY_STALE_MS;
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
52
|
* The marker that identifies the `release-blocker` Issue of a line.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/release-automation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Release lines, Release PRs, nightly gates and publishing for D-ZERO repositories",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"@types/node": "26.6.6",
|
|
69
69
|
"husky": "9.1.7",
|
|
70
70
|
"npm-run-all2": "9.1.0",
|
|
71
|
-
"oxfmt": "0.
|
|
72
|
-
"oxlint": "1.
|
|
71
|
+
"oxfmt": "0.80.0",
|
|
72
|
+
"oxlint": "1.95.0",
|
|
73
73
|
"oxlint-tsgolint": "7.0.2008",
|
|
74
74
|
"textlint": "16.1.3",
|
|
75
75
|
"typescript": "7.0.2",
|