From 7bf98feef1b3a15b5d50e4bb74cce320c16b9072 Mon Sep 17 00:00:00 2001 From: mintaka Date: Mon, 9 Nov 2026 23:40:11 -0500 Subject: [PATCH 1/2] feat(site): add the canonical docs-dispatch workflow (RIG-9080) Co-authored-by: Matt Wilkinson --- README.md | 2 + site/dispatch/docs-dispatch.yml | 40 +++++++++ site/scripts/dispatch-workflow.test.ts | 116 +++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 site/dispatch/docs-dispatch.yml create mode 100644 site/scripts/dispatch-workflow.test.ts diff --git a/README.md b/README.md index 1a35f031..13b145e1 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,6 @@ Check the returned ID before creating `docs/designs//decisions//D Run `bun install`, `bun test`, `bun run gate`, `bun run ref-gate`, `rumdl check .`, `biome ci .`, and `bun run build`. The gather step reads checked-in Markdown under `docs/`, renders decision pages and per-project decision indexes into generated content, and the Astro Starlight site publishes to the Cloudflare Pages project `docs`. +The canonical source-repository dispatch workflow is `site/dispatch/docs-dispatch.yml`. + Cloudflare assigns the Pages hostname for project `docs`; the site does not configure a custom domain. diff --git a/site/dispatch/docs-dispatch.yml b/site/dispatch/docs-dispatch.yml new file mode 100644 index 00000000..c3e5e3dc --- /dev/null +++ b/site/dispatch/docs-dispatch.yml @@ -0,0 +1,40 @@ +name: Docs dispatch + +on: + push: + branches: [main] + paths: + - "**/*.md" + - "**/*.png" + - "**/*.jpg" + - "**/*.jpeg" + - "**/*.gif" + - "**/*.svg" + - "**/*.webp" + - "**/*.avif" + - "**/*.PNG" + - "**/*.JPG" + - "**/*.JPEG" + - "**/*.GIF" + - "**/*.SVG" + - "**/*.WEBP" + - "**/*.AVIF" + - "docs-bundle.toml" +jobs: + dispatch: + runs-on: ubuntu-latest + environment: main + permissions: {} + steps: + - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 + id: app-token + with: + client-id: ${{ secrets.DOCS_DISPATCH_CLIENT_ID }} + private-key: ${{ secrets.DOCS_DISPATCH_PRIVATE_KEY }} + owner: RigelBuild + repositories: docs + permission-actions: write + - name: Rebuild docs.rigel.build + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + run: gh workflow run deploy.yml --repo RigelBuild/docs --ref main diff --git a/site/scripts/dispatch-workflow.test.ts b/site/scripts/dispatch-workflow.test.ts new file mode 100644 index 00000000..c3b13acf --- /dev/null +++ b/site/scripts/dispatch-workflow.test.ts @@ -0,0 +1,116 @@ +import { describe, expect, test } from "bun:test"; + +function record(value: unknown): Record { + if (typeof value !== "object" || value === null || Array.isArray(value)) { + throw new Error("Expected a YAML mapping"); + } + const entries: [string, unknown][] = Object.entries(value); + return Object.fromEntries(entries); +} + +function strings(value: unknown): string[] { + if ( + !Array.isArray(value) || + value.some((entry) => typeof entry !== "string") + ) { + throw new Error("Expected a list of path patterns"); + } + return value; +} + +const workflowPromise = Bun.file( + new URL("../dispatch/docs-dispatch.yml", import.meta.url), +) + .text() + .then((source) => record(Bun.YAML.parse(source))); + +function paths(workflow: Record): string[] { + const triggers = record(workflow.on); + const push = record(triggers.push); + return strings(push.paths); +} + +async function matchesPath(path: string): Promise { + const patterns = paths(await workflowPromise); + if (patterns.some((pattern) => pattern.includes("{"))) { + throw new Error("Workflow path patterns must not use brace expansion"); + } + const globs = patterns.map((pattern) => new Bun.Glob(pattern)); + return globs.some((glob) => glob.match(path)); +} + +describe("canonical docs dispatch workflow", () => { + test("triggers only on pushes to main", async () => { + const triggers = record((await workflowPromise).on); + expect(Object.keys(triggers)).toEqual(["push"]); + const push = record(triggers.push); + expect(push.branches).toEqual(["main"]); + expect(Object.keys(push).sort()).toEqual(["branches", "paths"]); + }); + + test("uses the main environment and empty job permissions", async () => { + const jobs = record((await workflowPromise).jobs); + const dispatch = record(jobs.dispatch); + expect(dispatch.environment).toBe("main"); + expect(dispatch.permissions).toEqual({}); + }); + + test("passes the app token to the workflow dispatch command", async () => { + const jobs = record((await workflowPromise).jobs); + const dispatch = record(jobs.dispatch); + if (!Array.isArray(dispatch.steps)) + throw new Error("Expected workflow steps"); + const steps = dispatch.steps.map(record); + const tokenStep = steps.find((step) => step.id === "app-token"); + expect(tokenStep?.id).toBe("app-token"); + const runStep = steps.find( + (step) => + typeof step.run === "string" && step.run.includes("gh workflow run"), + ); + expect(record(runStep?.env).GH_TOKEN).toBe( + `\${{ steps.app-token.outputs.token }}`, + ); + }); + + test("has brace-free path patterns that compile", async () => { + const patterns = paths(await workflowPromise); + expect(patterns.every((pattern) => !pattern.includes("{"))).toBe(true); + expect(() => + patterns.map((pattern) => new Bun.Glob(pattern)), + ).not.toThrow(); + }); + + test("includes lower- and upper-case image patterns", async () => { + const patterns = paths(await workflowPromise); + for (const extension of [ + "png", + "jpg", + "jpeg", + "gif", + "svg", + "webp", + "avif", + ]) { + expect(patterns).toContain(`**/*.${extension}`); + expect(patterns).toContain(`**/*.${extension.toUpperCase()}`); + } + }); + + for (const path of [ + "docs/arch/diagram.png", + "docs/arch/DIAGRAM.SVG", + "README.md", + "docs/guide.md", + "docs-bundle.toml", + ]) { + test(`matches ${path}`, async () => { + expect(await matchesPath(path)).toBe(true); + }); + } + + for (const path of ["src/main.go", "docs/arch/diagram.bmp"]) { + test(`does not match ${path}`, async () => { + expect(await matchesPath(path)).toBe(false); + }); + } +}); From a0410a50c29c42473ce125fb838e30f5b79db0ba Mon Sep 17 00:00:00 2001 From: mintaka Date: Mon, 9 Nov 2026 23:57:29 -0500 Subject: [PATCH 2/2] test(site): pin the dispatch token scope and run target Co-authored-by: Matt Wilkinson --- site/scripts/dispatch-workflow.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/site/scripts/dispatch-workflow.test.ts b/site/scripts/dispatch-workflow.test.ts index c3b13acf..6f5f1de6 100644 --- a/site/scripts/dispatch-workflow.test.ts +++ b/site/scripts/dispatch-workflow.test.ts @@ -63,6 +63,16 @@ describe("canonical docs dispatch workflow", () => { const steps = dispatch.steps.map(record); const tokenStep = steps.find((step) => step.id === "app-token"); expect(tokenStep?.id).toBe("app-token"); + expect(String(tokenStep?.uses)).toStartWith( + "actions/create-github-app-token@", + ); + const tokenInputs = record(tokenStep?.with); + expect(tokenInputs.owner).toBe("RigelBuild"); + expect(tokenInputs.repositories).toBe("docs"); + expect( + Object.keys(tokenInputs).filter((key) => key.startsWith("permission-")), + ).toEqual(["permission-actions"]); + expect(tokenInputs["permission-actions"]).toBe("write"); const runStep = steps.find( (step) => typeof step.run === "string" && step.run.includes("gh workflow run"), @@ -70,6 +80,9 @@ describe("canonical docs dispatch workflow", () => { expect(record(runStep?.env).GH_TOKEN).toBe( `\${{ steps.app-token.outputs.token }}`, ); + expect(runStep?.run).toBe( + "gh workflow run deploy.yml --repo RigelBuild/docs --ref main", + ); }); test("has brace-free path patterns that compile", async () => {