@d-zero/release-automation 0.0.2 → 0.0.4
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/dist/commands/context.js +2 -0
- package/dist/commands/release-pr.js +3 -2
- package/dist/commands/runs.js +22 -1
- package/dist/io/repo.js +9 -3
- package/dist/nightly.js +12 -8
- package/package.json +1 -1
package/dist/commands/context.js
CHANGED
|
@@ -13,6 +13,8 @@ export const BLOCKER_LABEL = 'release-blocker';
|
|
|
13
13
|
export const VERIFY_CHECK = 'release-pr-verified';
|
|
14
14
|
/** The file name of the Full CI workflow the Nightly dispatches. */
|
|
15
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';
|
|
16
18
|
/**
|
|
17
19
|
* Reads an environment variable that must be set.
|
|
18
20
|
* @param name - The variable
|
|
@@ -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
|
package/dist/io/repo.js
CHANGED
|
@@ -142,20 +142,26 @@ export function publishModeAt(git, rev) {
|
|
|
142
142
|
* automation acts on. The checks of a pull request read `HEAD` instead, so
|
|
143
143
|
* that the pull request that brings in or changes the definition is checked
|
|
144
144
|
* against what it proposes.
|
|
145
|
+
*
|
|
146
|
+
* The version of `dev` is always read from `origin/dev`, whatever the
|
|
147
|
+
* revision: the current major is the one `dev` carries. On a previous line
|
|
148
|
+
* the checked-out `lerna.json` states the previous major, and reading it
|
|
149
|
+
* there would make `dev` look like it carries that line.
|
|
145
150
|
* @param git - Git access
|
|
146
151
|
* @param now - The current time
|
|
147
|
-
* @param rev - The revision the files are read from
|
|
152
|
+
* @param rev - The revision the definition files are read from
|
|
148
153
|
* @returns The facts
|
|
149
154
|
* @example
|
|
150
155
|
* classify(readFacts(git, new Date()));
|
|
151
156
|
* classify(readFacts(git, new Date(), 'HEAD'));
|
|
152
157
|
*/
|
|
153
158
|
export function readFacts(git, now, rev = `origin/${CURRENT_BRANCH}`) {
|
|
154
|
-
const
|
|
159
|
+
const devRev = `origin/${CURRENT_BRANCH}`;
|
|
160
|
+
const lerna = git.show(devRev, 'lerna.json');
|
|
155
161
|
const root = JSON.parse(git.show(rev, 'package.json') ?? '{}');
|
|
156
162
|
const codeowners = git.show(rev, '.github/CODEOWNERS');
|
|
157
163
|
return {
|
|
158
|
-
devVersion: versionAt(git,
|
|
164
|
+
devVersion: versionAt(git, devRev),
|
|
159
165
|
lernaVersion: lerna === null
|
|
160
166
|
? null
|
|
161
167
|
: (JSON.parse(lerna).version ?? null),
|
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.
|