Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

check-nightly-release.cjs

44 lines1.4 KB

1const MINIMUM_RELEASE_GAP_MS = 6 * 60 * 60 * 1000;
2​
3// Runs after the workflow acquires the nightly concurrency lock.
4async function shouldReleaseNightly({ github, context, core, now = Date.now() }) {
5 const releases = await github.paginate(github.rest.repos.listReleases, {
6 ...context.repo,
7 per_page: 100,
8 });
9 const lastNightly = releases
10 .filter(
11 (release) =>
12 !release.draft &&
13 release.published_at &&
14 (/^v.*-nightly\./.test(release.tag_name) || release.tag_name.startsWith("nightly-v")),
15 )
16 .sort((a, b) => Date.parse(b.published_at) - Date.parse(a.published_at))[0];
17​
18 if (!lastNightly) {
19 core.info("No published nightly found. Proceeding with release.");
20 return true;
21 }
22​
23 if (now - Date.parse(lastNightly.published_at) < MINIMUM_RELEASE_GAP_MS) {
24 core.info(`Nightly ${lastNightly.tag_name} was published less than six hours ago. Skipping.`);
25 return false;
26 }
27​
28 const { data: comparison } = await github.rest.repos.compareCommitsWithBasehead({
29 ...context.repo,
30 basehead: `${lastNightly.tag_name}...${context.sha}`,
31 per_page: 1,
32 });
33 if (comparison.status !== "ahead") {
34 core.info(
35 `Candidate commit is ${comparison.status} relative to ${lastNightly.tag_name}. Skipping.`,
36 );
37 return false;
38 }
39​
40 core.info(`New commits since ${lastNightly.tag_name}, and the six-hour gap has passed.`);
41 return true;
43​
44module.exports = { shouldReleaseNightly };