From c09662dc6da7d41ee4a1747a35b382f0b85e31fe Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 6 Dec 2026 00:42:07 -0600 Subject: [PATCH] feat(ci[port-heads]) Check one library family MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit why: Verifying the Lua exporter starts every port’s build and badge check. what: - Select a library family before resolving repository heads. - Keep its wrappers and skip jobs with an empty build matrix. - Test and document the weekly and manual selections. --- .github/workflows/port-heads.yml | 11 +++++- docs/ci.md | 30 +++++++++------ scripts/check-port-heads.mjs | 26 ++++++++----- site/test/check-port-heads.test.ts | 61 ++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 21 deletions(-) diff --git a/.github/workflows/port-heads.yml b/.github/workflows/port-heads.yml index 92c4e4062..bb317b05c 100644 --- a/.github/workflows/port-heads.yml +++ b/.github/workflows/port-heads.yml @@ -26,6 +26,11 @@ on: schedule: - cron: '41 7 * * 1' workflow_dispatch: + inputs: + family: + description: Library family slug such as lua or java, or all + type: string + default: all permissions: contents: read @@ -51,10 +56,13 @@ jobs: node-version: '26' - run: pnpm install --frozen-lockfile - id: matrix - run: node scripts/check-port-heads.mjs matrix + env: + FAMILY: ${{ github.event_name == 'schedule' && 'all' || inputs.family }} + run: node scripts/check-port-heads.mjs matrix "$FAMILY" build: needs: matrix + if: ${{ fromJSON(needs.matrix.outputs.matrix).include[0] != null }} strategy: fail-fast: false matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }} @@ -78,6 +86,7 @@ jobs: # port head's own docs tooling, against docs main. native: needs: matrix + if: ${{ fromJSON(needs.matrix.outputs.own).include[0] != null }} runs-on: ubuntu-24.04 timeout-minutes: 30 strategy: diff --git a/docs/ci.md b/docs/ci.md index 65641f3f5..d22d36930 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -545,14 +545,22 @@ regenerates its API model and guides from the port's head, so a new package or README badge service in the port can break that build while this repository's CI, which reads committed models and guides, stays green. -The `build` job calls [`port-docs.yml`](../.github/workflows/port-docs.yml), the -workflow every port publish calls, once per library family (a core port and its -wrappers) with the port's repository, the head commit of its default branch, -`publish: false` and the `latest` trunk identity. Every port therefore runs its -own exporters, toolchains and `build-site.sh` exactly as a release does, wrapper -legs set only the wrapper's `LIBTMUX_DOCS_CHECKOUT_`, and no -`reusable-deploy.yml` job follows, so nothing is deployed. The matrix -(`scripts/check-port-heads.mjs matrix`) resolves each head with `git ls-remote`. +When running the workflow manually, set `family` to a core port slug such as +`lua` or `java`. The `java` family includes Clojure, Kotlin and Scala. Leave +`family` at `all` to check every family, as the weekly run does. + +This command runs the Lua check using the workflow on `main`. + +```console +$ gh workflow run port-heads.yml --repo libtmux/docs --ref main -f family=lua +``` + +The `native` job runs Lua and Ruby's own exporters. The `build` job calls +[`port-docs.yml`](../.github/workflows/port-docs.yml) for the other selected +families, including their wrappers. It passes each family's default-branch +head, `publish: false` and the `latest` trunk identity. The planner +(`scripts/check-port-heads.mjs matrix [family]`) resolves only the selected +heads with `git ls-remote`. To allow this, `port-docs.yml` has one optional input, `source-repository` (string, default empty). Empty keeps today's behavior, building the calling @@ -561,9 +569,9 @@ identity step lists and which the matrix checks against `ports.ts`. `port-docs-identity.sh` also accepts a `schedule` event, treated like a dispatch that names its inputs, and refuses it when `publish` is true. -The `badges` job runs `scripts/check-port-badges.mjs` over each family's staged -guides at the same head. It lists every unmapped badge with port, file and URL, -where the build stops at the first. +The `badges` job runs `scripts/check-port-badges.mjs` over the selected families' +staged guides at the same heads. It lists each unmapped badge with its port, +file and URL. ## Secrets this scheme expects diff --git a/scripts/check-port-heads.mjs b/scripts/check-port-heads.mjs index f2965c706..cb62621ff 100644 --- a/scripts/check-port-heads.mjs +++ b/scripts/check-port-heads.mjs @@ -4,9 +4,9 @@ * each naming the family's repository, the head commit of its default branch, * and the ports built from it. * - * `node scripts/check-port-heads.mjs matrix` writes `matrix=` to - * $GITHUB_OUTPUT and prints it. The head is resolved with `git ls-remote`, so a - * leg builds one fixed commit however long the queue is. + * `node scripts/check-port-heads.mjs matrix [family]` writes the job matrices to + * $GITHUB_OUTPUT and prints them. Select a core port slug or leave `all` to + * check every family. Each leg resolves its head once with `git ls-remote`. */ import { spawnSync } from 'node:child_process' import { appendFileSync } from 'node:fs' @@ -21,9 +21,12 @@ import { PORTS } from '../site/src/lib/ports.ts' export const OWN_WORKFLOW = ['lua', 'ruby'] /** One leg per core port; its wrappers share its repository and are built with it. */ -export function matrix(headOf = defaultBranchHead, { own = false } = {}) { +export function matrix(headOf = defaultBranchHead, { own = false, family = 'all' } = {}) { + const families = PORTS.filter((port) => !port.parentLibrary && (family === 'all' || port.slug === family)) + if (families.length === 0) throw new Error(`unknown port-heads family ${JSON.stringify(family)}. Use a core port slug or "all".`) + return { - include: PORTS.filter((port) => !port.parentLibrary && OWN_WORKFLOW.includes(port.slug) === own).map((port) => ({ + include: families.filter((port) => OWN_WORKFLOW.includes(port.slug) === own).map((port) => ({ port: port.slug, repo: port.repo, ref: headOf(port.repo), @@ -40,10 +43,15 @@ function defaultBranchHead(repo) { } if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { - if (process.argv[2] !== 'matrix') throw new Error('usage: check-port-heads.mjs matrix') - const all = matrix(defaultBranchHead, { own: false }) - const own = matrix(defaultBranchHead, { own: true }) - const outputs = { matrix: JSON.stringify(all), own: JSON.stringify(own), badges: JSON.stringify({ include: [...all.include, ...own.include] }) } + const [command, family = 'all', ...extra] = process.argv.slice(2) + if (command !== 'matrix' || extra.length) throw new Error('usage: check-port-heads.mjs matrix [family]') + const shared = matrix(defaultBranchHead, { family }) + const own = matrix(defaultBranchHead, { family, own: true }) + const outputs = { + matrix: JSON.stringify(shared), + own: JSON.stringify(own), + badges: JSON.stringify({ include: [...shared.include, ...own.include] }), + } for (const [name, json] of Object.entries(outputs)) { if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT, `${name}=${json}\n`) console.log(`${name}=${json}`) diff --git a/site/test/check-port-heads.test.ts b/site/test/check-port-heads.test.ts index 7f95af654..6bd0a47ec 100644 --- a/site/test/check-port-heads.test.ts +++ b/site/test/check-port-heads.test.ts @@ -1,3 +1,4 @@ +import { readFileSync } from 'node:fs' import { describe, expect, it } from 'vitest' import { matrix } from '../../scripts/check-port-heads.mjs' import { PORTS } from '../src/lib/ports.ts' @@ -21,4 +22,64 @@ describe('port-heads matrix', () => { it('names each leg by the repository the port builds from', () => { for (const leg of legs) expect(PORTS.find((port) => port.slug === leg.port)?.repo).toBe(leg.repo) }) + + it('resolves only the selected shared family, including its wrappers', () => { + const lookups: string[] = [] + const resolve = (repo: string) => { + lookups.push(repo) + return head() + } + + expect(matrix(resolve, { family: 'java' }).include).toEqual([ + { port: 'java', repo: 'libtmux/libtmux-java', ref: head(), members: 'java clojure kotlin scala' }, + ]) + expect(matrix(resolve, { family: 'java', own: true }).include).toEqual([]) + expect(lookups).toEqual(['libtmux/libtmux-java']) + }) + + it('resolves only the selected family with a native exporter', () => { + const lookups: string[] = [] + const resolve = (repo: string) => { + lookups.push(repo) + return head() + } + + expect(matrix(resolve, { family: 'lua' }).include).toEqual([]) + expect(matrix(resolve, { family: 'lua', own: true }).include).toEqual([ + { port: 'lua', repo: 'libtmux/libtmux-lua', ref: head(), members: 'lua' }, + ]) + expect(lookups).toEqual(['libtmux/libtmux-lua']) + }) + + it.each(['kotlin', 'unknown', 'lua,java', '', 'constructor'])('refuses family %j before resolving heads', (family) => { + const lookups: string[] = [] + const resolve = (repo: string) => { + lookups.push(repo) + return head() + } + + expect(() => matrix(resolve, { family })).toThrow('unknown port-heads family') + expect(lookups).toEqual([]) + }) + + it('uses the default family selection when explicitly asked for all', () => { + for (const own of [false, true]) { + expect(matrix(head, { family: 'all', own })).toEqual(matrix(head, { own })) + } + }) +}) + +describe('port-heads workflow', () => { + const workflow = readFileSync(new URL('../../.github/workflows/port-heads.yml', import.meta.url), 'utf8') + + it('defaults manual and scheduled runs to all and forwards a named manual family', () => { + expect(workflow).toMatch(/workflow_dispatch:\n inputs:\n family:\n(?: {8}[^\n]+\n)* {8}default: all/) + expect(workflow).toContain(`FAMILY: \${{ github.event_name == 'schedule' && 'all' || inputs.family }}`) + expect(workflow).toContain('run: node scripts/check-port-heads.mjs matrix "$FAMILY"') + }) + + it('skips the build job whose matrix has no rows', () => { + expect(workflow).toMatch(/ build:\n needs: matrix\n if: .*fromJSON\(needs\.matrix\.outputs\.matrix\)\.include\[0\] != null/) + expect(workflow).toMatch(/ native:\n needs: matrix\n if: .*fromJSON\(needs\.matrix\.outputs\.own\)\.include\[0\] != null/) + }) })