Skip to content
This repository was archived by the owner on Oct 21, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/scripts/check-fork-release.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { assertReleaseSource, shouldReleaseNightly } = require("./check-nightly-release.cjs");

// Decides whether a Fork Release run publishes, and the UTC date its version
// carries. Manual dispatch skips the six-hour gap but must build main, since a
// published branch build would leave main behind it and stall later scheduled
// checks. The date is when the run was created, so a run that queues past
// midnight or is retried on another day keeps the same tag.
async function resolveForkRelease({ github, context, core }) {
if (context.eventName === "workflow_dispatch") {
await assertReleaseSource({ github, context, releaseChannel: "nightly" });
} else if (!(await shouldReleaseNightly({ github, context, core }))) {
return { due: false };
}

const { data: run } = await github.rest.actions.getWorkflowRun({
...context.repo,
run_id: context.runId,
});
return { due: true, date: run.created_at.slice(0, 10).replaceAll("-", "") };
}

module.exports = { resolveForkRelease };
82 changes: 82 additions & 0 deletions .github/scripts/check-fork-release.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const assert = require("node:assert/strict");
const test = require("node:test");
const { resolveForkRelease } = require("./check-fork-release.cjs");

const hour = 60 * 60 * 1000;
const core = { info() {} };

function fixture({
eventName = "workflow_dispatch",
ref = "refs/heads/main",
comparisonStatus = "ahead",
nightlyHoursAgo = 7,
createdAt = "2026-09-29T23:59:30Z",
} = {}) {
const runLookups = [];
return {
runLookups,
options: {
core,
context: {
eventName,
payload: { repository: { default_branch: "main" } },
ref,
repo: { owner: "example", repo: "app" },
runId: 42,
sha: "candidate",
},
github: {
async paginate() {
return [
{
tag_name: "v0.0.43-nightly.20260929.19",
draft: false,
published_at: new Date(Date.now() - nightlyHoursAgo * hour).toISOString(),
},
];
},
rest: {
actions: {
async getWorkflowRun(params) {
runLookups.push(params);
return { data: { created_at: createdAt } };
},
},
repos: {
async compareCommitsWithBasehead() {
return { data: { status: comparisonStatus } };
},
},
},
},
},
};
}

test("rejects a manual release dispatched from a feature branch", async () => {
const { options, runLookups } = fixture({ ref: "refs/heads/feature" });
await assert.rejects(resolveForkRelease(options), /must be dispatched from main/);
assert.equal(runLookups.length, 0);
});

test("rejects a manual release whose commit is not on main", async () => {
const { options } = fixture({ comparisonStatus: "diverged" });
await assert.rejects(resolveForkRelease(options), /not contained in main \(diverged\)/);
});

test("a manual release from main skips the six-hour gap", async () => {
const { options } = fixture({ nightlyHoursAgo: 1 });
assert.deepEqual(await resolveForkRelease(options), { due: true, date: "20260929" });
});

test("a scheduled run waits for the six-hour gap", async () => {
const { options, runLookups } = fixture({ eventName: "schedule", nightlyHoursAgo: 1 });
assert.deepEqual(await resolveForkRelease(options), { due: false });
assert.equal(runLookups.length, 0);
});

test("a run created before midnight keeps its date when it runs or retries after", async () => {
const { options, runLookups } = fixture({ eventName: "schedule" });
assert.deepEqual(await resolveForkRelease(options), { due: true, date: "20260929" });
assert.equal(runLookups[0].run_id, 42);
});
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ jobs:
- name: Test nightly release checks
run: node --test .github/scripts/check-nightly-release.test.cjs

- name: Test fork release checks
run: node --test .github/scripts/check-fork-release.test.cjs

- name: Test
run: vp run --parallel --concurrency-limit 4 --filter '!t3' --filter '!@t3tools/monorepo' test

Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/fork-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ jobs:
name: Check if a release is due
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
actions: read
outputs:
due: ${{ steps.check.outputs.due }}
date: ${{ steps.check.outputs.date }}
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
Expand All @@ -60,9 +64,10 @@ jobs:
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const { shouldReleaseNightly } = require('./.github/scripts/check-nightly-release.cjs');
const due = context.eventName !== 'schedule' || (await shouldReleaseNightly({ github, context, core }));
const { resolveForkRelease } = require('./.github/scripts/check-fork-release.cjs');
const { due, date } = await resolveForkRelease({ github, context, core });
core.setOutput('due', due);
if (date) core.setOutput('date', date);

version:
name: Resolve version
Expand Down Expand Up @@ -102,10 +107,12 @@ jobs:

- id: resolve
shell: bash
env:
RELEASE_DATE: ${{ needs.due.outputs.date }}
run: |
set -euo pipefail
node scripts/resolve-nightly-release.ts \
--date "$(date -u -d "${{ github.run_started_at }}" +%Y%m%d)" \
--date "$RELEASE_DATE" \
--run-number "${{ github.run_number }}" \
--sha "$GITHUB_SHA" \
--github-output
Expand Down
Loading