From 50bc5be75ba75db7244ee3b445a48e549d10a64f Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:05:38 +0200 Subject: [PATCH 1/5] feat(scripts): read the latest Panel release from GitHub before each build sync-release writes data/release.json (version, date, link). 5 s timeout, one retry; any failure prints one line and leaves the committed fallback, so the build never fails or waits on GitHub. --- AGENTS.md | 4 +- README.md | 2 +- data/release.json | 3 + package.json | 3 +- scripts/README.md | 10 +- scripts/sync-release.mjs | 130 ++++++++++++++++++++++++++ scripts/sync-release.test.mjs | 169 ++++++++++++++++++++++++++++++++++ 7 files changed, 314 insertions(+), 7 deletions(-) create mode 100644 data/release.json create mode 100644 scripts/sync-release.mjs create mode 100644 scripts/sync-release.test.mjs diff --git a/AGENTS.md b/AGENTS.md index add8a264..24304e8b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,7 +19,9 @@ This block is written and re-added by `next dev` — verify at `node_modules/nex - Before opening a pull request: `bun test`, `bun run typecheck`, `bun run build`. The build checks the pages before it (`check:content`), refreshes the egg data (`sync:eggs`, which uses the network and rewrites `data/eggs.json`, `public/data/eggs/`, `public/img/eggs/`, `public/img/games/`: don't - commit those unless the task is about eggs), and checks the paths and the links after it (`check:paths`, `check:links`). + commit those unless the task is about eggs), reads the latest Panel release from GitHub (`sync:release`, + which rewrites `data/release.json`: never commit it; on failure the build uses `lib/home-data.ts`'s typed + values), and checks the paths and the links after it (`check:paths`, `check:links`). - The paths this build serves on pelican.dev are in one file, `router/paths.mjs`. Change them there, and in the Hub's `DocsBuildService::ROOT_FILES` for the root files. - A new MDX component goes in `mdx-components.tsx` and in `COMPONENTS` in diff --git a/README.md b/README.md index 72615e46..16f06ead 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ bun test # the tests for scripts/ and router/ Every script in `scripts/` and `router/` runs on Bun and starts with the same header: what it does, when it runs, how to run it and where its tests are. [scripts/README.md](scripts/README.md) lists them all. -The build refreshes the egg data for the interim `/eggs` page (it uses the network), so it can change `data/eggs.json`, `public/data/eggs/`, `public/img/eggs/` and `public/img/games/`. Leave those out of a pull request unless it's about the egg data. +The build refreshes the egg data for the interim `/eggs` page (it uses the network), so it can change `data/eggs.json`, `public/data/eggs/`, `public/img/eggs/` and `public/img/games/`. Leave those out of a pull request unless it's about the egg data. It also writes the latest Panel release from GitHub into `data/release.json`; leave that out too (`git restore data`). ### Before a pull request diff --git a/data/release.json b/data/release.json new file mode 100644 index 00000000..9b14b0c3 --- /dev/null +++ b/data/release.json @@ -0,0 +1,3 @@ +{ + "note": "Written by scripts/sync-release.mjs before each build. Empty here: lib/home-data.ts uses its typed values." +} diff --git a/package.json b/package.json index 776b61be..c4c6c04a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "next dev", "dev:site": "bun router/dev-server.mjs", "build": "next build", - "prebuild": "bun scripts/check-content.mjs && bun scripts/sync-eggs.mjs --if-online", + "prebuild": "bun scripts/check-content.mjs && bun scripts/sync-eggs.mjs --if-online && bun scripts/sync-release.mjs", "postbuild": "bun scripts/check-paths.mjs && bun scripts/check-links.mjs", "test": "bun test", "typecheck": "fumadocs-mdx && next typegen && tsc --noEmit", @@ -15,6 +15,7 @@ "check:paths": "bun scripts/check-paths.mjs", "check:links": "bun scripts/check-links.mjs", "sync:eggs": "bun scripts/sync-eggs.mjs", + "sync:release": "bun scripts/sync-release.mjs", "pack:docs": "bun scripts/pack-docs.mjs", "postinstall": "fumadocs-mdx" }, diff --git a/scripts/README.md b/scripts/README.md index aaa9ee2f..c448d0e3 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -27,6 +27,7 @@ run and change one without reading the others first: | --- | --- | --- | --- | --- | | `check-content.mjs` | Fails if a page in `content/` could run code (MDX compiles pages to JavaScript) | Before every build, and in CI | `bun run check:content` | `check-content.test.mjs` | | `sync-eggs.mjs` | Refreshes the egg data for the interim `/eggs` page and the homepage games strip. Uses the network and rewrites `data/eggs.json`, `public/data/eggs/`, `public/img/eggs/` and `public/img/games/` | Before every build (`--if-online`: no network keeps the saved data; a bug still fails); by hand | `bun run sync:eggs` | `sync-eggs.test.mjs` | +| `sync-release.mjs` | Reads the latest Pelican Panel release from GitHub (version, date, link) for the homepage and `llms.txt`, into `data/release.json`. Uses the network (`GITHUB_TOKEN` if set); on any failure it prints one line and the build uses the typed values in `lib/home-data.ts` | Before every build (never fails it: 5 s timeout, one retry); by hand | `bun run sync:release` | `sync-release.test.mjs` | | `check-paths.mjs` | Fails if the build puts a file where pelican.dev won't serve it from this build, misses a root file, or a docs page loads something from outside `/docs/` | After every build, and in CI | `bun run check:paths` | `check-paths.test.mjs` | | `check-links.mjs` | Fails if a link on a docs page goes to a docs page, file or `#anchor` that isn't in the build (links to the Hub and other sites aren't checked) | After every build, and in CI | `bun run check:links` | `check-links.test.mjs` | | `pack-docs.mjs` | Packs `out/` into the folder the Hub serves on pelican.dev (docs, root files, 404 page, redirects) | Before every publish, in CI ("Publish docs build"); by hand to look at the result | `bun run pack:docs` | `pack-docs.test.mjs` | @@ -35,13 +36,14 @@ run and change one without reading the others first: | `../router/dev-server.mjs` | Shows pelican.dev as one site on your machine (docs from `out/`, the rest from a local Hub) | By hand | `bun run dev:site` | `router/dev-server.test.mjs` | | `../router/worker.mjs` | The Cloudflare Worker option for later (not deployed) | Not deployed | see `router/README.md` | `router/worker.test.mjs` | -`bun run build` runs the checks around Next.js: `prebuild` runs `check-content` and `sync-eggs` -(`--if-online`), and `postbuild` runs `check-paths` and `check-links`. +`bun run build` runs the checks around Next.js: `prebuild` runs `check-content`, `sync-eggs` +(`--if-online`) and `sync-release`, and `postbuild` runs `check-paths` and `check-links`. **The build changes tracked files.** `sync-eggs` refreshes the egg data, so after `bun run build` you may see changes in `data/eggs.json`, `public/data/eggs/`, `public/img/eggs/` and `public/img/games/`. Commit -them only when a pull request is about the egg data. Otherwise leave them out -(`git restore data public/data public/img/eggs public/img/games`). +them only when a pull request is about the egg data. `sync-release` writes the latest release into +`data/release.json`; in git that file holds no release (the typed values in `lib/home-data.ts` apply), so +never commit it. Leave them out with `git restore data public/data public/img/eggs public/img/games`. ## Before a pull request diff --git a/scripts/sync-release.mjs b/scripts/sync-release.mjs new file mode 100644 index 00000000..ea594d94 --- /dev/null +++ b/scripts/sync-release.mjs @@ -0,0 +1,130 @@ +#!/usr/bin/env bun +/** + * Reads the latest Pelican Panel release from GitHub, for the homepage and llms.txt. + * + * When: before every build (prebuild); by hand to see what the build will use + * Writes: data/release.json + * Run: bun run sync:release (or: bun scripts/sync-release.mjs) + * Tests: bun test scripts/sync-release.test.mjs (with a stubbed fetch, no network) + * + * Asks the GitHub API for pelican/panel's last 10 releases and takes the newest published one + * (prereleases count, drafts don't): its version (the tag without the leading `v`), the day it + * was published ("19 November 2026") and its page. lib/home-data.ts reads data/release.json and + * uses its typed values for anything the file doesn't have. + * + * It never fails or holds up the build: each request times out after 5 seconds and is tried at + * most twice. On any failure (no network, rate limit, an error status, an answer that isn't a + * list of releases) it prints one line and writes the file as it is in git, with no release in + * it, so the build uses home-data.ts's typed values. + * + * Env: GITHUB_TOKEN (optional; CI sets it, it raises the rate limit), GITHUB_API (default + * https://api.github.com; point it somewhere unreachable to try the fallback). + */ +import { join } from 'node:path'; + +export const REPO = 'pelican/panel'; +export const OUT = join(import.meta.dir, '..', 'data', 'release.json'); +export const TIMEOUT_MS = 5000; + +/** What data/release.json holds when there is no live release (as committed in git). */ +export const FALLBACK = { + note: 'Written by scripts/sync-release.mjs before each build. Empty here: lib/home-data.ts uses its typed values.', +}; + +/** "2026-11-19T18:47:34Z" → "19 November 2026" (the day in UTC, like home-data.ts's dates). */ +export function formatDate(iso) { + return new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' }).format( + new Date(iso), + ); +} + +/** + * The newest published release in a GitHub releases list: drafts skipped, prereleases kept, + * newest by published_at. Throws if the list holds none, or isn't a list of releases. + */ +export function pickRelease(releases) { + if (!Array.isArray(releases)) throw new Error('the answer is not a list of releases'); + const published = releases + .filter((r) => r && !r.draft && typeof r.published_at === 'string' && !Number.isNaN(Date.parse(r.published_at))) + .sort((a, b) => Date.parse(b.published_at) - Date.parse(a.published_at)); + const latest = published[0]; + if (!latest) throw new Error('no published release'); + const version = String(latest.tag_name ?? '').replace(/^v/, ''); + // It ends up in llms.txt and on the homepage: only a plain version is taken. + if (!/^\d+\.\d+\.\d+[0-9A-Za-z.+-]*$/.test(version)) throw new Error(`unexpected tag ${JSON.stringify(latest.tag_name)}`); + const url = String(latest.html_url ?? ''); + if (!url.startsWith(`https://github.com/${REPO}/releases/`)) throw new Error(`unexpected release URL ${JSON.stringify(url)}`); + return { version, released: formatDate(latest.published_at), url, publishedAt: latest.published_at }; +} + +/** A failure worth one more try: the network, a timeout or a 5xx (not a rate limit or bad data). */ +class RetryableError extends Error {} + +/** + * The latest release from the GitHub API, or null (with one line on `warn`) on any failure. + * `fetchFn`, `api` and `token` are parameters so the tests can stub them. + */ +export async function latestRelease({ + fetchFn = fetch, + api = 'https://api.github.com', + token, + timeoutMs = TIMEOUT_MS, + retryDelayMs = 500, + warn = console.warn, +} = {}) { + const url = `${api.replace(/\/$/, '')}/repos/${REPO}/releases?per_page=10`; + const headers = { + Accept: 'application/vnd.github+json', + 'X-GitHub-Api-Version': '2022-11-28', + 'User-Agent': 'pelican-docs-build', + ...(token ? { Authorization: `Bearer ${token}` } : {}), + }; + + const once = async () => { + let res; + try { + res = await fetchFn(url, { headers, signal: AbortSignal.timeout(timeoutMs) }); + } catch (error) { + throw new RetryableError(error?.message ?? String(error)); + } + if (res.status >= 500) throw new RetryableError(`${res.status} from GitHub`); + if (!res.ok) throw new Error(`${res.status} from GitHub${res.status === 403 || res.status === 429 ? ' (rate limited?)' : ''}`); + let body; + try { + body = await res.json(); + } catch { + throw new Error('GitHub answered with something that is not JSON'); + } + return pickRelease(body); + }; + + try { + try { + return await once(); + } catch (error) { + if (!(error instanceof RetryableError)) throw error; + await Bun.sleep(retryDelayMs); + return await once(); + } + } catch (error) { + warn(`release: could not read the latest ${REPO} release (${error?.message ?? error}); using the typed version in lib/home-data.ts`); + return null; + } +} + +async function main() { + const release = await latestRelease({ + api: process.env.GITHUB_API || undefined, + token: process.env.GITHUB_TOKEN || undefined, + }); + await Bun.write(OUT, `${JSON.stringify(release ?? FALLBACK, null, 2)}\n`); + if (release) console.log(`release: ${REPO} ${release.version}, ${release.released} → data/release.json`); +} + +if (import.meta.main) { + main().catch((error) => { + // Only writing the file can get here: that is a real problem, so it fails the build. + console.error(error); + process.exit(1); + }); +} diff --git a/scripts/sync-release.test.mjs b/scripts/sync-release.test.mjs new file mode 100644 index 00000000..32d525b8 --- /dev/null +++ b/scripts/sync-release.test.mjs @@ -0,0 +1,169 @@ +// bun test scripts/sync-release.test.mjs (all tests: bun test) +// Which release sync-release picks (drafts skipped, prereleases kept, newest first, `v` stripped) +// and that every failure falls back to home-data.ts's typed values. fetch is stubbed: no network. +import { describe, expect, test } from 'bun:test'; +import { formatDate, latestRelease, pickRelease } from './sync-release.mjs'; + +const rel = (tag, publishedAt, extra = {}) => ({ + tag_name: tag, + published_at: publishedAt, + html_url: `https://github.com/pelican/panel/releases/tag/${tag}`, + draft: false, + prerelease: false, + ...extra, +}); + +describe('pickRelease', () => { + test('takes the newest by published date, whatever order the list is in', () => { + const picked = pickRelease([ + rel('v1.0.0-rc.3', '2026-11-14T17:04:30Z'), + rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z'), + rel('v1.0.0-rc.2', '2026-10-22T16:29:49Z'), + ]); + expect(picked).toEqual({ + version: '1.0.0-rc.4', + released: '19 November 2026', + url: 'https://github.com/pelican/panel/releases/tag/v1.0.0-rc.4', + publishedAt: '2026-11-19T18:47:34Z', + }); + }); + + test('skips drafts, even newer ones', () => { + const picked = pickRelease([ + rel('v1.0.0', null, { draft: true }), + rel('v1.0.1', '2026-12-01T00:00:00Z', { draft: true }), + rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z'), + ]); + expect(picked.version).toBe('1.0.0-rc.4'); + }); + + test('keeps prereleases', () => { + const picked = pickRelease([ + rel('v1.0.0-rc.5', '2026-11-25T10:00:00Z', { prerelease: true }), + rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z'), + ]); + expect(picked.version).toBe('1.0.0-rc.5'); + }); + + test('strips only a leading v', () => { + expect(pickRelease([rel('v1.2.3', '2026-11-19T00:00:00Z')]).version).toBe('1.2.3'); + expect(pickRelease([rel('1.2.3', '2026-11-19T00:00:00Z')]).version).toBe('1.2.3'); + }); + + test('throws on anything it should not trust', () => { + expect(() => pickRelease({ message: 'API rate limit exceeded' })).toThrow('not a list'); + expect(() => pickRelease([])).toThrow('no published release'); + expect(() => pickRelease([rel('v1.0.0', null, { draft: true })])).toThrow('no published release'); + expect(() => pickRelease([rel('nightly ', '2026-11-19T00:00:00Z')])).toThrow('unexpected tag'); + expect(() => + pickRelease([rel('v1.0.0', '2026-11-19T00:00:00Z', { html_url: 'https://example.com/x' })]), + ).toThrow('unexpected release URL'); + }); +}); + +test('formatDate gives the day in UTC, like home-data.ts', () => { + expect(formatDate('2026-10-22T16:29:49Z')).toBe('22 October 2026'); + expect(formatDate('2026-11-30T23:59:59Z')).toBe('30 November 2026'); +}); + +describe('latestRelease', () => { + const json = (body, status = 200) => + new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } }); + const collect = () => { + const lines = []; + return { lines, warn: (line) => lines.push(line) }; + }; + + test('asks GitHub for the last 10 releases, with the token when there is one', async () => { + const calls = []; + const fetchFn = async (url, init) => { + calls.push({ url, init }); + return json([rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z')]); + }; + const release = await latestRelease({ fetchFn, token: 'tkn', warn: () => {} }); + expect(release.version).toBe('1.0.0-rc.4'); + expect(calls).toHaveLength(1); + expect(calls[0].url).toBe('https://api.github.com/repos/pelican/panel/releases?per_page=10'); + expect(calls[0].init.headers.Authorization).toBe('Bearer tkn'); + expect(calls[0].init.signal).toBeInstanceOf(AbortSignal); + }); + + test('sends no Authorization header without a token', async () => { + let headers; + await latestRelease({ + fetchFn: async (_url, init) => { + headers = init.headers; + return json([rel('v1.0.0', '2026-11-19T00:00:00Z')]); + }, + warn: () => {}, + }); + expect(headers.Authorization).toBeUndefined(); + }); + + test('tries a network failure once more, then falls back with one line', async () => { + let calls = 0; + const { lines, warn } = collect(); + const release = await latestRelease({ + fetchFn: async () => { + calls++; + throw new Error('ECONNRESET'); + }, + retryDelayMs: 0, + warn, + }); + expect(release).toBeNull(); + expect(calls).toBe(2); + expect(lines).toHaveLength(1); + expect(lines[0]).toContain('ECONNRESET'); + }); + + test('uses the retry when it works', async () => { + let calls = 0; + const release = await latestRelease({ + fetchFn: async () => (++calls === 1 ? json({}, 502) : json([rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z')])), + retryDelayMs: 0, + warn: () => {}, + }); + expect(calls).toBe(2); + expect(release.version).toBe('1.0.0-rc.4'); + }); + + test('a rate limit, bad JSON or no releases fall back at once, without a retry', async () => { + for (const answer of [ + () => json({ message: 'API rate limit exceeded' }, 403), + () => new Response('oops', { status: 200 }), + () => json([]), + () => json({ message: 'Not Found' }), + ]) { + let calls = 0; + const { lines, warn } = collect(); + const release = await latestRelease({ + fetchFn: async () => { + calls++; + return answer(); + }, + retryDelayMs: 0, + warn, + }); + expect(release).toBeNull(); + expect(calls).toBe(1); + expect(lines).toHaveLength(1); + } + }); + + test('a request that hangs is cut off by the timeout', async () => { + const { lines, warn } = collect(); + const started = Date.now(); + const release = await latestRelease({ + // Like fetch: rejects when the signal aborts. + fetchFn: (_url, { signal }) => + new Promise((_resolve, reject) => signal.addEventListener('abort', () => reject(signal.reason))), + timeoutMs: 50, + retryDelayMs: 0, + warn, + }); + expect(release).toBeNull(); + expect(Date.now() - started).toBeLessThan(2000); + expect(lines).toHaveLength(1); + }); +}); From aca11a8eb6d44c0a4389856b3ad03b8cf0b7668d Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:05:38 +0200 Subject: [PATCH 2/5] feat(home): take the Panel version for llms.txt and the homepage from GitHub home-data reads data/release.json and keeps its typed rc.2 values as the fallback. The announcement bar keeps its rc.2 sentence only for rc.2. --- components/home/sections.tsx | 4 ++-- components/home/site-header.tsx | 12 ++++++++++-- lib/home-data.ts | 21 ++++++++++++++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/components/home/sections.tsx b/components/home/sections.tsx index 25c51c03..10d21a3e 100644 --- a/components/home/sections.tsx +++ b/components/home/sections.tsx @@ -300,7 +300,7 @@ export function ActivitySection() {

