Skip to content
Draft
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
11 changes: 10 additions & 1 deletion .github/workflows/port-heads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }}
Expand All @@ -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:
Expand Down
30 changes: 19 additions & 11 deletions docs/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<PORT>`, 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
Expand All @@ -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

Expand Down
26 changes: 17 additions & 9 deletions scripts/check-port-heads.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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=<json>` 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'
Expand All @@ -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),
Expand All @@ -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}`)
Expand Down
61 changes: 61 additions & 0 deletions site/test/check-port-heads.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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/)
})
})
Loading