Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ Check the returned ID before creating `docs/designs/<project>/decisions/<area>/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.
40 changes: 40 additions & 0 deletions site/dispatch/docs-dispatch.yml
Original file line number Diff line number Diff line change
@@ -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
129 changes: 129 additions & 0 deletions site/scripts/dispatch-workflow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { describe, expect, test } from "bun:test";

function record(value: unknown): Record<string, unknown> {
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, unknown>): string[] {
const triggers = record(workflow.on);
const push = record(triggers.push);
return strings(push.paths);
}

async function matchesPath(path: string): Promise<boolean> {
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");
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"),
);
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 () => {
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);
});
}
});
Loading