Skip to content

Commit 7e51fcc

Browse files
t3dotggclaude
andcommitted
ci(release): rely on the step's built-in retries for the nightly lookup
#33149 turned on actions/github-script's `retries: 3` for this step. That plugin already retries 5xx, dropped connections, and GraphQL timeouts on every call, including the new GraphQL release query. The script's own retry loop stacked a second layer on top, so remove it with its core/sleep plumbing and tests. release.yml is no longer touched. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 812d33c commit 7e51fcc

3 files changed

Lines changed: 29 additions & 121 deletions

File tree

‎.github/scripts/check-nightly-release.cjs‎

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
11
const MINIMUM_RELEASE_GAP_MS = 6 * 60 * 60 * 1000;
2-
// Waits before each retry of a read that failed with a 5xx or a network error.
3-
const RETRY_DELAYS_MS = [2_000, 5_000, 10_000];
4-
5-
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
6-
7-
// Octokit reports network failures as status 500, so this also covers resets.
8-
// Auth, permission, validation, and GraphQL query errors fail at once.
9-
async function withRetry(label, request, { core, sleep = defaultSleep } = {}) {
10-
for (let attempt = 0; ; attempt++) {
11-
try {
12-
return await request();
13-
} catch (error) {
14-
const delay = RETRY_DELAYS_MS[attempt];
15-
if (delay === undefined || !(error?.status >= 500)) throw error;
16-
core?.warning(`${label} failed with status ${error.status}. Retrying in ${delay / 1000}s.`);
17-
await sleep(delay);
18-
}
19-
}
20-
}
212

