GeezerVison is showing github.com — ci(release): scheduled nightly checks read 10 KB instead of 28 MB (#3… · AndryHTC/t3code@81fb019
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/scripts/check-nightly-release.cjs +42-17Lines changed: 42 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,42 +40,67 @@ async function assertReleaseSource({ github, context, releaseChannel }) { | 40 | 40 |
| 41 | 41 | const isNightlyTag = (tag) => /^v.*-nightly\./.test(tag) || tag.startsWith("nightly-v"); | 42 | 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; | 51 | 75 | } | 52 | 76 |
| 53 | 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 }); | 55 | 81 |
| 56 | 82 | if (!lastNightly) { | 57 | 83 | core.info("No published nightly found. Proceeding with release."); | 58 | 84 | return true; | 59 | 85 | } | 60 | 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.`); | 63 | 90 | return false; | 64 | 91 | } | 65 | 92 |
| 66 | 93 | const { data: comparison } = await github.rest.repos.compareCommitsWithBasehead({ | 67 | 94 | ...context.repo, | 68 | | - basehead: `${lastNightly.tag_name}...${context.sha}`, | | 95 | + basehead: `${tag}...${context.sha}`, | 69 | 96 | per_page: 1, | 70 | 97 | }); | 71 | 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.`); | 75 | 100 | return false; | 76 | 101 | } | 77 | 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.`); | 79 | 104 | return true; | 80 | 105 | } | 81 | 106 |
| @@ -85,7 +110,7 @@ async function resolveLatestNightlyCommit({ github, context, core }) { | 85 | 110 | throw new Error("No published nightly found. Stable releases build the latest nightly commit."); | 86 | 111 | } | 87 | 112 |
| 88 | | - const tag = lastNightly.tag_name; | | 113 | + const tag = lastNightly.tagName; | 89 | 114 | const { data: commit } = await github.rest.repos.getCommit({ ...context.repo, ref: tag }); | 90 | 115 | const version = /^(?:nightly-)?v(\d+\.\d+\.\d+)-nightly\./.exec(tag)?.[1]; | 91 | 116 | if (!version) { | |
Collapse file Copy file name to clipboardExpand all lines: .github/scripts/check-nightly-release.test.cjs +84-18Lines changed: 84 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | const now = Date.parse("2026-09-05T12:00:00Z"); | 10 | 10 | const hour = 60 * 60 * 1000; | 11 | 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 | 15 | ...overrides, | 16 | 16 | }); | 17 | 17 |
| @@ -73,26 +73,39 @@ for (const comparisonStatus of ["behind", "diverged"]) { | 73 | 73 | }); | 74 | 74 | } | 75 | 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" } = {}) { | 77 | 78 | const calls = []; | | 79 | + const cursors = []; | 78 | 80 | return { | 79 | 81 | calls, | | 82 | + cursors, | 80 | 83 | options: { | 81 | 84 | now, | 82 | 85 | context: { repo: { owner: "example", repo: "app" }, sha: "new" }, | 83 | 86 | core: { info() {} }, | 84 | 87 | github: { | 85 | 88 | rest: { | 86 | 89 | repos: { | 87 | | - listReleases() {}, | 88 | 90 | async compareCommitsWithBasehead(params) { | 89 | 91 | calls.push(params); | 90 | 92 | return { data: { status: comparisonStatus } }; | 91 | 93 | }, | 92 | 94 | }, | 93 | 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 | + }; | 96 | 109 | }, | 97 | 110 | }, | 98 | 111 | }, | @@ -101,28 +114,65 @@ function fixture({ releases = [nightly(7)], comparisonStatus = "ahead" } = {}) { | 101 | 114 |
| 102 | 115 | test("releases the first nightly when no nightly is published", async () => { | 103 | 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 })], | 105 | 118 | }); | 106 | 119 | assert.equal(await shouldReleaseNightly(options), true); | 107 | 120 | }); | 108 | 121 |
| 109 | 122 | test("uses publication time, not release order or the tagged commit date", async () => { | 110 | 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 | + ], | 112 | 149 | }); | 113 | 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 | + ); | 114 | 164 | }); | 115 | 165 |
| 116 | 166 | test("ignores stable releases and drafts when checking the gap", async () => { | 117 | 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)], | 119 | 169 | }); | 120 | 170 | assert.equal(await shouldReleaseNightly(options), true); | 121 | 171 | }); | 122 | 172 |
| 123 | 173 | test("fails instead of releasing when GitHub cannot supply release state", async () => { | 124 | 174 | const { options } = fixture(); | 125 | | - options.github.paginate = async () => { | | 175 | + options.github.graphql = async () => { | 126 | 176 | throw new Error("GitHub unavailable"); | 127 | 177 | }; | 128 | 178 | await assert.rejects(shouldReleaseNightly(options), /GitHub unavailable/); | @@ -137,9 +187,9 @@ for (const status of ["behind", "diverged"]) { | 137 | 187 |
| 138 | 188 | const { resolveLatestNightlyCommit } = require("./check-nightly-release.cjs"); | 139 | 189 |
| 140 | | -function nightlyCommitFixture({ releases, commitSha = "abc123" }) { | | 190 | +function nightlyCommitFixture({ releases, pages, commitSha = "abc123" }) { | 141 | 191 | const refs = []; | 142 | | - const { options } = fixture({ releases }); | | 192 | + const { options } = fixture({ releases, pages }); | 143 | 193 | options.github.rest.repos.getCommit = async ({ ref }) => { | 144 | 194 | refs.push(ref); | 145 | 195 | return { data: { sha: commitSha } }; | @@ -150,10 +200,10 @@ function nightlyCommitFixture({ releases, commitSha = "abc123" }) { | 150 | 200 | test("stable releases resolve the commit of the newest published nightly", async () => { | 151 | 201 | const { options, refs } = nightlyCommitFixture({ | 152 | 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" }), | 157 | 207 | ], | 158 | 208 | commitSha: "deadbeef", | 159 | 209 | }); | @@ -167,7 +217,23 @@ test("stable releases resolve the commit of the newest published nightly", async | 167 | 217 |
| 168 | 218 | test("stable releases derive the version from legacy nightly tags", async () => { | 169 | 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" })], | 171 | 221 | }); | 172 | 222 | assert.equal((await resolveLatestNightlyCommit(options)).version, "0.9.0"); | 173 | 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 | +}); |
|