Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

ci: stop re-running the full suite on main pushes and release merges

[._.]/ Adam Eivy7e0cea2ae3dd
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 46a26914aa..98290b7bae 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,10 +1,13 @@
name: CI
on:
+ # No push trigger. Every change reaches `main` through a pull request whose
+ # own CI gate must be green, so re-running the suite on the merge commit only
+ # repeats work. The nightly schedule below is the main-branch health signal,
+ # and the main -> release pull request runs the complete suite before a
+ # release ships.
pull_request:
branches: [main, release]
- push:
- branches: [main]
schedule:
- cron: '17 9 * * *'
workflow_dispatch:
@@ -52,7 +55,10 @@ jobs:
- name: Select affected test surfaces
id: plan
env:
- CI_FORCE_FULL: ${{ github.event_name != 'pull_request' || inputs.full }}
+ # Full suite for anything that is not an ordinary PR, and for the
+ # main -> release PR: that PR is the single gate a release ships
+ # behind, so it never runs a scoped plan.
+ CI_FORCE_FULL: ${{ github.event_name != 'pull_request' || github.base_ref == 'release' || inputs.full == true }}
CI_BASE_SHA: ${{ github.event.pull_request.base.sha }}
CI_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: node scripts/ci-test-plan.js
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 5fc731bc99..b12dc085fc 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -8,17 +8,58 @@ permissions:
contents: write
jobs:
- full-ci:
+ # The main -> release pull request already ran the complete suite on the very
+ # tree this push carries. Look for that green gate instead of paying for it
+ # twice; anything unverified (a direct push to release, a merge that changed
+ # the tree, an API failure) still falls through to the full run below.
+ verify-ci:
+ name: Check for an existing full CI run
if: "!contains(github.event.head_commit.message, '[skip ci]')"
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ checks: read
+ outputs:
+ verified: ${{ steps.check.outputs.verified }}
+ sha: ${{ steps.check.outputs.sha }}
+ reason: ${{ steps.check.outputs.reason }}
+ steps:
+ # Depth 2 so both parents of the release merge commit — and their trees —
+ # are available to compare against the tree being released.
+ - uses: actions/checkout@v7
+ with:
+ fetch-depth: 2
+
+ - name: Look for a passing CI Gate on this tree
+ id: check
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: node scripts/verify-ci-status.js
+
+ - name: Publish verification summary
+ env:
+ VERIFIED: ${{ steps.check.outputs.verified }}
+ REASON: ${{ steps.check.outputs.reason }}
+ run: |
+ {
+ echo "### Release CI verification"
+ echo
+ echo "- Already verified: \`${VERIFIED}\`"
+ echo "- Reason: \`${REASON}\`"
+ } >> "$GITHUB_STEP_SUMMARY"
+
+ full-ci:
+ needs: verify-ci
+ if: needs.verify-ci.outputs.verified != 'true'
uses: ./.github/workflows/ci.yml
with:
full: true
release:
- needs: full-ci
+ needs: [verify-ci, full-ci]
runs-on: ubuntu-latest
# Skip version bump commits
- if: always() && !contains(github.event.head_commit.message, '[skip ci]')
+ if: always() && !contains(github.event.head_commit.message, '[skip ci]') && needs.verify-ci.result == 'success'
steps:
- uses: actions/checkout@v7
@@ -40,8 +81,10 @@ jobs:
id: package-version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
+ # full-ci is skipped when verify-ci already found a green gate for this
+ # tree, so only an actually-executed-and-failed run blocks the release.
- name: Report release failure on CI failure
- if: needs.full-ci.result != 'success'
+ if: needs.verify-ci.outputs.verified != 'true' && needs.full-ci.result != 'success'
run: |
VERSION="${{ steps.package-version.outputs.version }}"
echo "::error::release v${VERSION} did NOT publish because full-ci status was '${{ needs.full-ci.result }}'"
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.md
index d9007515fa..e14a393c29 100644
--- a/docs/GITHUB_ACTIONS.md
+++ b/docs/GITHUB_ACTIONS.md
@@ -1,23 +1,43 @@
# GitHub Actions Workflows
PortOS uses a test-impact-aware CI workflow plus a release workflow that cannot
-publish until the complete CI suite passes.
+publish until the complete CI suite has passed on the exact tree being released.
+
+## Where the suite actually runs
+
+Every change reaches `main` through a pull request, and `main` reaches
+`release` through a pull request, so the suite runs once per gate rather than
+once per event:
+
+| Event | What runs |
+|-------|-----------|
+| PR into `main` | Impact-scoped plan (only the surfaces the diff touches) |
+| Push/merge to `main` | **Nothing** — no push trigger; the PR gate already passed |
+| PR `main` → `release` | **Full suite**, forced regardless of the diff |
+| Push/merge to `release` | Reuses the release PR's green gate; full suite only if it cannot be verified |
+| Nightly 09:17 UTC | Full suite — the `main`-branch health signal |
+| `workflow_dispatch` | Full suite |
+
+A release therefore pays for one full run (on its PR), not three.
## Branch Strategy
| Branch | Purpose |
|--------|---------|
| `main` | Active development |
-| `release` | Push `main` to `release` to trigger releases |
+| `release` | Merge `main` into `release` to trigger releases |
## CI Workflow (`ci.yml`)
-PRs to `main`/`release` use `scripts/ci-test-plan.js` to classify the changed
-files before installing dependencies. Directory-scoped features run their
-server and client feature tests; flat modules fall back to Vitest's
-import-graph-aware `--changed` mode. The planner deliberately chooses full CI
-for shared composition roots, test configuration, dependency manifests,
-workflow changes, unknown artifacts, or wide diffs.
+PRs into `main` use `scripts/ci-test-plan.js` to classify the changed files
+before installing dependencies. Directory-scoped features run their server and
+client feature tests; flat modules fall back to Vitest's import-graph-aware
+`--changed` mode. The planner deliberately chooses full CI for shared
+composition roots, test configuration, dependency manifests, workflow changes,
+unknown artifacts, or wide diffs.
+
+PRs into `release` skip the planner entirely and force the full suite: that PR
+is the single gate a release ships behind.
A short always-run list (`ALWAYS_RUN_TESTS` in the planner) is added to every
plan, so no impact scope can drop it — currently
@@ -54,7 +74,7 @@ The selected work is split across parallel jobs:
- **DB tests** — provisions only the isolated `portos_test` database and runs
the serial DB suite when database-sensitive files changed.
- **Windows server tests** — the same server selection, but only on full CI
- (push to `main`, nightly, release, workflow dispatch) or when a
+ (the `main` → `release` PR, nightly, release, workflow dispatch) or when a
Windows-sensitive surface changed (`.ps1` / `.cmd` spawn, PowerShell BOM,
`bufferedSpawn`, `cos-runner`, shell/PM2, etc.). Docs-only and ordinary
Linux-faithful PRs skip this job. `pinPlatform('win32')` tests still run on
@@ -76,10 +96,15 @@ JSON argument array to `spawnSync`, never through shell interpolation.
The complete server, client, DB, lint, build, and smoke suite runs:
-- after every push to `main`;
+- on every pull request whose base branch is `release` (the release gate);
- nightly at 09:17 UTC;
- from manual workflow dispatch;
-- as a reusable workflow called by every release.
+- as a reusable workflow called by a release whose tree has no verifiable gate.
+
+There is **no push trigger on `main`**. A merge commit on `main` re-tests a
+tree whose PR gate is already green, so the run was pure duplication; the
+nightly full run is what catches a semantic conflict between two independently
+green PRs, and the `main` → `release` PR catches it before a release ships.
Changes to CI/test configuration also force the full suite on their own PR.
`[skip ci]` remains honored for push events only; PR CI always runs.
@@ -103,17 +128,35 @@ Changes to CI/test configuration also force the full suite on their own PR.
Triggers on push to `release` branch. Steps:
-1. Calls `ci.yml` with `full: true` and waits for the complete CI gate.
-2. Reads version from `package.json`.
-3. Checks if the git tag already exists (skips release creation if so).
-4. Looks for a changelog file:
+1. Runs `scripts/verify-ci-status.js` to look for a full CI run that already
+ covered this exact tree (see below).
+2. Calls `ci.yml` with `full: true` **only if** step 1 found nothing.
+3. Reads version from `package.json`.
+4. Checks if the git tag already exists (skips release creation if so).
+5. Looks for a changelog file:
- First: `.changelog/v{version}.md` (exact match)
- Then: `.changelog/v{major}.{minor}.x.md` (pattern match, replaces placeholders)
- Fallback: generates changelog from commit messages
-5. Creates the GitHub release with tag `v{version}`.
-6. If a pattern changelog file (`.changelog/v{major}.{minor}.x.md`) was used,
+6. Creates the GitHub release with tag `v{version}`.
+7. If a pattern changelog file (`.changelog/v{major}.{minor}.x.md`) was used,
archives it on `main` (renames `.x.md` to the exact version).
-7. If the archive step ran, fast-forwards `release` to match `main`.
+8. If the archive step ran, fast-forwards `release` to match `main`.
+
+### Reusing the release PR's CI run
+
+`scripts/verify-ci-status.js` decides whether the push already has a green
+gate. The rule is **content-based, not SHA-based**: a commit vouches for this
+push only when its git tree is byte-identical to the tree being released *and*
+it carries a completed, successful `CI Gate` check run. It considers the pushed
+commit itself and its direct parents.
+
+The ordinary release merge satisfies this — `release` is strictly behind
+`main`, so the merge commit's tree equals the `main` tip it merged, and that
+tip is exactly the SHA the release PR ran full CI on.
+
+Everything else fails closed and runs the complete suite again: a direct push to
+`release`, a hotfix committed on `release` that changes the merge tree, a
+missing or failed gate, or an unreachable checks API.
## Working with CI
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index 82c340fa82..8256197492 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -33,7 +33,7 @@ const FULL_TRIGGER_RULES = [
// Files whose Windows behavior is not faithfully exercised by pinPlatform()
// stubs on Linux: real .cmd spawn, PowerShell BOM, PTY wrap, path.basename
// on backslashes. A PR that does not touch these still gets a full Windows
-// run on main / nightly / release.
+// run nightly, on the main -> release PR, and on release.
const WINDOWS_RISK_RULES = [
/\.(?:ps1|cmd|bat)$/i,
/^scripts\/fix-windows-console(?:\.test)?\.js$/,
diff --git a/scripts/verify-ci-status.js b/scripts/verify-ci-status.js
new file mode 100644
index 0000000000..c00306d10a
--- /dev/null
+++ b/scripts/verify-ci-status.js
@@ -0,0 +1,125 @@
+#!/usr/bin/env node
+
+// Decides whether the commit being released was ALREADY validated by a full CI
+// run, so the release workflow does not repeat the ~8-minute suite the
+// main -> release pull request just finished.
+//
+// The rule is content-based, not SHA-based: a candidate commit verifies this
+// push only when its git tree is byte-identical to the tree being released AND
+// it carries a completed, successful "CI Gate" check run. A merge commit on
+// `release` has the same tree as the `main` tip it merged (release is strictly
+// behind main), and that tip is exactly the SHA the release PR ran full CI on.
+//
+// Anything else — a direct push to `release`, a merge that changed the tree, a
+// missing or failed gate, an unreachable API — reports `verified=false`, and
+// the release workflow falls back to running the complete suite.
+
+import { spawnSync } from 'child_process';
+import { appendFileSync } from 'fs';
+import { fileURLToPath } from 'url';
+import { resolve } from 'path';
+
+export const CI_GATE_CHECK_NAME = 'CI Gate';
+
+/** Parent SHAs from a raw `git cat-file -p <commit>` payload. */
+export function parseCommitParents(commitObject) {
+ // The header ends at the first blank line. Stop there, or a commit message
+ // body line beginning with "parent " would forge a candidate.
+ const lines = String(commitObject || '').split('\n');
+ const headerEnd = lines.indexOf('');
+ return lines
+ .slice(0, headerEnd === -1 ? lines.length : headerEnd)
+ .filter((line) => line.startsWith('parent '))
+ .map((line) => line.slice('parent '.length).trim())
+ .filter(Boolean);
+}
+
+/** The completed, successful CI gate in a `/check-runs` payload, or null. */
+export function findPassingGate(checkRuns, gateName = CI_GATE_CHECK_NAME) {
+ const runs = Array.isArray(checkRuns) ? checkRuns : [];
+ return runs.find((run) => (
+ run?.name === gateName
+ && run?.status === 'completed'
+ && run?.conclusion === 'success'
+ )) || null;
+}
+
+/**
+ * Pick the commit whose green CI gate vouches for `headTree`.
+ *
+ * @param {Array<{sha: string, tree: string|null, checkRuns: Array}>} candidates
+ * @param {string} headTree tree SHA of the commit being released
+ */
+export function selectVerifiedCommit(candidates, headTree, gateName = CI_GATE_CHECK_NAME) {
+ if (!headTree) return null;
+ for (const candidate of candidates) {
+ if (!candidate?.tree || candidate.tree !== headTree) continue;
+ const gate = findPassingGate(candidate.checkRuns, gateName);
+ if (gate) return { sha: candidate.sha, gate };
+ }
+ return null;
+}
+
+const capture = (command, args) => {
+ const result = spawnSync(command, args, { encoding: 'utf8' });
+ if (result.error || result.status !== 0) return null;
+ return result.stdout.trim();
+};
+
+const gitTree = (sha) => capture('git', ['rev-parse', `${sha}^{tree}`]);
+
+function fetchCheckRuns(repo, sha) {
+ const body = capture('gh', ['api', `repos/${repo}/commits/${sha}/check-runs?per_page=100`]);
+ if (!body) {
+ console.warn(`⚠️ Could not read check runs for ${sha.slice(0, 8)}.`);
+ return [];
+ }
+ return JSON.parse(body).check_runs || [];
+}
+
+const writeOutput = (name, value) => {
+ if (!process.env.GITHUB_OUTPUT) return;
+ appendFileSync(process.env.GITHUB_OUTPUT, `${name}=${String(value)}\n`);
+};
+
+function emit(verified, sha, reason) {
+ writeOutput('verified', verified);
+ writeOutput('sha', sha);
+ writeOutput('reason', reason);
+}
+
+function main() {
+ const repo = process.env.GITHUB_REPOSITORY;
+ const head = process.env.GITHUB_SHA || capture('git', ['rev-parse', 'HEAD']);
+ if (!repo || !head) {
+ console.log('❔ No repository or head SHA available — requiring a full CI run.');
+ emit(false, '', 'missing repository or head SHA');
+ return;
+ }
+
+ const headTree = gitTree(head);
+ const commitObject = capture('git', ['cat-file', '-p', head]) || '';
+ // HEAD first: a workflow_dispatch or re-run may have gated this exact SHA.
+ // Parents are content-checked too, so the previous release tip cannot vouch
+ // for a merge that actually changed the tree.
+ const candidates = [head, ...parseCommitParents(commitObject)].map((sha) => {
+ const tree = gitTree(sha);
+ return { sha, tree, checkRuns: tree === headTree ? fetchCheckRuns(repo, sha) : [] };
+ });
+
+ const verified = selectVerifiedCommit(candidates, headTree);
+ if (verified) {
+ const short = verified.sha.slice(0, 8);
+ console.log(`✅ CI Gate already passed on ${short} with this exact tree — skipping the full suite.`);
+ emit(true, verified.sha, `CI Gate succeeded on ${short} with an identical tree`);
+ return;
+ }
+
+ console.log('🧪 No green CI Gate found for this tree — running the full suite.');
+ emit(false, '', 'no successful CI Gate found for this tree');
+}
+
+const isMain = process.argv[1]
+ && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url));
+
+if (isMain) main();
diff --git a/scripts/verify-ci-status.test.js b/scripts/verify-ci-status.test.js
new file mode 100644
index 0000000000..8adb060212
--- /dev/null
+++ b/scripts/verify-ci-status.test.js
@@ -0,0 +1,99 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ CI_GATE_CHECK_NAME,
+ findPassingGate,
+ parseCommitParents,
+ selectVerifiedCommit,
+} from './verify-ci-status.js';
+
+const passingGate = { name: CI_GATE_CHECK_NAME, status: 'completed', conclusion: 'success' };
+
+const mergeCommit = [
+ 'tree 1111111111111111111111111111111111111111',
+ 'parent aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+ 'parent bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
+ 'author github-actions <[email protected]> 0 +0000',
+ 'committer github-actions <[email protected]> 0 +0000',
+ '',
+ 'Merge pull request #1 from example/main',
+].join('\n');
+
+describe('parseCommitParents', () => {
+ it('reads both parents of a merge commit', () => {
+ expect(parseCommitParents(mergeCommit)).toEqual([
+ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+ 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
+ ]);
+ });
+
+ it('stops at the header so a commit message cannot forge a parent', () => {
+ const forged = [
+ 'tree 1111111111111111111111111111111111111111',
+ 'parent aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+ '',
+ 'parent cccccccccccccccccccccccccccccccccccccccc',
+ ].join('\n');
+
+ expect(parseCommitParents(forged)).toEqual(['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']);
+ });
+
+ it('returns nothing for a root commit or empty input', () => {
+ expect(parseCommitParents('tree 1111\nauthor a <[email protected]> 0 +0000\n\nroot')).toEqual([]);
+ expect(parseCommitParents('')).toEqual([]);
+ expect(parseCommitParents(null)).toEqual([]);
+ });
+});
+
+describe('findPassingGate', () => {
+ it('only accepts a completed successful gate under the exact name', () => {
+ expect(findPassingGate([passingGate])).toEqual(passingGate);
+ expect(findPassingGate([{ ...passingGate, conclusion: 'failure' }])).toBeNull();
+ expect(findPassingGate([{ ...passingGate, status: 'in_progress', conclusion: null }])).toBeNull();
+ expect(findPassingGate([{ ...passingGate, name: 'lint' }])).toBeNull();
+ expect(findPassingGate([])).toBeNull();
+ expect(findPassingGate(undefined)).toBeNull();
+ });
+});
+
+describe('selectVerifiedCommit', () => {
+ const headTree = 'tree-head';
+
+ it('accepts the merged branch head when its tree matches', () => {
+ const verified = selectVerifiedCommit([
+ { sha: 'merge', tree: headTree, checkRuns: [] },
+ { sha: 'prev-release', tree: 'tree-old', checkRuns: [passingGate] },
+ { sha: 'main-tip', tree: headTree, checkRuns: [passingGate] },
+ ], headTree);
+
+ expect(verified).toMatchObject({ sha: 'main-tip' });
+ });
+
+ it('refuses a green parent whose tree differs from what is being released', () => {
+ expect(selectVerifiedCommit([
+ { sha: 'merge', tree: headTree, checkRuns: [] },
+ { sha: 'prev-release', tree: 'tree-old', checkRuns: [passingGate] },
+ ], headTree)).toBeNull();
+ });
+
+ it('refuses a same-tree commit whose gate did not pass', () => {
+ expect(selectVerifiedCommit([
+ { sha: 'main-tip', tree: headTree, checkRuns: [{ ...passingGate, conclusion: 'failure' }] },
+ ], headTree)).toBeNull();
+ });
+
+ it('prefers a gate on the released commit itself', () => {
+ const verified = selectVerifiedCommit([
+ { sha: 'merge', tree: headTree, checkRuns: [passingGate] },
+ { sha: 'main-tip', tree: headTree, checkRuns: [passingGate] },
+ ], headTree);
+
+ expect(verified).toMatchObject({ sha: 'merge' });
+ });
+
+ it('fails closed when the head tree could not be resolved', () => {
+ expect(selectVerifiedCommit([
+ { sha: 'main-tip', tree: null, checkRuns: [passingGate] },
+ ], null)).toBeNull();
+ });
+});