223
function repositoryDefaultBranch(context) {
234
const branch = context.payload.repository?.default_branch;
@@ -27,22 +8,21 @@ function repositoryDefaultBranch(context) {
278
return branch;
289
}
2910

30-
async function assertCommitOnDefaultBranch({ github, context, core, sleep, sha }) {
11+
async function assertCommitOnDefaultBranch({ github, context, sha }) {
3112
const defaultBranch = repositoryDefaultBranch(context);
32-
const basehead = `${sha}...${defaultBranch}`;
33-
const { data: comparison } = await withRetry(
34-
`Compare ${basehead}`,
35-
() => github.rest.repos.compareCommitsWithBasehead({ ...context.repo, basehead, per_page: 1 }),
36-
{ core, sleep },
37-
);
13+
const { data: comparison } = await github.rest.repos.compareCommitsWithBasehead({
14+
...context.repo,
15+
basehead: `${sha}...${defaultBranch}`,
16+
per_page: 1,
17+
});
3818
if (comparison.status !== "ahead" && comparison.status !== "identical") {
3919
throw new Error(
4020
`Release commit ${sha} is not contained in ${defaultBranch} (${comparison.status}).`,
4121
);
4222
}
4323
}
4424

45-
async function assertReleaseSource({ github, context, core, sleep, releaseChannel }) {
25+
async function assertReleaseSource({ github, context, releaseChannel }) {
4626
if (releaseChannel === "preview") return;
4727
if (releaseChannel !== "stable" && releaseChannel !== "nightly") {
4828
throw new Error(`Unsupported release channel: ${releaseChannel}`);
@@ -55,7 +35,7 @@ async function assertReleaseSource({ github, context, core, sleep, releaseChanne
5535
);
5636
}
5737

58-
await assertCommitOnDefaultBranch({ github, context, core, sleep, sha: context.sha });
38+
await assertCommitOnDefaultBranch({ github, context, sha: context.sha });
5939
}
6040

6141
const isNightlyTag = (tag) => /^v.*-nightly\./.test(tag) || tag.startsWith("nightly-v");
@@ -76,15 +56,11 @@ const RELEASES_QUERY = `
7656
// Returns the nightly with the newest publishedAt. Release order follows the
7757
// tagged commit date, not publication, so every page is read unless `isSettled`
7858
// says the newest nightly seen so far already decides the caller's answer.
79-
async function findLatestNightly({ github, context, core, sleep, isSettled = () => false }) {
59+
async function findLatestNightly({ github, context, isSettled = () => false }) {
8060
let latest;
8161
let cursor = null;
8262
do {
83-
const { repository } = await withRetry(
84-
"List releases",
85-
() => github.graphql(RELEASES_QUERY, { ...context.repo, cursor }),
86-
{ core, sleep },
87-
);
63+
const { repository } = await github.graphql(RELEASES_QUERY, { ...context.repo, cursor });
8864
const { nodes, pageInfo } = repository.releases;
8965
for (const release of nodes) {
9066
if (release.isDraft || !release.publishedAt || !isNightlyTag(release.tagName)) continue;
@@ -98,10 +74,10 @@ async function findLatestNightly({ github, context, core, sleep, isSettled = ()
9874
return latest;
9975
}
10076

101-
async function shouldReleaseNightly({ github, context, core, sleep, now = Date.now() }) {
77+
async function shouldReleaseNightly({ github, context, core, now = Date.now() }) {
10278
const isInGap = (release) => now - Date.parse(release.publishedAt) < MINIMUM_RELEASE_GAP_MS;
10379
// Any nightly inside the gap means the newest one is too, so stop reading.
104-
const lastNightly = await findLatestNightly({ github, context, core, sleep, isSettled: isInGap });
80+
const lastNightly = await findLatestNightly({ github, context, isSettled: isInGap });
10581

10682
if (!lastNightly) {
10783
core.info("No published nightly found. Proceeding with release.");
@@ -114,12 +90,11 @@ async function shouldReleaseNightly({ github, context, core, sleep, now = Date.n
11490
return false;
11591
}
11692

117-
const basehead = `${tag}...${context.sha}`;
118-
const { data: comparison } = await withRetry(
119-
`Compare ${basehead}`,
120-
() => github.rest.repos.compareCommitsWithBasehead({ ...context.repo, basehead, per_page: 1 }),
121-
{ core, sleep },
122-
);
93+
const { data: comparison } = await github.rest.repos.compareCommitsWithBasehead({
94+
...context.repo,
95+
basehead: `${tag}...${context.sha}`,
96+
per_page: 1,
97+
});
12398
if (comparison.status !== "ahead") {
12499
core.info(`Candidate commit is ${comparison.status} relative to ${tag}. Skipping.`);
125100
return false;
@@ -129,18 +104,14 @@ async function shouldReleaseNightly({ github, context, core, sleep, now = Date.n
129104
return true;
130105
}
131106

132-
async function resolveLatestNightlyCommit({ github, context, core, sleep }) {
133-
const lastNightly = await findLatestNightly({ github, context, core, sleep });
107+
async function resolveLatestNightlyCommit({ github, context, core }) {
108+
const lastNightly = await findLatestNightly({ github, context });
134109
if (!lastNightly) {
135110
throw new Error("No published nightly found. Stable releases build the latest nightly commit.");
136111
}
137112

138113
const tag = lastNightly.tagName;
139-
const { data: commit } = await withRetry(
140-
`Read commit ${tag}`,
141-
() => github.rest.repos.getCommit({ ...context.repo, ref: tag }),
142-
{ core, sleep },
143-
);
114+
const { data: commit } = await github.rest.repos.getCommit({ ...context.repo, ref: tag });
144115
const version = /^(?:nightly-)?v(\d+\.\d+\.\d+)-nightly\./.exec(tag)?.[1];
145116
if (!version) {
146117
throw new Error(`Cannot derive a stable version from nightly tag ${tag}.`);

‎.github/scripts/check-nightly-release.test.cjs‎

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const nightly = (hoursAgo, overrides = {}) => ({
1414
publishedAt: new Date(now - hoursAgo * hour).toISOString(),
1515
...overrides,
1616
});
17-
const httpError = (status) => Object.assign(new Error(`HTTP ${status}`), { status });
1817

1918
function releaseSourceFixture({
2019
comparisonStatus = "ahead",
@@ -75,25 +74,16 @@ for (const comparisonStatus of ["behind", "diverged"]) {
7574
}
7675

7776
// `pages` holds the GraphQL release pages; `releases` is shorthand for one page.
78-
// `failures` are thrown, in order, before the listed pages are served.
79-
function fixture({
80-
releases = [nightly(7)],
81-
pages = [releases],
82-
failures = [],
83-
comparisonStatus = "ahead",
84-
} = {}) {
77+
function fixture({ releases = [nightly(7)], pages = [releases], comparisonStatus = "ahead" } = {}) {
8578
const calls = [];
8679
const cursors = [];
87-
const sleeps = [];
8880
return {
8981
calls,
9082
cursors,
91-
sleeps,
9283
options: {
9384
now,
94-
sleep: async (ms) => sleeps.push(ms),
9585
context: { repo: { owner: "example", repo: "app" }, sha: "new" },
96-
core: { info() {}, warning() {} },
86+
core: { info() {} },
9787
github: {
9888
rest: {
9989
repos: {
@@ -106,7 +96,6 @@ function fixture({
10696
async graphql(_query, { owner, repo, cursor }) {
10797
assert.deepEqual({ owner, repo }, { owner: "example", repo: "app" });
10898
cursors.push(cursor);
109-
if (failures.length > 0) throw failures.shift();
11099
const index = cursor === null ? 0 : Number(cursor);
111100
const hasNextPage = index + 1 < pages.length;
112101
return {
@@ -181,64 +170,12 @@ test("ignores stable releases and drafts when checking the gap", async () => {
181170
assert.equal(await shouldReleaseNightly(options), true);
182171
});
183172

184-
test("retries transient release list failures with bounded backoff", async () => {
185-
const { options, sleeps } = fixture({ failures: [httpError(504), httpError(500)] });
186-
assert.equal(await shouldReleaseNightly(options), true);
187-
assert.deepEqual(sleeps, [2_000, 5_000]);
188-
});
189-
190-
test("fails instead of releasing when transient failures outlast the retries", async () => {
191-
const failures = [500, 504, 502, 503].map(httpError);
192-
const { options, cursors, sleeps } = fixture({ failures });
193-
await assert.rejects(shouldReleaseNightly(options), /HTTP 503/);
194-
assert.equal(cursors.length, 4);
195-
assert.deepEqual(sleeps, [2_000, 5_000, 10_000]);
196-
});
197-
198-
for (const failure of [httpError(401), httpError(422), new Error("GraphQL query error")]) {
199-
test(`fails at once without retrying: ${failure.message}`, async () => {
200-
const { options, cursors } = fixture({ failures: [failure] });
201-
await assert.rejects(shouldReleaseNightly(options), failure);
202-
assert.equal(cursors.length, 1);
203-
});
204-
}
205-
206-
test("retries a transient failure on a later page without losing earlier pages", async () => {
207-
const { options, cursors, calls } = fixture({
208-
pages: [[nightly(10)], [nightly(8, { tagName: "v1.0.1-nightly.20260905.200" })]],
209-
});
210-
const graphql = options.github.graphql;
211-
let failed = false;
212-
options.github.graphql = async (query, variables) => {
213-
if (variables.cursor === "1" && !failed) {
214-
failed = true;
215-
cursors.push(variables.cursor);
216-
throw httpError(502);
217-
}
218-
return graphql(query, variables);
219-
};
220-
assert.equal(await shouldReleaseNightly(options), true);
221-
assert.deepEqual(cursors, [null, "1", "1"]);
222-
assert.deepEqual(
223-
calls.map((call) => call.basehead),
224-
["v1.0.1-nightly.20260905.200...new"],
225-
);
226-
});
227-
228-
test("retries a transient comparison failure", async () => {
229-
const { options, calls, sleeps } = fixture();
230-
const compare = options.github.rest.repos.compareCommitsWithBasehead;
231-
let failed = false;
232-
options.github.rest.repos.compareCommitsWithBasehead = async (params) => {
233-
if (!failed) {
234-
failed = true;
235-
throw httpError(500);
236-
}
237-
return compare(params);
173+
test("fails instead of releasing when GitHub cannot supply release state", async () => {
174+
const { options } = fixture();
175+
options.github.graphql = async () => {
176+
throw new Error("GitHub unavailable");
238177
};
239-
assert.equal(await shouldReleaseNightly(options), true);
240-
assert.equal(calls.length, 1);
241-
assert.deepEqual(sleeps, [2_000]);
178+
await assert.rejects(shouldReleaseNightly(options), /GitHub unavailable/);
242179
});
243180

244181
for (const status of ["behind", "diverged"]) {

‎.github/workflows/release.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ jobs:
8686
? dispatchChannel
8787
: 'stable';
8888
89-
await assertReleaseSource({ github, context, core, releaseChannel });
89+
await assertReleaseSource({ github, context, releaseChannel });
9090
9191
if (context.eventName === 'schedule') {
9292
core.setOutput('has_changes', await shouldReleaseNightly({ github, context, core }));
9393
core.setOutput('ref', context.sha);
9494
} else if (context.eventName === 'workflow_dispatch' && dispatchChannel === 'stable') {
9595
const { tag, sha, version } = await resolveLatestNightlyCommit({ github, context, core });
96-
await assertCommitOnDefaultBranch({ github, context, core, sha });
96+
await assertCommitOnDefaultBranch({ github, context, sha });
9797
core.notice(`Stable release builds ${sha}, the commit shipped by ${tag}.`);
9898
core.setOutput('ref', sha);
9999
core.setOutput('nightly_version', version);

0 commit comments

Comments
 (0)