Latest release:{' '} - + {project.version}, {project.released}

@@ -508,7 +508,7 @@ export function SiteFooterNav() {

© 2024–{new Date().getFullYear()} Pelican · {project.license} · Latest release{' '} - {project.version}, {project.released} + {project.version}, {project.released}

diff --git a/components/home/site-header.tsx b/components/home/site-header.tsx index d47412df..2cc1becc 100644 --- a/components/home/site-header.tsx +++ b/components/home/site-header.tsx @@ -5,8 +5,16 @@ import { links } from '@/lib/links'; import { project } from '@/lib/home-data'; import { MobileMenu } from './mobile-menu'; +/** + * What the announcement bar says about a release. The version comes from GitHub at build time + * (lib/home-data.ts), so a newer release than the one written about here gets a plain line. + */ +const announced = { version: '1.0.0-rc.2', text: 'A crashing plugin can no longer take the panel down, and more.' }; + /** Announcement bar plus the sky-blue nav from the V12 "B v3" board. */ export function SiteHeader() { + const text = + project.version === announced.version ? announced.text : `The latest Panel release, out ${project.released}.`; return ( <> @@ -14,8 +22,8 @@ export function SiteHeader() {
{project.version.replace('1.0.0-', '')} - A crashing plugin can no longer take the panel down, and more. - + {text} + Read the release →
diff --git a/lib/home-data.ts b/lib/home-data.ts index cd61e30a..0a745122 100644 --- a/lib/home-data.ts +++ b/lib/home-data.ts @@ -1,13 +1,32 @@ +import releaseJson from '@/data/release.json'; + /** * Facts the homepage shows. Everything here was read from a real source on * 2 November 2026; the source is noted beside each block. Update it when the * numbers move (a new release, a new plugin count) rather than guessing. */ -export const project = { +/** + * The latest Panel release, read from GitHub before each build by scripts/sync-release.mjs + * (data/release.json). These typed values are the fallback for when it couldn't (no network, + * a rate limit); in git the file holds no release, so they also apply until the first build. + */ +const typedRelease = { // github.com/pelican/panel/releases version: '1.0.0-rc.2', released: '22 October 2026', + url: 'https://github.com/pelican/panel/releases/tag/v1.0.0-rc.2', +}; +const live = releaseJson as { version?: string; released?: string; url?: string }; +export const release = + live.version && live.released && live.url + ? { version: live.version, released: live.released, url: live.url } + : typedRelease; + +export const project = { + version: release.version, + released: release.released, + releaseUrl: release.url, // github.com/pelican/panel (stargazers, contributors on the default branch) stars: 2419, contributors: 235, From 9b6187d35f89a2dc044995d0fba20e721651df78 Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:05:38 +0200 Subject: [PATCH 3/5] ci(publish): rebuild the docs daily so a new Panel release shows within a day Adds a schedule that publishes the same branches a push does, passes GITHUB_TOKEN to the build, and names the built branch and commit in BUILD.json (BUILD_SHA/BUILD_BRANCH) since the daily run starts on main. --- .github/workflows/publish-docs.yml | 65 ++++++++++++++++++++++++++---- scripts/pack-docs.mjs | 6 ++- scripts/pack-docs.test.mjs | 19 +++++++++ 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 76cc3575..91327a0d 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -8,6 +8,11 @@ # feat/fumadocs-next -> preview/docs-under-docs (hub-preview.pelican.dev) # # The last step asks that Hub to install it right away; it also checks every 10 minutes. +# +# It also runs every day, so the latest Panel release (scripts/sync-release.mjs: the homepage and +# llms.txt) is on pelican.dev within a day without a push. That run builds and publishes each +# branch above that exists. GitHub runs schedules only from the default branch (main), so the +# daily run starts once this file is on main. name: 'Publish docs build' on: workflow_dispatch: @@ -15,22 +20,62 @@ on: branches: - 'main' - 'feat/fumadocs-next' - -concurrency: - group: publish-docs-${{ github.ref_name }} - cancel-in-progress: true + schedule: + - cron: '23 5 * * *' permissions: contents: write jobs: + branches: + name: 'Pick the branches to publish' + runs-on: ubuntu-latest + outputs: + list: ${{ steps.pick.outputs.list }} + steps: + # A push or a manual run publishes its own branch. The daily run publishes the same branches + # a push would (the list under on.push), skipping any that no longer exist. + - name: 'Pick the branches' + id: pick + env: + EVENT: ${{ github.event_name }} + REPO_URL: ${{ github.server_url }}/${{ github.repository }}.git + run: | + if [ "$EVENT" = "schedule" ]; then + found=() + for branch in main feat/fumadocs-next; do + if git ls-remote --exit-code --heads "$REPO_URL" "refs/heads/$branch" > /dev/null; then + found+=("$branch") + fi + done + list=$(printf '%s\n' "${found[@]}" | jq -Rnc '[inputs]') + else + list=$(jq -nc --arg b "$GITHUB_REF_NAME" '[$b]') + fi + echo "list=$list" >> "$GITHUB_OUTPUT" + echo "Publishing: $list" + publish: - name: 'Build and publish /docs for the Hub' + name: 'Build and publish /docs for the Hub (${{ matrix.branch }})' + needs: branches runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + branch: ${{ fromJSON(needs.branches.outputs.list) }} + # One publish per branch at a time; a newer run (a push, or the daily run) replaces an older one. + concurrency: + group: publish-docs-${{ matrix.branch }} + cancel-in-progress: true + env: + # The branch built, and pack-docs' BUILD.json names it (the daily run starts on main). + BUILD_BRANCH: ${{ matrix.branch }} steps: - name: 'Checkout' uses: actions/checkout@v7 with: + # A push builds its own commit; the daily run builds each branch's latest commit. + ref: ${{ github.event_name == 'schedule' && matrix.branch || github.sha }} # The whole history: each page's "Last updated", sitemap date and JSON-LD dates come # from git (lastModified in source.config.ts). A shallow clone gives every page the same date. fetch-depth: 0 @@ -63,16 +108,22 @@ jobs: run: bun run typecheck # prebuild checks the content, postbuild checks every file lands where it should and every link works. + # GITHUB_TOKEN: sync-release reads the latest Panel release with it (a higher rate limit). - name: 'Build' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: bun run build + - name: 'Name the commit built' + run: echo "BUILD_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV" + - name: 'Pack the docs for the Hub' run: bun run pack:docs dist-docs - name: 'Pick the target' id: target run: | - if [ "$GITHUB_REF_NAME" = "main" ]; then + if [ "$BUILD_BRANCH" = "main" ]; then echo "branch=docs-build" >> "$GITHUB_OUTPUT" echo "refresh=https://pelican.dev/docs/_refresh" >> "$GITHUB_OUTPUT" else @@ -90,7 +141,7 @@ jobs: git config user.name 'github-actions[bot]' git config user.email '41898282+github-actions[bot]@users.noreply.github.com' git add -A - git commit -q -m "Docs build of ${GITHUB_SHA::10} (${GITHUB_REF_NAME})" + git commit -q -m "Docs build of ${BUILD_SHA::10} (${BUILD_BRANCH})" git push -q -f "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "HEAD:refs/heads/${TARGET}" # Not fatal: the Hub also checks on its own every 10 minutes and on the first visit. Until diff --git a/scripts/pack-docs.mjs b/scripts/pack-docs.mjs index ae4c3937..22ed8e84 100644 --- a/scripts/pack-docs.mjs +++ b/scripts/pack-docs.mjs @@ -62,9 +62,11 @@ export async function pack(folder, { src = 'out', toml = 'netlify.toml' } = {}) await Bun.write(join(folder, 'redirects.json'), `${JSON.stringify(redirects, null, 2)}\n`); + // BUILD_SHA/BUILD_BRANCH: the commit and branch built, when they aren't the ones that started + // the run (the daily publish starts on main and also builds feat/fumadocs-next). const build = { - sha: process.env.GITHUB_SHA ?? 'local', - branch: process.env.GITHUB_REF_NAME ?? 'local', + sha: process.env.BUILD_SHA || process.env.GITHUB_SHA || 'local', + branch: process.env.BUILD_BRANCH || process.env.GITHUB_REF_NAME || 'local', built_at: new Date().toISOString().replace(/\.\d+Z$/, 'Z'), }; await Bun.write(join(folder, 'BUILD.json'), `${JSON.stringify(build)}\n`); diff --git a/scripts/pack-docs.test.mjs b/scripts/pack-docs.test.mjs index 8cbc27d1..d992164d 100644 --- a/scripts/pack-docs.test.mjs +++ b/scripts/pack-docs.test.mjs @@ -97,6 +97,25 @@ describe('pack', () => { expect(Object.keys(JSON.parse(readFileSync(join(folder, 'BUILD.json'), 'utf8')))).toEqual(['sha', 'branch', 'built_at']); }); + test('BUILD.json names the commit and branch built, BUILD_SHA/BUILD_BRANCH first', async () => { + const saved = { ...process.env }; + try { + Object.assign(process.env, { GITHUB_SHA: 'aaa', GITHUB_REF_NAME: 'main', BUILD_SHA: 'bbb', BUILD_BRANCH: 'feat/fumadocs-next' }); + const folder = join(sandbox, 'dist-build-env'); + await pack(folder, { src, toml }); + expect(JSON.parse(readFileSync(join(folder, 'BUILD.json'), 'utf8'))).toMatchObject({ sha: 'bbb', branch: 'feat/fumadocs-next' }); + delete process.env.BUILD_SHA; + delete process.env.BUILD_BRANCH; + await pack(folder, { src, toml }); + expect(JSON.parse(readFileSync(join(folder, 'BUILD.json'), 'utf8'))).toMatchObject({ sha: 'aaa', branch: 'main' }); + } finally { + for (const key of ['GITHUB_SHA', 'GITHUB_REF_NAME', 'BUILD_SHA', 'BUILD_BRANCH']) { + if (key in saved) process.env[key] = saved[key]; + else delete process.env[key]; + } + } + }); + test('refuses an output folder that isn\'t a dist folder, before deleting anything', async () => { await expect(pack(src, { src, toml })).rejects.toThrow('must start with "dist"'); await expect(pack(sandbox, { src, toml })).rejects.toThrow('must start with "dist"'); From 91b8b2495d450b182553e7f624609732686cc618 Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:15:02 +0200 Subject: [PATCH 4/5] refactor(scripts): make sync-release short enough to read at a glance One fetch with a 5-second timeout, no retry (the build already falls back and the docs rebuild daily), no custom error class or extra checks. Tests cover the release picking only. 130 lines down to 50. --- data/release.json | 4 +- scripts/README.md | 2 +- scripts/sync-release.mjs | 148 +++++++-------------------- scripts/sync-release.test.mjs | 181 +++++----------------------------- 4 files changed, 62 insertions(+), 273 deletions(-) diff --git a/data/release.json b/data/release.json index 9b14b0c3..0967ef42 100644 --- a/data/release.json +++ b/data/release.json @@ -1,3 +1 @@ -{ - "note": "Written by scripts/sync-release.mjs before each build. Empty here: lib/home-data.ts uses its typed values." -} +{} diff --git a/scripts/README.md b/scripts/README.md index c448d0e3..c6c27f08 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -27,7 +27,7 @@ run and change one without reading the others first: | --- | --- | --- | --- | --- | | `check-content.mjs` | Fails if a page in `content/` could run code (MDX compiles pages to JavaScript) | Before every build, and in CI | `bun run check:content` | `check-content.test.mjs` | | `sync-eggs.mjs` | Refreshes the egg data for the interim `/eggs` page and the homepage games strip. Uses the network and rewrites `data/eggs.json`, `public/data/eggs/`, `public/img/eggs/` and `public/img/games/` | Before every build (`--if-online`: no network keeps the saved data; a bug still fails); by hand | `bun run sync:eggs` | `sync-eggs.test.mjs` | -| `sync-release.mjs` | Reads the latest Pelican Panel release from GitHub (version, date, link) for the homepage and `llms.txt`, into `data/release.json`. Uses the network (`GITHUB_TOKEN` if set); on any failure it prints one line and the build uses the typed values in `lib/home-data.ts` | Before every build (never fails it: 5 s timeout, one retry); by hand | `bun run sync:release` | `sync-release.test.mjs` | +| `sync-release.mjs` | Reads the latest Pelican Panel release from GitHub (version, date, link) for the homepage and `llms.txt`, into `data/release.json`. Uses the network (`GITHUB_TOKEN` if set); on any failure it prints one line and the build uses the typed values in `lib/home-data.ts` | Before every build (never fails it: 5 s timeout); by hand | `bun run sync:release` | `sync-release.test.mjs` | | `check-paths.mjs` | Fails if the build puts a file where pelican.dev won't serve it from this build, misses a root file, or a docs page loads something from outside `/docs/` | After every build, and in CI | `bun run check:paths` | `check-paths.test.mjs` | | `check-links.mjs` | Fails if a link on a docs page goes to a docs page, file or `#anchor` that isn't in the build (links to the Hub and other sites aren't checked) | After every build, and in CI | `bun run check:links` | `check-links.test.mjs` | | `pack-docs.mjs` | Packs `out/` into the folder the Hub serves on pelican.dev (docs, root files, 404 page, redirects) | Before every publish, in CI ("Publish docs build"); by hand to look at the result | `bun run pack:docs` | `pack-docs.test.mjs` | diff --git a/scripts/sync-release.mjs b/scripts/sync-release.mjs index ea594d94..e7ab2e98 100644 --- a/scripts/sync-release.mjs +++ b/scripts/sync-release.mjs @@ -2,129 +2,49 @@ /** * Reads the latest Pelican Panel release from GitHub, for the homepage and llms.txt. * - * When: before every build (prebuild); by hand to see what the build will use - * Writes: data/release.json - * Run: bun run sync:release (or: bun scripts/sync-release.mjs) - * Tests: bun test scripts/sync-release.test.mjs (with a stubbed fetch, no network) + * When: before every build (prebuild); by hand to see what the build will use + * Writes: data/release.json ({} when GitHub can't be reached: the typed values in lib/home-data.ts are used) + * Run: bun run sync:release + * Tests: bun test scripts/sync-release.test.mjs * - * Asks the GitHub API for pelican/panel's last 10 releases and takes the newest published one - * (prereleases count, drafts don't): its version (the tag without the leading `v`), the day it - * was published ("19 November 2026") and its page. lib/home-data.ts reads data/release.json and - * uses its typed values for anything the file doesn't have. - * - * It never fails or holds up the build: each request times out after 5 seconds and is tried at - * most twice. On any failure (no network, rate limit, an error status, an answer that isn't a - * list of releases) it prints one line and writes the file as it is in git, with no release in - * it, so the build uses home-data.ts's typed values. - * - * Env: GITHUB_TOKEN (optional; CI sets it, it raises the rate limit), GITHUB_API (default - * https://api.github.com; point it somewhere unreachable to try the fallback). + * Never fails the build: no network, a rate limit or a 5-second timeout just means the fallback. + * GITHUB_TOKEN, when set (CI sets it), raises GitHub's rate limit. */ import { join } from 'node:path'; -export const REPO = 'pelican/panel'; -export const OUT = join(import.meta.dir, '..', 'data', 'release.json'); -export const TIMEOUT_MS = 5000; - -/** What data/release.json holds when there is no live release (as committed in git). */ -export const FALLBACK = { - note: 'Written by scripts/sync-release.mjs before each build. Empty here: lib/home-data.ts uses its typed values.', -}; +const OUT = join(import.meta.dir, '..', 'data', 'release.json'); -/** "2026-11-19T18:47:34Z" → "19 November 2026" (the day in UTC, like home-data.ts's dates). */ -export function formatDate(iso) { - return new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' }).format( - new Date(iso), - ); -} - -/** - * The newest published release in a GitHub releases list: drafts skipped, prereleases kept, - * newest by published_at. Throws if the list holds none, or isn't a list of releases. - */ +/** The newest published release (drafts skipped, prereleases kept), or null. */ export function pickRelease(releases) { - if (!Array.isArray(releases)) throw new Error('the answer is not a list of releases'); - const published = releases - .filter((r) => r && !r.draft && typeof r.published_at === 'string' && !Number.isNaN(Date.parse(r.published_at))) - .sort((a, b) => Date.parse(b.published_at) - Date.parse(a.published_at)); - const latest = published[0]; - if (!latest) throw new Error('no published release'); - const version = String(latest.tag_name ?? '').replace(/^v/, ''); - // It ends up in llms.txt and on the homepage: only a plain version is taken. - if (!/^\d+\.\d+\.\d+[0-9A-Za-z.+-]*$/.test(version)) throw new Error(`unexpected tag ${JSON.stringify(latest.tag_name)}`); - const url = String(latest.html_url ?? ''); - if (!url.startsWith(`https://github.com/${REPO}/releases/`)) throw new Error(`unexpected release URL ${JSON.stringify(url)}`); - return { version, released: formatDate(latest.published_at), url, publishedAt: latest.published_at }; -} - -/** A failure worth one more try: the network, a timeout or a 5xx (not a rate limit or bad data). */ -class RetryableError extends Error {} - -/** - * The latest release from the GitHub API, or null (with one line on `warn`) on any failure. - * `fetchFn`, `api` and `token` are parameters so the tests can stub them. - */ -export async function latestRelease({ - fetchFn = fetch, - api = 'https://api.github.com', - token, - timeoutMs = TIMEOUT_MS, - retryDelayMs = 500, - warn = console.warn, -} = {}) { - const url = `${api.replace(/\/$/, '')}/repos/${REPO}/releases?per_page=10`; - const headers = { - Accept: 'application/vnd.github+json', - 'X-GitHub-Api-Version': '2022-11-28', - 'User-Agent': 'pelican-docs-build', - ...(token ? { Authorization: `Bearer ${token}` } : {}), - }; - - const once = async () => { - let res; - try { - res = await fetchFn(url, { headers, signal: AbortSignal.timeout(timeoutMs) }); - } catch (error) { - throw new RetryableError(error?.message ?? String(error)); - } - if (res.status >= 500) throw new RetryableError(`${res.status} from GitHub`); - if (!res.ok) throw new Error(`${res.status} from GitHub${res.status === 403 || res.status === 429 ? ' (rate limited?)' : ''}`); - let body; - try { - body = await res.json(); - } catch { - throw new Error('GitHub answered with something that is not JSON'); - } - return pickRelease(body); + const latest = releases + .filter((release) => !release.draft && release.published_at) + .sort((a, b) => Date.parse(b.published_at) - Date.parse(a.published_at))[0]; + if (!latest) return null; + + return { + version: latest.tag_name.replace(/^v/, ''), // "v1.0.0-rc.4" → "1.0.0-rc.4" + released: new Date(latest.published_at).toLocaleDateString('en-GB', { + day: 'numeric', + month: 'long', + year: 'numeric', + timeZone: 'UTC', + }), + url: latest.html_url, }; +} +if (import.meta.main) { + let release = null; try { - try { - return await once(); - } catch (error) { - if (!(error instanceof RetryableError)) throw error; - await Bun.sleep(retryDelayMs); - return await once(); - } + const response = await fetch('https://api.github.com/repos/pelican/panel/releases?per_page=10', { + headers: process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}, + signal: AbortSignal.timeout(5000), + }); + if (!response.ok) throw new Error(`GitHub answered ${response.status}`); + release = pickRelease(await response.json()); } catch (error) { - warn(`release: could not read the latest ${REPO} release (${error?.message ?? error}); using the typed version in lib/home-data.ts`); - return null; + console.warn(`release: using the typed version in lib/home-data.ts (${error.message})`); } -} - -async function main() { - const release = await latestRelease({ - api: process.env.GITHUB_API || undefined, - token: process.env.GITHUB_TOKEN || undefined, - }); - await Bun.write(OUT, `${JSON.stringify(release ?? FALLBACK, null, 2)}\n`); - if (release) console.log(`release: ${REPO} ${release.version}, ${release.released} → data/release.json`); -} - -if (import.meta.main) { - main().catch((error) => { - // Only writing the file can get here: that is a real problem, so it fails the build. - console.error(error); - process.exit(1); - }); + await Bun.write(OUT, `${JSON.stringify(release ?? {}, null, 2)}\n`); + if (release) console.log(`release: pelican/panel ${release.version}, ${release.released}`); } diff --git a/scripts/sync-release.test.mjs b/scripts/sync-release.test.mjs index 32d525b8..24269cdf 100644 --- a/scripts/sync-release.test.mjs +++ b/scripts/sync-release.test.mjs @@ -1,169 +1,40 @@ // bun test scripts/sync-release.test.mjs (all tests: bun test) -// Which release sync-release picks (drafts skipped, prereleases kept, newest first, `v` stripped) -// and that every failure falls back to home-data.ts's typed values. fetch is stubbed: no network. -import { describe, expect, test } from 'bun:test'; -import { formatDate, latestRelease, pickRelease } from './sync-release.mjs'; +// Which release sync-release.mjs picks from GitHub's list. No network: the list is written here. +import { expect, test } from 'bun:test'; +import { pickRelease } from './sync-release.mjs'; -const rel = (tag, publishedAt, extra = {}) => ({ +const release = (tag, publishedAt, draft = false) => ({ tag_name: tag, published_at: publishedAt, html_url: `https://github.com/pelican/panel/releases/tag/${tag}`, - draft: false, - prerelease: false, - ...extra, + draft, }); -describe('pickRelease', () => { - test('takes the newest by published date, whatever order the list is in', () => { - const picked = pickRelease([ - rel('v1.0.0-rc.3', '2026-11-14T17:04:30Z'), - rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z'), - rel('v1.0.0-rc.2', '2026-10-22T16:29:49Z'), - ]); - expect(picked).toEqual({ - version: '1.0.0-rc.4', - released: '19 November 2026', - url: 'https://github.com/pelican/panel/releases/tag/v1.0.0-rc.4', - publishedAt: '2026-11-19T18:47:34Z', - }); - }); - - test('skips drafts, even newer ones', () => { - const picked = pickRelease([ - rel('v1.0.0', null, { draft: true }), - rel('v1.0.1', '2026-12-01T00:00:00Z', { draft: true }), - rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z'), - ]); - expect(picked.version).toBe('1.0.0-rc.4'); - }); - - test('keeps prereleases', () => { - const picked = pickRelease([ - rel('v1.0.0-rc.5', '2026-11-25T10:00:00Z', { prerelease: true }), - rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z'), - ]); - expect(picked.version).toBe('1.0.0-rc.5'); - }); - - test('strips only a leading v', () => { - expect(pickRelease([rel('v1.2.3', '2026-11-19T00:00:00Z')]).version).toBe('1.2.3'); - expect(pickRelease([rel('1.2.3', '2026-11-19T00:00:00Z')]).version).toBe('1.2.3'); - }); - - test('throws on anything it should not trust', () => { - expect(() => pickRelease({ message: 'API rate limit exceeded' })).toThrow('not a list'); - expect(() => pickRelease([])).toThrow('no published release'); - expect(() => pickRelease([rel('v1.0.0', null, { draft: true })])).toThrow('no published release'); - expect(() => pickRelease([rel('nightly ', '2026-11-19T00:00:00Z')])).toThrow('unexpected tag'); - expect(() => - pickRelease([rel('v1.0.0', '2026-11-19T00:00:00Z', { html_url: 'https://example.com/x' })]), - ).toThrow('unexpected release URL'); +test('takes the newest release, whatever order GitHub lists them in', () => { + expect( + pickRelease([ + release('v1.0.0-rc.3', '2026-11-14T17:04:30Z'), + release('v1.0.0-rc.4', '2026-11-19T18:47:34Z'), + release('v1.0.0-rc.2', '2026-10-22T16:29:49Z'), + ]), + ).toEqual({ + version: '1.0.0-rc.4', + released: '19 November 2026', + url: 'https://github.com/pelican/panel/releases/tag/v1.0.0-rc.4', }); }); -test('formatDate gives the day in UTC, like home-data.ts', () => { - expect(formatDate('2026-10-22T16:29:49Z')).toBe('22 October 2026'); - expect(formatDate('2026-11-30T23:59:59Z')).toBe('30 November 2026'); +test('skips drafts, which have no publish date yet', () => { + expect(pickRelease([release('v1.0.1', null, true), release('v1.0.0-rc.4', '2026-11-19T18:47:34Z')]).version).toBe( + '1.0.0-rc.4', + ); }); -describe('latestRelease', () => { - const json = (body, status = 200) => - new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } }); - const collect = () => { - const lines = []; - return { lines, warn: (line) => lines.push(line) }; - }; - - test('asks GitHub for the last 10 releases, with the token when there is one', async () => { - const calls = []; - const fetchFn = async (url, init) => { - calls.push({ url, init }); - return json([rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z')]); - }; - const release = await latestRelease({ fetchFn, token: 'tkn', warn: () => {} }); - expect(release.version).toBe('1.0.0-rc.4'); - expect(calls).toHaveLength(1); - expect(calls[0].url).toBe('https://api.github.com/repos/pelican/panel/releases?per_page=10'); - expect(calls[0].init.headers.Authorization).toBe('Bearer tkn'); - expect(calls[0].init.signal).toBeInstanceOf(AbortSignal); - }); - - test('sends no Authorization header without a token', async () => { - let headers; - await latestRelease({ - fetchFn: async (_url, init) => { - headers = init.headers; - return json([rel('v1.0.0', '2026-11-19T00:00:00Z')]); - }, - warn: () => {}, - }); - expect(headers.Authorization).toBeUndefined(); - }); - - test('tries a network failure once more, then falls back with one line', async () => { - let calls = 0; - const { lines, warn } = collect(); - const release = await latestRelease({ - fetchFn: async () => { - calls++; - throw new Error('ECONNRESET'); - }, - retryDelayMs: 0, - warn, - }); - expect(release).toBeNull(); - expect(calls).toBe(2); - expect(lines).toHaveLength(1); - expect(lines[0]).toContain('ECONNRESET'); - }); - - test('uses the retry when it works', async () => { - let calls = 0; - const release = await latestRelease({ - fetchFn: async () => (++calls === 1 ? json({}, 502) : json([rel('v1.0.0-rc.4', '2026-11-19T18:47:34Z')])), - retryDelayMs: 0, - warn: () => {}, - }); - expect(calls).toBe(2); - expect(release.version).toBe('1.0.0-rc.4'); - }); - - test('a rate limit, bad JSON or no releases fall back at once, without a retry', async () => { - for (const answer of [ - () => json({ message: 'API rate limit exceeded' }, 403), - () => new Response('oops', { status: 200 }), - () => json([]), - () => json({ message: 'Not Found' }), - ]) { - let calls = 0; - const { lines, warn } = collect(); - const release = await latestRelease({ - fetchFn: async () => { - calls++; - return answer(); - }, - retryDelayMs: 0, - warn, - }); - expect(release).toBeNull(); - expect(calls).toBe(1); - expect(lines).toHaveLength(1); - } - }); +test('reads the date in UTC', () => { + expect(pickRelease([release('v1.0.0', '2026-11-19T23:30:00Z')]).released).toBe('19 November 2026'); +}); - test('a request that hangs is cut off by the timeout', async () => { - const { lines, warn } = collect(); - const started = Date.now(); - const release = await latestRelease({ - // Like fetch: rejects when the signal aborts. - fetchFn: (_url, { signal }) => - new Promise((_resolve, reject) => signal.addEventListener('abort', () => reject(signal.reason))), - timeoutMs: 50, - retryDelayMs: 0, - warn, - }); - expect(release).toBeNull(); - expect(Date.now() - started).toBeLessThan(2000); - expect(lines).toHaveLength(1); - }); +test('gives null when there is no published release', () => { + expect(pickRelease([])).toBeNull(); + expect(pickRelease([release('v1.0.1', null, true)])).toBeNull(); }); From 84231124480bb87de46fda635af74880d5f6e0eb Mon Sep 17 00:00:00 2001 From: "Alexandru Vlad (Scai)" <59282365+alexevladgabriel@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:21:55 +0200 Subject: [PATCH 5/5] ci(publish): just a daily schedule, no branch matrix The daily run only needs to rebuild pelican.dev, which a scheduled run on main already does like a push to main. Drops the branch-picking job, the matrix and the BUILD_SHA/BUILD_BRANCH plumbing in pack-docs. --- .github/workflows/publish-docs.yml | 64 +++++------------------------- scripts/pack-docs.mjs | 6 +-- scripts/pack-docs.test.mjs | 19 --------- 3 files changed, 12 insertions(+), 77 deletions(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 91327a0d..e981481c 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -8,11 +8,6 @@ # feat/fumadocs-next -> preview/docs-under-docs (hub-preview.pelican.dev) # # The last step asks that Hub to install it right away; it also checks every 10 minutes. -# -# It also runs every day, so the latest Panel release (scripts/sync-release.mjs: the homepage and -# llms.txt) is on pelican.dev within a day without a push. That run builds and publishes each -# branch above that exists. GitHub runs schedules only from the default branch (main), so the -# daily run starts once this file is on main. name: 'Publish docs build' on: workflow_dispatch: @@ -20,62 +15,26 @@ on: branches: - 'main' - 'feat/fumadocs-next' + # Daily, so a new Panel release (scripts/sync-release.mjs) reaches pelican.dev without a push. + # GitHub runs schedules from main only, so this rebuilds pelican.dev, like a push to main. schedule: - cron: '23 5 * * *' +concurrency: + group: publish-docs-${{ github.ref_name }} + cancel-in-progress: true + permissions: contents: write jobs: - branches: - name: 'Pick the branches to publish' - runs-on: ubuntu-latest - outputs: - list: ${{ steps.pick.outputs.list }} - steps: - # A push or a manual run publishes its own branch. The daily run publishes the same branches - # a push would (the list under on.push), skipping any that no longer exist. - - name: 'Pick the branches' - id: pick - env: - EVENT: ${{ github.event_name }} - REPO_URL: ${{ github.server_url }}/${{ github.repository }}.git - run: | - if [ "$EVENT" = "schedule" ]; then - found=() - for branch in main feat/fumadocs-next; do - if git ls-remote --exit-code --heads "$REPO_URL" "refs/heads/$branch" > /dev/null; then - found+=("$branch") - fi - done - list=$(printf '%s\n' "${found[@]}" | jq -Rnc '[inputs]') - else - list=$(jq -nc --arg b "$GITHUB_REF_NAME" '[$b]') - fi - echo "list=$list" >> "$GITHUB_OUTPUT" - echo "Publishing: $list" - publish: - name: 'Build and publish /docs for the Hub (${{ matrix.branch }})' - needs: branches + name: 'Build and publish /docs for the Hub' runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - branch: ${{ fromJSON(needs.branches.outputs.list) }} - # One publish per branch at a time; a newer run (a push, or the daily run) replaces an older one. - concurrency: - group: publish-docs-${{ matrix.branch }} - cancel-in-progress: true - env: - # The branch built, and pack-docs' BUILD.json names it (the daily run starts on main). - BUILD_BRANCH: ${{ matrix.branch }} steps: - name: 'Checkout' uses: actions/checkout@v7 with: - # A push builds its own commit; the daily run builds each branch's latest commit. - ref: ${{ github.event_name == 'schedule' && matrix.branch || github.sha }} # The whole history: each page's "Last updated", sitemap date and JSON-LD dates come # from git (lastModified in source.config.ts). A shallow clone gives every page the same date. fetch-depth: 0 @@ -108,22 +67,19 @@ jobs: run: bun run typecheck # prebuild checks the content, postbuild checks every file lands where it should and every link works. - # GITHUB_TOKEN: sync-release reads the latest Panel release with it (a higher rate limit). - name: 'Build' env: + # sync-release reads the latest Panel release with it (a higher rate limit). GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: bun run build - - name: 'Name the commit built' - run: echo "BUILD_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV" - - name: 'Pack the docs for the Hub' run: bun run pack:docs dist-docs - name: 'Pick the target' id: target run: | - if [ "$BUILD_BRANCH" = "main" ]; then + if [ "$GITHUB_REF_NAME" = "main" ]; then echo "branch=docs-build" >> "$GITHUB_OUTPUT" echo "refresh=https://pelican.dev/docs/_refresh" >> "$GITHUB_OUTPUT" else @@ -141,7 +97,7 @@ jobs: git config user.name 'github-actions[bot]' git config user.email '41898282+github-actions[bot]@users.noreply.github.com' git add -A - git commit -q -m "Docs build of ${BUILD_SHA::10} (${BUILD_BRANCH})" + git commit -q -m "Docs build of ${GITHUB_SHA::10} (${GITHUB_REF_NAME})" git push -q -f "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "HEAD:refs/heads/${TARGET}" # Not fatal: the Hub also checks on its own every 10 minutes and on the first visit. Until diff --git a/scripts/pack-docs.mjs b/scripts/pack-docs.mjs index 22ed8e84..ae4c3937 100644 --- a/scripts/pack-docs.mjs +++ b/scripts/pack-docs.mjs @@ -62,11 +62,9 @@ export async function pack(folder, { src = 'out', toml = 'netlify.toml' } = {}) await Bun.write(join(folder, 'redirects.json'), `${JSON.stringify(redirects, null, 2)}\n`); - // BUILD_SHA/BUILD_BRANCH: the commit and branch built, when they aren't the ones that started - // the run (the daily publish starts on main and also builds feat/fumadocs-next). const build = { - sha: process.env.BUILD_SHA || process.env.GITHUB_SHA || 'local', - branch: process.env.BUILD_BRANCH || process.env.GITHUB_REF_NAME || 'local', + sha: process.env.GITHUB_SHA ?? 'local', + branch: process.env.GITHUB_REF_NAME ?? 'local', built_at: new Date().toISOString().replace(/\.\d+Z$/, 'Z'), }; await Bun.write(join(folder, 'BUILD.json'), `${JSON.stringify(build)}\n`); diff --git a/scripts/pack-docs.test.mjs b/scripts/pack-docs.test.mjs index d992164d..8cbc27d1 100644 --- a/scripts/pack-docs.test.mjs +++ b/scripts/pack-docs.test.mjs @@ -97,25 +97,6 @@ describe('pack', () => { expect(Object.keys(JSON.parse(readFileSync(join(folder, 'BUILD.json'), 'utf8')))).toEqual(['sha', 'branch', 'built_at']); }); - test('BUILD.json names the commit and branch built, BUILD_SHA/BUILD_BRANCH first', async () => { - const saved = { ...process.env }; - try { - Object.assign(process.env, { GITHUB_SHA: 'aaa', GITHUB_REF_NAME: 'main', BUILD_SHA: 'bbb', BUILD_BRANCH: 'feat/fumadocs-next' }); - const folder = join(sandbox, 'dist-build-env'); - await pack(folder, { src, toml }); - expect(JSON.parse(readFileSync(join(folder, 'BUILD.json'), 'utf8'))).toMatchObject({ sha: 'bbb', branch: 'feat/fumadocs-next' }); - delete process.env.BUILD_SHA; - delete process.env.BUILD_BRANCH; - await pack(folder, { src, toml }); - expect(JSON.parse(readFileSync(join(folder, 'BUILD.json'), 'utf8'))).toMatchObject({ sha: 'aaa', branch: 'main' }); - } finally { - for (const key of ['GITHUB_SHA', 'GITHUB_REF_NAME', 'BUILD_SHA', 'BUILD_BRANCH']) { - if (key in saved) process.env[key] = saved[key]; - else delete process.env[key]; - } - } - }); - test('refuses an output folder that isn\'t a dist folder, before deleting anything', async () => { await expect(pack(src, { src, toml })).rejects.toThrow('must start with "dist"'); await expect(pack(sandbox, { src, toml })).rejects.toThrow('must start with "dist"');