The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 02:00 UTC
ci(release): scheduled nightly checks read 10 KB instead of 28 MB (#33141)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Nov 8, 2026 at 18:22 UTC
81fb019fb7756fa0a3cdd42eef38e49281afc732
2 files changed
+126
-35
.github/scripts/check-nightly-release.cjs
+42
-17
@@ -40,42 +40,67 @@ async function assertReleaseSource({ github, context, releaseChannel }) {
40
41
const isNightlyTag = (tag) => /^v.*-nightly\./.test(tag) || tag.startsWith("nightly-v");
42
43
-async function findLatestNightly({ github, context }) {
44
- const releases = await github.paginate(github.rest.repos.listReleases, {
45
- ...context.repo,
46
- per_page: 100,
47
- });
48
- return releases
49
- .filter((release) => !release.draft && release.published_at && isNightlyTag(release.tag_name))
50
- .sort((a, b) => Date.parse(b.published_at) - Date.parse(a.published_at))[0];
43
+// Only the three fields the gate reads. The REST list also returns every asset,
44
+// which made a full scan tens of megabytes.
45
+const RELEASES_QUERY = `
46
+ query ($owner: String!, $repo: String!, $cursor: String) {
47
+ repository(owner: $owner, name: $repo) {
48
+ releases(first: 100, after: $cursor, orderBy: { field: CREATED_AT, direction: DESC }) {
49
+ pageInfo { hasNextPage endCursor }
50
+ nodes { tagName isDraft publishedAt }
51
+ }
52
+ }
53
+ }
54
+`;
55
+
56
+// Returns the nightly with the newest publishedAt. Release order follows the
57
+// tagged commit date, not publication, so every page is read unless `isSettled`
58
+// says the newest nightly seen so far already decides the caller's answer.
59
+async function findLatestNightly({ github, context, isSettled = () => false }) {
60
+ let latest;
61
+ let cursor = null;
62
+ do {
63
+ const { repository } = await github.graphql(RELEASES_QUERY, { ...context.repo, cursor });
64
+ const { nodes, pageInfo } = repository.releases;
65
+ for (const release of nodes) {
66
+ if (release.isDraft || !release.publishedAt || !isNightlyTag(release.tagName)) continue;
67
+ if (!latest || Date.parse(release.publishedAt) > Date.parse(latest.publishedAt)) {
68
+ latest = release;
69
+ }
70
+ }
71
+ if (latest && isSettled(latest)) return latest;
72
+ cursor = pageInfo.hasNextPage ? pageInfo.endCursor : null;
73
+ } while (cursor);
74
+ return latest;
75
}
76
77
async function shouldReleaseNightly({ github, context, core, now = Date.now() }) {
54
- const lastNightly = await findLatestNightly({ github, context });
78
+ const isInGap = (release) => now - Date.parse(release.publishedAt) < MINIMUM_RELEASE_GAP_MS;
79
+ // Any nightly inside the gap means the newest one is too, so stop reading.
80
+ const lastNightly = await findLatestNightly({ github, context, isSettled: isInGap });
81
82
if (!lastNightly) {
83
core.info("No published nightly found. Proceeding with release.");
84
return true;
85
}
86
61
- if (now - Date.parse(lastNightly.published_at) < MINIMUM_RELEASE_GAP_MS) {
62
- core.info(`Nightly ${lastNightly.tag_name} was published less than six hours ago. Skipping.`);
87
+ const tag = lastNightly.tagName;
88
+ if (isInGap(lastNightly)) {
89
+ core.info(`Nightly ${tag} was published less than six hours ago. Skipping.`);
90
return false;
91
}
92
93
const { data: comparison } = await github.rest.repos.compareCommitsWithBasehead({
94
...context.repo,
68
- basehead: `${lastNightly.tag_name}...${context.sha}`,
95
+ basehead: `${tag}...${context.sha}`,
96
per_page: 1,
97
});
98
if (comparison.status !== "ahead") {
72
- core.info(
73
- `Candidate commit is ${comparison.status} relative to ${lastNightly.tag_name}. Skipping.`,
74
- );
99
+ core.info(`Candidate commit is ${comparison.status} relative to ${tag}. Skipping.`);
100
return false;
101
}
102
78
- core.info(`New commits since ${lastNightly.tag_name}, and the six-hour gap has passed.`);
103
+ core.info(`New commits since ${tag}, and the six-hour gap has passed.`);
104
return true;
105
}
106
@@ -85,7 +110,7 @@ async function resolveLatestNightlyCommit({ github, context, core }) {
110
throw new Error("No published nightly found. Stable releases build the latest nightly commit.");
111
}
112
88
- const tag = lastNightly.tag_name;
113
+ const tag = lastNightly.tagName;
114
const { data: commit } = await github.rest.repos.getCommit({ ...context.repo, ref: tag });
115
const version = /^(?:nightly-)?v(\d+\.\d+\.\d+)-nightly\./.exec(tag)?.[1];
116
if (!version) {
.github/scripts/check-nightly-release.test.cjs
+84
-18
@@ -9,9 +9,9 @@ const {
9
const now = Date.parse("2026-09-05T12:00:00Z");
10
const hour = 60 * 60 * 1000;
11
const nightly = (hoursAgo, overrides = {}) => ({
12
- tag_name: "v1.0.1-nightly.20260905.123",
13
- draft: false,
14
- published_at: new Date(now - hoursAgo * hour).toISOString(),
12
+ tagName: "v1.0.1-nightly.20260905.123",
13
+ isDraft: false,
14
+ publishedAt: new Date(now - hoursAgo * hour).toISOString(),
15
...overrides,
16
});
17
@@ -73,10 +73,13 @@ for (const comparisonStatus of ["behind", "diverged"]) {
73
});
74
}
75
76
-function fixture({ releases = [nightly(7)], comparisonStatus = "ahead" } = {}) {
76
+// `pages` holds the GraphQL release pages; `releases` is shorthand for one page.
77
+function fixture({ releases = [nightly(7)], pages = [releases], comparisonStatus = "ahead" } = {}) {
78
const calls = [];
79
+ const cursors = [];
80
return {
81
calls,
82
+ cursors,
83
options: {
84
now,
85
context: { repo: { owner: "example", repo: "app" }, sha: "new" },
@@ -84,15 +87,25 @@ function fixture({ releases = [nightly(7)], comparisonStatus = "ahead" } = {}) {
87
github: {
88
rest: {
89
repos: {
87
- listReleases() {},
90
async compareCommitsWithBasehead(params) {
91
calls.push(params);
92
return { data: { status: comparisonStatus } };
93
},
94
},
95
},
94
- async paginate() {
95
- return releases;
96
+ async graphql(_query, { owner, repo, cursor }) {
97
+ assert.deepEqual({ owner, repo }, { owner: "example", repo: "app" });
98
+ cursors.push(cursor);
99
+ const index = cursor === null ? 0 : Number(cursor);
100
+ const hasNextPage = index + 1 < pages.length;
101
+ return {
102
+ repository: {
103
+ releases: {
104
+ nodes: pages[index],
105
+ pageInfo: { hasNextPage, endCursor: hasNextPage ? String(index + 1) : null },
106
+ },
107
+ },
108
+ };
109
},
110
},
111
},
@@ -101,28 +114,65 @@ function fixture({ releases = [nightly(7)], comparisonStatus = "ahead" } = {}) {
114
115
test("releases the first nightly when no nightly is published", async () => {
116
const { options } = fixture({
104
- releases: [nightly(0, { tag_name: "v1.0.0" }), nightly(0, { draft: true })],
117
+ releases: [nightly(0, { tagName: "v1.0.0" }), nightly(0, { isDraft: true })],
118
});
119
assert.equal(await shouldReleaseNightly(options), true);
120
});
121
122
test("uses publication time, not release order or the tagged commit date", async () => {
123
const { options } = fixture({
111
- releases: [nightly(10), nightly(1), nightly(20, { tag_name: "nightly-v0.9.0" })],
124
+ releases: [nightly(10), nightly(1), nightly(20, { tagName: "nightly-v0.9.0" })],
125
+ });
126
+ assert.equal(await shouldReleaseNightly(options), false);
127
+});
128
+
129
+test("the six-hour gap ends exactly six hours after publication", async () => {
130
+ const atBoundary = fixture({ releases: [nightly(6)] });
131
+ assert.equal(await shouldReleaseNightly(atBoundary.options), true);
132
+ const justInside = fixture({ releases: [nightly(6 - 1 / 3_600_000)] });
133
+ assert.equal(await shouldReleaseNightly(justInside.options), false);
134
+ assert.equal(justInside.calls.length, 0);
135
+});
136
+
137
+test("stops reading releases once a nightly inside the gap is seen", async () => {
138
+ const { options, cursors } = fixture({ pages: [[nightly(10), nightly(2)], [nightly(30)]] });
139
+ assert.equal(await shouldReleaseNightly(options), false);
140
+ assert.deepEqual(cursors, [null]);
141
+});
142
+
143
+test("reads every page when no nightly seen so far settles the gap", async () => {
144
+ const { options, cursors, calls } = fixture({
145
+ pages: [
146
+ [nightly(10), nightly(0, { tagName: "v1.0.0" })],
147
+ [nightly(1, { tagName: "nightly-v0.9.0" })],
148
+ ],
149
});
150
assert.equal(await shouldReleaseNightly(options), false);
151
+ assert.deepEqual(cursors, [null, "1"]);
152
+ assert.equal(calls.length, 0);
153
+});
154
+
155
+test("compares against the newest nightly across pages once the gap has passed", async () => {
156
+ const { options, calls } = fixture({
157
+ pages: [[nightly(10, { tagName: "v1.0.1-nightly.20260905.100" })], [nightly(8)]],
158
+ });
159
+ assert.equal(await shouldReleaseNightly(options), true);
160
+ assert.deepEqual(
161
+ calls.map((call) => call.basehead),
162
+ ["v1.0.1-nightly.20260905.123...new"],
163
+ );
164
});
165
166
test("ignores stable releases and drafts when checking the gap", async () => {
167
const { options } = fixture({
118
- releases: [nightly(0, { tag_name: "v1.0.0" }), nightly(0, { draft: true }), nightly(7)],
168
+ releases: [nightly(0, { tagName: "v1.0.0" }), nightly(0, { isDraft: true }), nightly(7)],
169
});
170
assert.equal(await shouldReleaseNightly(options), true);
171
});
172
173
test("fails instead of releasing when GitHub cannot supply release state", async () => {
174
const { options } = fixture();
125
- options.github.paginate = async () => {
175
+ options.github.graphql = async () => {
176
throw new Error("GitHub unavailable");
177
};
178
await assert.rejects(shouldReleaseNightly(options), /GitHub unavailable/);
@@ -137,9 +187,9 @@ for (const status of ["behind", "diverged"]) {
187
188
const { resolveLatestNightlyCommit } = require("./check-nightly-release.cjs");
189
140
-function nightlyCommitFixture({ releases, commitSha = "abc123" }) {
190
+function nightlyCommitFixture({ releases, pages, commitSha = "abc123" }) {
191
const refs = [];
142
- const { options } = fixture({ releases });
192
+ const { options } = fixture({ releases, pages });
193
options.github.rest.repos.getCommit = async ({ ref }) => {
194
refs.push(ref);
195
return { data: { sha: commitSha } };
@@ -150,10 +200,10 @@ function nightlyCommitFixture({ releases, commitSha = "abc123" }) {
200
test("stable releases resolve the commit of the newest published nightly", async () => {
201
const { options, refs } = nightlyCommitFixture({
202
releases: [
153
- nightly(10, { tag_name: "v1.0.1-nightly.20260905.100" }),
154
- nightly(1, { tag_name: "v1.0.1-nightly.20260905.123" }),
155
- nightly(0, { tag_name: "v1.0.0" }),
156
- nightly(0, { draft: true, tag_name: "v1.0.1-nightly.20260905.999" }),
203
+ nightly(10, { tagName: "v1.0.1-nightly.20260905.100" }),
204
+ nightly(1, { tagName: "v1.0.1-nightly.20260905.123" }),
205
+ nightly(0, { tagName: "v1.0.0" }),
206
+ nightly(0, { isDraft: true, tagName: "v1.0.1-nightly.20260905.999" }),
207
],
208
commitSha: "deadbeef",
209
});
@@ -167,7 +217,23 @@ test("stable releases resolve the commit of the newest published nightly", async
217
218
test("stable releases derive the version from legacy nightly tags", async () => {
219
const { options } = nightlyCommitFixture({
170
- releases: [nightly(1, { tag_name: "nightly-v0.9.0-nightly.20260905.5" })],
220
+ releases: [nightly(1, { tagName: "nightly-v0.9.0-nightly.20260905.5" })],
221
});
222
assert.equal((await resolveLatestNightlyCommit(options)).version, "0.9.0");
223
});
224
+
225
+test("stable releases read every page, even after a recent nightly", async () => {
226
+ const { options, refs } = nightlyCommitFixture({
227
+ pages: [
228
+ [nightly(2, { tagName: "v1.0.1-nightly.20260905.100" })],
229
+ [nightly(1, { tagName: "v1.0.1-nightly.20260905.123" })],
230
+ ],
231
+ });
232
+ assert.equal((await resolveLatestNightlyCommit(options)).tag, "v1.0.1-nightly.20260905.123");
233
+ assert.deepEqual(refs, ["v1.0.1-nightly.20260905.123"]);
234
+});
235
+
236
+test("stable releases fail when no nightly is published", async () => {
237
+ const { options } = nightlyCommitFixture({ releases: [nightly(1, { tagName: "v1.0.0" })] });
238
+ await assert.rejects(resolveLatestNightlyCommit(options), /No published nightly found/);
239
+});