ci: prepare CI workflows for a GitHub merge queue (#2721)

Co-authored-by: Kandev Agent <agent@kandev.dev>
This commit is contained in:
João Salavisa
2026-08-16 20:10:03 +01:00
committed by GitHub
parent 032b693eb2
commit 5dcac3f259
12 changed files with 1372 additions and 278 deletions
+38 -11
View File
@@ -5,11 +5,15 @@ on:
branches: [main]
pull_request:
branches: [main]
merge_group:
types: [checks_requested]
concurrency:
# Pull requests can supersede one another safely. Pushes compare each commit
# with its own before-SHA, so never cancel a push run before that comparison
# completes.
# completes. Merge-queue runs are keyed by their own merge-group SHA for the
# same reason, and are likewise never cancelled: the queue reads a cancelled
# check as a failure and ejects the pull request.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
@@ -31,19 +35,42 @@ jobs:
- name: Run linter tests
run: python3 scripts/lint-architecture.test.py
- name: Lint pull request architecture
if: github.event_name == 'pull_request'
# One step rather than one per event. Each event names the baseline
# commit differently, and a `merge_group` run has neither of the two the
# split steps used to read: no `event.pull_request`, no `event.before`.
# Under the old shape it would have run the linter tests and silently
# linted nothing, which is the worst possible outcome for a required
# check — green, and having compared the branch against nothing.
- name: Resolve the architecture baseline
id: baseline
env:
ARCHITECTURE_BASE_REF: ${{ github.event.pull_request.base.sha }}
run: >-
python3 scripts/lint-architecture.py --all
--baseline-base-ref "$ARCHITECTURE_BASE_REF"
--allow-missing-base-baseline
EVENT_NAME: ${{ github.event_name }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
- name: Lint pushed architecture
if: github.event_name == 'push'
case "${EVENT_NAME}" in
pull_request) BASE_REF="${PR_BASE_SHA}" ;;
# The queue branch is cut from this commit, so it is the merge
# group's equivalent of the pull request's base.
merge_group) BASE_REF="${MERGE_GROUP_BASE_SHA}" ;;
push) BASE_REF="${PUSH_BEFORE}" ;;
*) BASE_REF="" ;;
esac
if [[ -z "${BASE_REF}" ]]; then
echo "No baseline commit for event '${EVENT_NAME}'." >&2
exit 1
fi
echo "base-ref=${BASE_REF}" >> "$GITHUB_OUTPUT"
echo "Architecture baseline: ${BASE_REF}"
- name: Lint architecture
env:
ARCHITECTURE_BASE_REF: ${{ github.event.before }}
ARCHITECTURE_BASE_REF: ${{ steps.baseline.outputs.base-ref }}
run: >-
python3 scripts/lint-architecture.py --all
--baseline-base-ref "$ARCHITECTURE_BASE_REF"
+156 -27
View File
@@ -1,32 +1,25 @@
name: Backend Tests
# No trigger-level `paths:` filter, deliberately. A workflow skipped by one
# reports no conclusion at all, and a required check that never reports leaves
# a pull request unable to enter a merge queue and a merge group unable to
# leave it. `merge_group` cannot carry a `paths:` filter in the first place.
# The filter lives in the `changes` job below instead, and the `test` job
# reports the single conclusion the queue waits on. See docs/ci-merge-queue.md.
on:
push:
branches: [main]
paths:
- "apps/backend/**"
# check-make-shells also lints the root Makefile's $(shell ...) probes, so
# a change there has to be able to trip it.
- "Makefile"
- "scripts/check-make-shells"
- ".github/workflows/backend-tests.yml"
- "!**/*.md"
- "!**/*.mdx"
- "!**/*.markdown"
pull_request:
branches: [main]
paths:
- "apps/backend/**"
- "Makefile"
- "scripts/check-make-shells"
- ".github/workflows/backend-tests.yml"
- "!**/*.md"
- "!**/*.mdx"
- "!**/*.markdown"
merge_group:
types: [checks_requested]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Never cancel a merge-queue run. Its ref is unique per queue entry, so a
# cancellation here could only come from a mis-keyed group, and the queue
# would read the cancelled check as a failure and eject the pull request.
cancel-in-progress: ${{ github.event_name != 'merge_group' }}
# Least-privilege default. The Linux static/test jobs and the Windows `test-windows`
# job only read source and run tests — no PR/issue writes, no release ops.
@@ -39,8 +32,78 @@ permissions:
packages: read
jobs:
# The former trigger-level `paths:` list, applied one level down so a skip
# still produces a conclusion. `.github/scripts/changed-paths.py` implements
# the same last-match-wins semantics GitHub applies to `paths:`.
changes:
name: Detect relevant changes
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
run: ${{ steps.detect.outputs.run }}
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
# The base commit has to be present locally for the diff below. Every
# other job in this workflow already pays for a full clone.
fetch-depth: 0
persist-credentials: false
- name: Detect relevant changes
id: detect
env:
PATTERNS: |
apps/backend/**
# check-make-shells also lints the root Makefile's $(shell ...)
# probes, so a change there has to be able to trip it.
Makefile
scripts/check-make-shells
.github/workflows/backend-tests.yml
.github/scripts/changed-paths.py
!**/*.md
!**/*.mdx
!**/*.markdown
EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
case "${EVENT_NAME}" in
# The checkout is the merge ref, whose first parent is the base
# branch tip. Diffing against that tip directly collapses to a
# two-dot diff over everything main landed since the PR opened, so
# take the fork point instead.
pull_request) BASE="$(git merge-base HEAD "origin/${BASE_REF}")" ;;
# The queue branch is cut from this commit, so it is a true ancestor.
merge_group) BASE="${MERGE_GROUP_BASE_SHA}" ;;
push) BASE="${PUSH_BEFORE}" ;;
*) BASE="" ;;
esac
# Fail open. A first push to a branch, a force push, or an unknown
# event leaves no usable base, and running the suite needlessly is
# cheaper than merging something no job ever looked at.
if [[ -z "${BASE}" || "${BASE}" == "0000000000000000000000000000000000000000" ]] \
|| ! git cat-file -e "${BASE}^{commit}" 2>/dev/null; then
echo "No usable base commit for '${EVENT_NAME}'; running everything."
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# `-z`, not plain --name-only: git quotes non-ASCII paths under its
# default core.quotePath, and a quoted path matches no pattern, so a
# change to one would skip every job and still report success.
git diff --name-only -z "${BASE}" HEAD \
| python3 .github/scripts/changed-paths.py
static_checks:
name: Backend Static Checks
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
# Pre-baked image bundles Go, golangci-lint, go-licenses, Docker CLI, Node,
# pnpm, and the Playwright base — see .github/docker/ci-base/Dockerfile.
@@ -94,13 +157,23 @@ jobs:
- name: Resolve base SHA
shell: bash
working-directory: ${{ github.workspace }}
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_SHA="${{ github.event.pull_request.base.sha }}"
# A merge_group run has no pull request behind it, so neither
# `pull_request.base.sha` nor `event.before` exists. The queue branch
# is cut from `merge_group.base_sha`, which is the equivalent base.
if [[ "${EVENT_NAME}" == "pull_request" ]]; then
BASE_SHA="${PR_BASE_SHA}"
elif [[ "${EVENT_NAME}" == "merge_group" ]]; then
BASE_SHA="${MERGE_GROUP_BASE_SHA}"
else
BASE_SHA="${{ github.event.before }}"
BASE_SHA="${PUSH_BEFORE}"
fi
if [[ -z "${BASE_SHA}" || "${BASE_SHA}" == "0000000000000000000000000000000000000000" ]]; then
@@ -144,6 +217,8 @@ jobs:
test_shards:
name: Backend Tests (${{ matrix.shard }}/2)
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
@@ -255,6 +330,8 @@ jobs:
test_ambient_env:
name: Backend (ambient integration env)
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
# test_shards runs in the same clean container and never sets these vars,
# so it cannot catch a package that starts reading them again — the class
@@ -298,28 +375,78 @@ jobs:
GITLAB_TOKEN: glpat-ambient-ci-not-a-real-token
run: go test -race ./internal/gitlab/... ./internal/agentctl/server/process/...
# The required check. Runs on every event, including the ones where every job
# above is correctly skipped, so the merge queue always has a conclusion to
# read instead of a check that stays pending forever.
#
# `needs` covers every other job in this workflow on purpose. A merge queue
# gates on check names an admin selects by hand, and a job missing from this
# list is a job whose failure would never block a merge — silently, and
# without appearing anywhere in the ruleset. `postgres-boot` and
# `test-windows` were outside it before this workflow became a gate.
test:
name: Run Backend Tests
runs-on: ubuntu-latest
needs: [static_checks, test_shards, test_ambient_env]
needs:
- changes
- static_checks
- test_shards
- test_ambient_env
- postgres-boot
- test-windows
if: ${{ always() }}
steps:
- name: Require backend checks to pass
env:
CHANGES_RESULT: ${{ needs.changes.result }}
STATIC_CHECKS_RESULT: ${{ needs.static_checks.result }}
TEST_SHARDS_RESULT: ${{ needs.test_shards.result }}
TEST_AMBIENT_ENV_RESULT: ${{ needs.test_ambient_env.result }}
POSTGRES_BOOT_RESULT: ${{ needs['postgres-boot'].result }}
TEST_WINDOWS_RESULT: ${{ needs['test-windows'].result }}
run: |
set -euo pipefail
if [[ "${STATIC_CHECKS_RESULT}" != "success" || "${TEST_SHARDS_RESULT}" != "success" || "${TEST_AMBIENT_ENV_RESULT}" != "success" ]]; then
echo "Static checks: ${STATIC_CHECKS_RESULT}"
echo "Test shards: ${TEST_SHARDS_RESULT}"
echo "Ambient env tests: ${TEST_AMBIENT_ENV_RESULT}"
echo "Change detection: ${CHANGES_RESULT}"
echo "Static checks: ${STATIC_CHECKS_RESULT}"
echo "Test shards: ${TEST_SHARDS_RESULT}"
echo "Ambient env tests: ${TEST_AMBIENT_ENV_RESULT}"
echo "Postgres boot: ${POSTGRES_BOOT_RESULT}"
echo "Windows tests: ${TEST_WINDOWS_RESULT}"
# Change detection itself must succeed: if it errored we do not know
# whether the skips below were deliberate.
if [[ "${CHANGES_RESULT}" != "success" ]]; then
echo "Change detection did not succeed; refusing to report a pass." >&2
exit 1
fi
# `skipped` is a pass — the change-detection job decided nothing this
# workflow covers was touched. `cancelled` is not: a cancelled job
# never reached a verdict, and treating that as a pass would let an
# untested merge group through.
#
# This gate is the one check a human opens when a merge is blocked, so
# name the job that failed here rather than making them correlate the
# list above by eye.
for entry in \
"static_checks:${STATIC_CHECKS_RESULT}" \
"test_shards:${TEST_SHARDS_RESULT}" \
"test_ambient_env:${TEST_AMBIENT_ENV_RESULT}" \
"postgres-boot:${POSTGRES_BOOT_RESULT}" \
"test-windows:${TEST_WINDOWS_RESULT}"; do
name="${entry%%:*}"
result="${entry#*:}"
if [[ "${result}" != "success" && "${result}" != "skipped" ]]; then
echo "${name} finished with result: ${result}" >&2
exit 1
fi
done
postgres-boot:
name: Backend Postgres
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
@@ -386,6 +513,8 @@ jobs:
test-windows:
name: Backend (windows)
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: windows-latest
# The race-sensitive Windows package suite can exceed 15 minutes on a
# busy hosted runner; keep the cap finite while allowing normal completion.
+159 -23
View File
@@ -1,28 +1,18 @@
name: E2E Tests
# No trigger-level `paths:` filter, deliberately. A workflow skipped by one
# reports no conclusion at all, and a required check that never reports leaves
# a pull request unable to enter a merge queue and a merge group unable to
# leave it. `merge_group` cannot carry a `paths:` filter in the first place.
# The filter lives in the `changes` job below instead, and `e2e-gate` reports
# the single conclusion the queue waits on. See docs/ci-merge-queue.md.
on:
push:
branches: [main]
paths:
- "apps/backend/**"
- "apps/desktop/**"
- "apps/web/**"
- "apps/packages/**"
- "apps/pnpm-lock.yaml"
- "apps/pnpm-workspace.yaml"
- ".github/workflows/e2e-tests.yml"
- "!**/*.md"
pull_request:
branches: [main]
paths:
- "apps/backend/**"
- "apps/desktop/**"
- "apps/web/**"
- "apps/packages/**"
- "apps/pnpm-lock.yaml"
- "apps/pnpm-workspace.yaml"
- ".github/workflows/e2e-tests.yml"
- "!**/*.md"
merge_group:
types: [checks_requested]
# Manual trigger for verifying CI on draft PRs and ad-hoc reruns. The
# default sharded run uses the same ref the user picks in the dispatch UI.
workflow_dispatch:
@@ -35,7 +25,10 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Never cancel a merge-queue run. Its ref is unique per queue entry, so a
# cancellation here could only come from a mis-keyed group, and the queue
# would read the cancelled check as a failure and eject the pull request.
cancel-in-progress: ${{ github.event_name != 'merge_group' }}
permissions:
contents: read
@@ -46,8 +39,77 @@ permissions:
packages: read
jobs:
# The former trigger-level `paths:` list, applied one level down so a skip
# still produces a conclusion. `.github/scripts/changed-paths.py` implements
# the same last-match-wins semantics GitHub applies to `paths:`.
changes:
name: Detect relevant changes
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
run: ${{ steps.detect.outputs.run }}
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
# The base commit has to be present locally for the diff below.
fetch-depth: 0
persist-credentials: false
- name: Detect relevant changes
id: detect
env:
PATTERNS: |
apps/backend/**
apps/desktop/**
apps/web/**
apps/packages/**
apps/pnpm-lock.yaml
apps/pnpm-workspace.yaml
.github/workflows/e2e-tests.yml
.github/scripts/changed-paths.py
!**/*.md
EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
case "${EVENT_NAME}" in
# The checkout is the merge ref, whose first parent is the base
# branch tip. Diffing against that tip directly collapses to a
# two-dot diff over everything main landed since the PR opened, so
# take the fork point instead.
pull_request) BASE="$(git merge-base HEAD "origin/${BASE_REF}")" ;;
# The queue branch is cut from this commit, so it is a true ancestor.
merge_group) BASE="${MERGE_GROUP_BASE_SHA}" ;;
push) BASE="${PUSH_BEFORE}" ;;
# workflow_dispatch is an explicit request to run the suite.
*) BASE="" ;;
esac
# Fail open. A first push to a branch, a force push, or a manual
# dispatch leaves no usable base, and running the suite needlessly is
# cheaper than merging something no job ever looked at.
if [[ -z "${BASE}" || "${BASE}" == "0000000000000000000000000000000000000000" ]] \
|| ! git cat-file -e "${BASE}^{commit}" 2>/dev/null; then
echo "No usable base commit for '${EVENT_NAME}'; running everything."
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# `-z`, not plain --name-only: git quotes non-ASCII paths under its
# default core.quotePath, and a quoted path matches no pattern, so a
# change to one would skip every job and still report success.
git diff --name-only -z "${BASE}" HEAD \
| python3 .github/scripts/changed-paths.py
build:
name: Build
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
# Pre-baked image bundles Go, Node 24, pnpm 9.15.9 — see
# .github/docker/ci-base/Dockerfile. Uses the `build` tag (with Go)
@@ -234,7 +296,8 @@ jobs:
e2e:
name: E2E Shard ${{ matrix.shard }}/14
needs: build
needs: [changes, build]
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
# Pre-baked image bundles Node 24, pnpm 9.15.9, and the Playwright browser
# binaries (Chromium etc.) — see .github/docker/ci-base/Dockerfile. This is
@@ -361,7 +424,8 @@ jobs:
# Sharded 6 ways — each shard is its own runner. See apps/web/e2e/README.md.
e2e-containers:
name: E2E Containers Shard ${{ matrix.shard }}/6
needs: build
needs: [changes, build]
if: needs.changes.outputs.run == 'true'
# This job intentionally runs on the host ubuntu runner (NOT the kandev-ci
# container image): the containers project needs direct access to the
# host Docker daemon, and a docker-in-docker setup would break the tests'
@@ -410,6 +474,10 @@ jobs:
# Their read-only GITHUB_TOKEN can still be rejected by GHCR during an
# explicit login because it belongs to the base repository, not the
# contributor's fork. Keep authenticated pulls for trusted runs.
#
# A merge_group run has no `github.event.pull_request` at all, so the
# first operand decides it. That is the right answer: the queue branch
# lives in this repository and its token is a base-repository token.
- name: Log in to GHCR
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
@@ -531,6 +599,8 @@ jobs:
desktop-e2e:
name: Desktop E2E Smoke
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
# Includes Ubuntu WebKit/Tauri system package installation; GitHub apt mirrors
# can spend more than 20 minutes there before tests start.
@@ -589,8 +659,12 @@ jobs:
e2e-report:
name: Merge E2E Reports
needs: [e2e, e2e-containers, desktop-e2e]
if: always()
needs: [changes, e2e, e2e-containers, desktop-e2e]
# `always()` so a failed shard still gets its report merged, but not when
# change detection skipped the shards outright: there would be no blob
# reports to download, and the artifact step would fail on an empty run.
# `e2e-gate` below, not this job, is what the merge queue waits on.
if: always() && needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
# Pre-baked image bundles Node 24, pnpm 9.15.9, and the Playwright CLI.
# `runtime` tag — no Go needed for merging blob reports.
@@ -949,3 +1023,65 @@ jobs:
echo "desktop-e2e finished with result: $DESKTOP_E2E_RESULT" >&2
exit 1
fi
# The required check. Runs on every event, including the ones where every job
# above is correctly skipped, so the merge queue always has a conclusion to
# read instead of a check that stays pending forever.
#
# A single gate is what makes this workflow usable from a ruleset at all: the
# alternative is naming all 14 E2E shards, all 6 container shards, and the
# desktop smoke individually, and renumbering the ruleset every time a shard
# count changes.
e2e-gate:
name: E2E Tests Passed
runs-on: ubuntu-latest
needs: [changes, build, e2e, e2e-containers, desktop-e2e, e2e-report]
if: always()
steps:
- name: Require the E2E jobs to have passed or been skipped
env:
CHANGES_RESULT: ${{ needs.changes.result }}
BUILD_RESULT: ${{ needs.build.result }}
E2E_RESULT: ${{ needs.e2e.result }}
E2E_CONTAINERS_RESULT: ${{ needs['e2e-containers'].result }}
DESKTOP_E2E_RESULT: ${{ needs['desktop-e2e'].result }}
E2E_REPORT_RESULT: ${{ needs['e2e-report'].result }}
run: |
set -euo pipefail
echo "Change detection: ${CHANGES_RESULT}"
echo "Build: ${BUILD_RESULT}"
echo "E2E shards: ${E2E_RESULT}"
echo "E2E container shards: ${E2E_CONTAINERS_RESULT}"
echo "Desktop smoke: ${DESKTOP_E2E_RESULT}"
echo "Report merge: ${E2E_REPORT_RESULT}"
# Change detection itself must succeed: if it errored we do not know
# whether the skips below were deliberate.
if [[ "${CHANGES_RESULT}" != "success" ]]; then
echo "Change detection did not succeed; refusing to report a pass." >&2
exit 1
fi
# `skipped` is a pass — the change-detection job decided nothing this
# workflow covers was touched. `cancelled` is not: a cancelled job
# never reached a verdict, and treating that as a pass would let an
# untested merge group through.
#
# This gate is the one check a human opens when a merge is blocked, so
# name the job that failed here rather than making them correlate the
# list above against twenty shard names.
for entry in \
"build:${BUILD_RESULT}" \
"e2e:${E2E_RESULT}" \
"e2e-containers:${E2E_CONTAINERS_RESULT}" \
"desktop-e2e:${DESKTOP_E2E_RESULT}" \
"e2e-report:${E2E_REPORT_RESULT}"; do
name="${entry%%:*}"
result="${entry#*:}"
if [[ "${result}" != "success" && "${result}" != "skipped" ]]; then
echo "${name} finished with result: ${result}" >&2
exit 1
fi
done
+159 -38
View File
@@ -1,42 +1,25 @@
name: Frontend Tests
# No trigger-level `paths:` filter, deliberately. A workflow skipped by one
# reports no conclusion at all, and a required check that never reports leaves
# a pull request unable to enter a merge queue and a merge group unable to
# leave it. `merge_group` cannot carry a `paths:` filter in the first place.
# The filter lives in the `changes` job below instead, and `frontend-gate`
# reports the single conclusion the queue waits on. See docs/ci-merge-queue.md.
on:
push:
branches: [main]
paths:
- "apps/cli/**"
- "apps/package.json"
- "apps/prettier.config.mjs"
- "apps/.prettierignore"
- "apps/web/**"
- "apps/packages/**"
- "apps/pnpm-lock.yaml"
- "apps/backend/go.mod"
- "apps/backend/go.sum"
- ".github/workflows/frontend-tests.yml"
- "!**/*.md"
- "!**/*.mdx"
- "!**/*.markdown"
pull_request:
branches: [main]
paths:
- "apps/cli/**"
- "apps/package.json"
- "apps/prettier.config.mjs"
- "apps/.prettierignore"
- "apps/web/**"
- "apps/packages/**"
- "apps/pnpm-lock.yaml"
- "apps/backend/go.mod"
- "apps/backend/go.sum"
- ".github/workflows/frontend-tests.yml"
- "!**/*.md"
- "!**/*.mdx"
- "!**/*.markdown"
merge_group:
types: [checks_requested]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Never cancel a merge-queue run. Its ref is unique per queue entry, so a
# cancellation here could only come from a mis-keyed group, and the queue
# would read the cancelled check as a failure and eject the pull request.
cancel-in-progress: ${{ github.event_name != 'merge_group' }}
# Least-privilege: the `frontend` job only reads source and runs tests.
# `packages: read` lets the container job pull the kandev-ci image from GHCR.
@@ -45,8 +28,82 @@ permissions:
packages: read
jobs:
# The former trigger-level `paths:` list, applied one level down so a skip
# still produces a conclusion. `.github/scripts/changed-paths.py` implements
# the same last-match-wins semantics GitHub applies to `paths:`.
changes:
name: Detect relevant changes
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
run: ${{ steps.detect.outputs.run }}
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
# The base commit has to be present locally for the diff below. Every
# other job in this workflow already pays for a full clone.
fetch-depth: 0
persist-credentials: false
- name: Detect relevant changes
id: detect
env:
PATTERNS: |
apps/cli/**
apps/package.json
apps/prettier.config.mjs
apps/.prettierignore
apps/web/**
apps/packages/**
apps/pnpm-lock.yaml
apps/backend/go.mod
apps/backend/go.sum
.github/workflows/frontend-tests.yml
.github/scripts/changed-paths.py
!**/*.md
!**/*.mdx
!**/*.markdown
EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
case "${EVENT_NAME}" in
# The checkout is the merge ref, whose first parent is the base
# branch tip. Diffing against that tip directly collapses to a
# two-dot diff over everything main landed since the PR opened, so
# take the fork point -- the same correction the steps below make.
pull_request) BASE="$(git merge-base HEAD "origin/${BASE_REF}")" ;;
# The queue branch is cut from this commit, so it is a true ancestor.
merge_group) BASE="${MERGE_GROUP_BASE_SHA}" ;;
push) BASE="${PUSH_BEFORE}" ;;
*) BASE="" ;;
esac
# Fail open. A first push to a branch, a force push, or an unknown
# event leaves no usable base, and running the suite needlessly is
# cheaper than merging something no job ever looked at.
if [[ -z "${BASE}" || "${BASE}" == "0000000000000000000000000000000000000000" ]] \
|| ! git cat-file -e "${BASE}^{commit}" 2>/dev/null; then
echo "No usable base commit for '${EVENT_NAME}'; running everything."
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# `-z`, not plain --name-only: git quotes non-ASCII paths under its
# default core.quotePath, and a quoted path matches no pattern, so a
# change to one would skip every job and still report success.
git diff --name-only -z "${BASE}" HEAD \
| python3 .github/scripts/changed-paths.py
frontend:
name: Run Frontend Lint, Tests, and Build
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
# Pre-baked image bundles Node 24, pnpm 9.15.9, Go, and go-licenses —
# see .github/docker/ci-base/Dockerfile.
@@ -101,6 +158,11 @@ jobs:
- name: Check formatting
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
@@ -112,10 +174,16 @@ jobs:
# extra files are already formatted), but it is the same trap the i18n
# ratchet below hit for real, so do not copy the old idiom. The fork
# point is what "changed in this PR" actually means.
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_SHA="$(git merge-base HEAD "origin/${{ github.base_ref }}")"
#
# `merge_group` has no PR context at all. Its own base_sha is the
# commit the queue branch was cut from, which is already the fork
# point, so no correction is needed there.
if [[ "${EVENT_NAME}" == "pull_request" ]]; then
BASE_SHA="$(git merge-base HEAD "origin/${BASE_REF}")"
elif [[ "${EVENT_NAME}" == "merge_group" ]]; then
BASE_SHA="${MERGE_GROUP_BASE_SHA}"
else
BASE_SHA="${{ github.event.before }}"
BASE_SHA="${PUSH_BEFORE}"
fi
if [[ -z "${BASE_SHA}" || "${BASE_SHA}" == "0000000000000000000000000000000000000000" ]]; then
@@ -183,6 +251,10 @@ jobs:
shell: bash
# The job defaults to `apps`; these scripts live one level deeper.
working-directory: apps/web
env:
EVENT_NAME: ${{ github.event_name }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
@@ -194,14 +266,23 @@ jobs:
# (#2160). The scripts' own default, `merge-base HEAD origin/main`,
# resolves to the merge ref's base-side parent and is correct here;
# origin/main is present because the checkout is fetch-depth: 0.
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [[ "${EVENT_NAME}" == "pull_request" ]]; then
node scripts/run-i18n-ratchet.mjs
exit 0
fi
# push: HEAD *is* the new base branch tip, so there is no fork point to
# find and the previous tip is the only meaningful base.
BASE_SHA="${{ github.event.before }}"
# merge_group: the queue branch is cut from base_sha and carries only
# the queued pull requests on top, so that IS the fork point. The
# scripts' `origin/main` default is wrong here — main may already have
# moved past what this merge group was built on.
if [[ "${EVENT_NAME}" == "merge_group" ]]; then
BASE_SHA="${MERGE_GROUP_BASE_SHA}"
else
# push: HEAD *is* the new base branch tip, so there is no fork point to
# find and the previous tip is the only meaningful base.
BASE_SHA="${PUSH_BEFORE}"
fi
if [[ -z "${BASE_SHA}" || "${BASE_SHA}" == "0000000000000000000000000000000000000000" ]]; then
echo "No usable base SHA; skipping the new-code ratchet."
exit 0
@@ -223,15 +304,24 @@ jobs:
- name: Run E2E sleep ratchet
shell: bash
working-directory: apps/web
env:
EVENT_NAME: ${{ github.event_name }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
PUSH_BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [[ "${EVENT_NAME}" == "pull_request" ]]; then
node scripts/check-new-e2e-sleeps.mjs
exit 0
fi
BASE_SHA="${{ github.event.before }}"
if [[ "${EVENT_NAME}" == "merge_group" ]]; then
BASE_SHA="${MERGE_GROUP_BASE_SHA}"
else
BASE_SHA="${PUSH_BEFORE}"
fi
if [[ -z "${BASE_SHA}" || "${BASE_SHA}" == "0000000000000000000000000000000000000000" ]]; then
echo "No usable base SHA; skipping the E2E sleep ratchet."
exit 0
@@ -256,3 +346,34 @@ jobs:
- name: Build
run: pnpm --filter @kandev/web build
# The required check. Runs on every event, including the ones where the
# `frontend` job above is correctly skipped, so the merge queue always has a
# conclusion to read instead of a check that stays pending forever.
frontend-gate:
name: Frontend Tests Passed
runs-on: ubuntu-latest
needs: [changes, frontend]
if: always()
steps:
- name: Require the frontend job to have passed or been skipped
env:
CHANGES_RESULT: ${{ needs.changes.result }}
FRONTEND_RESULT: ${{ needs.frontend.result }}
run: |
set -euo pipefail
# `skipped` is a pass: the change-detection job decided nothing this
# workflow covers was touched. `cancelled` is not — a cancelled job
# never reached a verdict, and treating that as a pass would let an
# untested merge group through.
if [[ "${CHANGES_RESULT}" != "success" ]]; then
echo "Change detection finished with result: ${CHANGES_RESULT}" >&2
exit 1
fi
if [[ "${FRONTEND_RESULT}" != "success" && "${FRONTEND_RESULT}" != "skipped" ]]; then
echo "Frontend job finished with result: ${FRONTEND_RESULT}" >&2
exit 1
fi
echo "Change detection: ${CHANGES_RESULT}; frontend: ${FRONTEND_RESULT}"
+20 -61
View File
@@ -1,74 +1,30 @@
name: Lint Action Pinning
# No trigger-level `paths:` filter, deliberately. A workflow skipped by one
# reports no conclusion at all, and a required check that never reports leaves
# a pull request unable to enter a merge queue and a merge group unable to
# leave it. `merge_group` cannot carry a `paths:` filter in the first place.
#
# The heavier gates push their filtering down into a `changes` job (see
# `.github/scripts/changed-paths.py`). This one is deliberately unfiltered
# instead: the list it replaced had grown to thirty-odd entries that each had
# to be added by hand whenever a contract test gained a new subject, and every
# omission was a silently unguarded file. Always running is both cheaper to
# reason about and strictly safer. See docs/ci-merge-queue.md.
on:
push:
branches: [main]
paths:
- ".github/workflows/**"
- ".github/scripts/lint-action-pinning.py"
- ".github/scripts/lint-action-pinning_test.py"
- ".github/scripts/claude-code-review-workflow-contract_test.py"
- ".github/scripts/frontend-tests-workflow-contract_test.py"
- "apps/web/vitest.config.ts"
- "apps/.npmrc"
- ".github/scripts/preview-env-workflow-contract_test.py"
- ".github/scripts/collect-macos-desktop-diagnostics.sh"
- ".github/scripts/release-workflow-contract_test.py"
- ".github/release-signing-key.asc"
- "docs/public/release-process.md"
- "Makefile"
- "apps/backend/Makefile"
- "scripts/release/package-bundle.sh"
- "scripts/release/runtime-bundle.test.sh"
- "scripts/release/validate-darwin-arm64-helper.mjs"
- "scripts/release/npm-packages.sh"
- "scripts/release/nightly-version.mjs"
- "scripts/release/nightly-version.test.mjs"
- "scripts/release/nightly-release.sh"
- "scripts/release/nightly-release.test.mjs"
- "scripts/release/npm-view-version.sh"
- "scripts/release/npm-view-version.test.mjs"
- "scripts/release/package-npm-runtime.sh"
- "scripts/release/publish-npm.sh"
- "scripts/release/publish-npm.test.mjs"
- "scripts/release/retry-ghcr-command.sh"
- "scripts/release/retry-ghcr-command.test.sh"
pull_request:
branches: [main]
paths:
- ".github/workflows/**"
- ".github/scripts/lint-action-pinning.py"
- ".github/scripts/lint-action-pinning_test.py"
- ".github/scripts/claude-code-review-workflow-contract_test.py"
- ".github/scripts/frontend-tests-workflow-contract_test.py"
- "apps/web/vitest.config.ts"
- "apps/.npmrc"
- ".github/scripts/preview-env-workflow-contract_test.py"
- ".github/scripts/collect-macos-desktop-diagnostics.sh"
- ".github/scripts/release-workflow-contract_test.py"
- ".github/release-signing-key.asc"
- "docs/public/release-process.md"
- "Makefile"
- "apps/backend/Makefile"
- "scripts/release/package-bundle.sh"
- "scripts/release/runtime-bundle.test.sh"
- "scripts/release/validate-darwin-arm64-helper.mjs"
- "scripts/release/npm-packages.sh"
- "scripts/release/nightly-version.mjs"
- "scripts/release/nightly-version.test.mjs"
- "scripts/release/nightly-release.sh"
- "scripts/release/nightly-release.test.mjs"
- "scripts/release/npm-view-version.sh"
- "scripts/release/npm-view-version.test.mjs"
- "scripts/release/package-npm-runtime.sh"
- "scripts/release/publish-npm.sh"
- "scripts/release/publish-npm.test.mjs"
- "scripts/release/retry-ghcr-command.sh"
- "scripts/release/retry-ghcr-command.test.sh"
merge_group:
types: [checks_requested]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Never cancel a merge-queue run. Its ref is unique per queue entry, so a
# cancellation here could only come from a mis-keyed group, and the queue
# would read the cancelled check as a failure and eject the pull request.
cancel-in-progress: ${{ github.event_name != 'merge_group' }}
# Least-privilege: only reads source.
permissions:
@@ -88,6 +44,9 @@ jobs:
- name: Test action-pinning lint
run: python3 .github/scripts/lint-action-pinning_test.py
- name: Test in-job path filter
run: python3 .github/scripts/changed-paths_test.py
- name: Test Claude Code review workflow contract
run: python3 .github/scripts/claude-code-review-workflow-contract_test.py
+17 -57
View File
@@ -1,70 +1,30 @@
name: Lint Harness Files
# No trigger-level `paths:` filter, deliberately. A workflow skipped by one
# reports no conclusion at all, and a required check that never reports leaves
# a pull request unable to enter a merge queue and a merge group unable to
# leave it. `merge_group` cannot carry a `paths:` filter in the first place.
#
# The heavier gates push their filtering down into a `changes` job (see
# `.github/scripts/changed-paths.py`). This job is a checkout plus four short
# linters, so the whole list is replaced by simply always running: cheaper than
# the job that would decide whether to run it, and it closes the gap where a
# harness file outside the old list changed and nothing checked it.
# See docs/ci-merge-queue.md.
on:
push:
branches: [main]
paths:
- ".github/workflows/lint-harness-files.yml"
- ".github/scripts/lint-harness-files.py"
- "scripts/lint-harness-files.test.py"
- ".pre-commit-config.yaml"
- "AGENTS.md"
- "CLAUDE.md"
- "**/AGENTS.md"
- "**/CLAUDE.md"
- "**/.cursorrules"
- ".agents/skills/**/*.md"
- ".augment/skills/**/*.md"
- ".claude/skills/**/*.md"
- ".cursor/skills/**/*.md"
- ".opencode/skills/**/*.md"
- "apps/backend/internal/office/configloader/skills/**/*.md"
- ".agents/agents/**/*.md"
- ".opencode/agents/**/*.md"
- ".claude/agents/**/*.md"
- ".codex/agents/**/*.toml"
- ".codex/config.toml"
- ".claude/settings.json"
- ".claude/rules/**/*.md"
- ".cursor/rules/**/*.mdc"
- ".claude/commands/**/*.md"
- "apps/web/lib/plugins/types.ts"
- "scripts/validate-plugin-api-claims.mjs"
- "scripts/validate-plugin-api-claims.test.mjs"
pull_request:
branches: [main]
paths:
- ".github/workflows/lint-harness-files.yml"
- ".github/scripts/lint-harness-files.py"
- "scripts/lint-harness-files.test.py"
- ".pre-commit-config.yaml"
- "AGENTS.md"
- "CLAUDE.md"
- "**/AGENTS.md"
- "**/CLAUDE.md"
- "**/.cursorrules"
- ".agents/skills/**/*.md"
- ".augment/skills/**/*.md"
- ".claude/skills/**/*.md"
- ".cursor/skills/**/*.md"
- ".opencode/skills/**/*.md"
- "apps/backend/internal/office/configloader/skills/**/*.md"
- ".agents/agents/**/*.md"
- ".opencode/agents/**/*.md"
- ".claude/agents/**/*.md"
- ".codex/agents/**/*.toml"
- ".codex/config.toml"
- ".claude/settings.json"
- ".claude/rules/**/*.md"
- ".cursor/rules/**/*.mdc"
- ".claude/commands/**/*.md"
- "apps/web/lib/plugins/types.ts"
- "scripts/validate-plugin-api-claims.mjs"
- "scripts/validate-plugin-api-claims.test.mjs"
merge_group:
types: [checks_requested]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Never cancel a merge-queue run. Its ref is unique per queue entry, so a
# cancellation here could only come from a mis-keyed group, and the queue
# would read the cancelled check as a failure and eject the pull request.
cancel-in-progress: ${{ github.event_name != 'merge_group' }}
permissions:
contents: read