From e101b7eb276c69699d4c4cbd6b08b36bcd0e7a94 Mon Sep 17 00:00:00 2001 From: Dizzle <112548150+maxmad64bis@users.noreply.github.com> Date: Sat, 3 Oct 2026 00:19:22 +0200 Subject: [PATCH] ci: run the scheduled workflows only in the upstream repository Scheduled crons skipped outside diegosouzapw/OmniRoute; 21 jobs guarded, check-workflows rule proves it. --- .github/workflows/nightly-compat.yml | 5 +- .github/workflows/nightly-llm-security.yml | 2 + .github/workflows/nightly-mutation.yml | 3 +- .github/workflows/nightly-property.yml | 1 + .github/workflows/nightly-release-green.yml | 8 +- .github/workflows/nightly-resilience.yml | 4 + .github/workflows/nightly-schemathesis.yml | 1 + .github/workflows/radar-export.yml | 1 + .github/workflows/scorecard.yml | 2 +- .github/workflows/test-quarantine.yml | 1 + .../15398-guard-scheduled-workflows.md | 1 + scripts/check/check-workflows.mjs | 128 ++++++++++++++++++ tests/unit/build/check-workflows.test.ts | 114 ++++++++++++++++ 13 files changed, 264 insertions(+), 7 deletions(-) create mode 100644 changelog.d/maintenance/15398-guard-scheduled-workflows.md diff --git a/.github/workflows/nightly-compat.yml b/.github/workflows/nightly-compat.yml index 9515d6b21892..0b940477eebc 100644 --- a/.github/workflows/nightly-compat.yml +++ b/.github/workflows/nightly-compat.yml @@ -27,6 +27,7 @@ concurrency: jobs: resolve-branch: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: Resolve active release branch runs-on: ubuntu-latest outputs: @@ -57,6 +58,7 @@ jobs: echo "target=$TARGET" >> "$GITHUB_OUTPUT" compat-build-26: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: Node 26 Compatibility Build runs-on: ubuntu-latest timeout-minutes: 25 @@ -87,6 +89,7 @@ jobs: OMNIROUTE_USE_TURBOPACK: "0" compat-tests: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: Node ${{ matrix.node }} Compat Tests (${{ matrix.shard }}/4) runs-on: ubuntu-latest timeout-minutes: 25 @@ -117,7 +120,7 @@ jobs: report: name: Open / update tracking issue on failure runs-on: ubuntu-latest - if: ${{ !cancelled() && (needs.compat-tests.result == 'failure' || needs.compat-build-26.result == 'failure') }} + if: ${{ (!cancelled() && (needs.compat-tests.result == 'failure' || needs.compat-build-26.result == 'failure')) && (github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute') }} needs: [resolve-branch, compat-build-26, compat-tests] permissions: issues: write diff --git a/.github/workflows/nightly-llm-security.yml b/.github/workflows/nightly-llm-security.yml index e0631f4f0477..1f74d209f685 100644 --- a/.github/workflows/nightly-llm-security.yml +++ b/.github/workflows/nightly-llm-security.yml @@ -9,6 +9,7 @@ permissions: jobs: promptfoo-guard: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: promptfoo — injection guard (block mode, no secret) # #11965: this job runs a backend-only `next build`; the hosted 7 GB runner cannot build # release/v3.8.51 (VM shutdown ~7 min in), so it targets the box's light pool (`omni-light`: @@ -56,6 +57,7 @@ jobs: run: kill "$(cat server.pid)" || true garak: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: garak probes (skip without provider secret) # #11965: this job runs a backend-only `next build`; the hosted 7 GB runner cannot build # release/v3.8.51 (VM shutdown ~7 min in), so it targets the box's light pool (`omni-light`: diff --git a/.github/workflows/nightly-mutation.yml b/.github/workflows/nightly-mutation.yml index 9ffb5c22b5b4..3c1cf824528f 100644 --- a/.github/workflows/nightly-mutation.yml +++ b/.github/workflows/nightly-mutation.yml @@ -9,6 +9,7 @@ permissions: jobs: stryker: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: Stryker mutation (batch ${{ matrix.batch.name }} — advisory) runs-on: ubuntu-latest # Mutation testing is expensive. History of the budget: @@ -144,7 +145,7 @@ jobs: mutation-ratchet: name: Mutation score ratchet (blocking) needs: stryker - if: always() + if: ${{ always() && (github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute') }} runs-on: ubuntu-latest timeout-minutes: 15 steps: diff --git a/.github/workflows/nightly-property.yml b/.github/workflows/nightly-property.yml index 2ef7a543aff5..ad5c1a6468fc 100644 --- a/.github/workflows/nightly-property.yml +++ b/.github/workflows/nightly-property.yml @@ -8,6 +8,7 @@ permissions: issues: write jobs: property-random-seed: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 diff --git a/.github/workflows/nightly-release-green.yml b/.github/workflows/nightly-release-green.yml index 53f8d15e82d7..99e25fc30e8d 100644 --- a/.github/workflows/nightly-release-green.yml +++ b/.github/workflows/nightly-release-green.yml @@ -65,7 +65,7 @@ jobs: name: Validate active release branch # On a push, only run for release/* pushes — a push to main is handled by the # main-green job below. Schedule/dispatch always run (they validate the highest release). - if: ${{ github.event_name != 'push' || startsWith(github.ref_name, 'release/') }} + if: ${{ (github.event_name != 'push' || startsWith(github.ref_name, 'release/')) && (github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute') }} # Dynamic runner: with USE_VPS_RUNNER=true (release window / on-demand pre-flight) # this runs on the dedicated VPS runner — clean env (no operator OMNIROUTE_API_KEY, # no local noauth CLIs => zero machine-specific false positives) and no contention. @@ -275,7 +275,7 @@ jobs: name: Validate main branch # On a push, only run for a push to main — a push to release/* is handled by # release-green above. Schedule/dispatch always run (they also sweep main). - if: ${{ github.event_name != 'push' || github.ref_name == 'main' }} + if: ${{ (github.event_name != 'push' || github.ref_name == 'main') && (github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute') }} runs-on: ${{ (vars.USE_VPS_RUNNER == 'true' && fromJSON('["self-hosted","omni-build"]')) || 'ubuntu-latest' }} env: JWT_SECRET: ci-nightly-secret-with-sufficient-length-for-validation @@ -436,7 +436,7 @@ jobs: # walk each time. Detection stays on push (release-green above); banking is batched. bank-ratchet-shrinks: name: Bank ratchet shrinks - if: ${{ github.event_name != 'push' }} + if: ${{ github.event_name != 'push' && (github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute') }} runs-on: ubuntu-latest permissions: contents: write @@ -567,7 +567,7 @@ jobs: # first red PR. Advisory: never fails the workflow. baseline-headroom: name: Baseline headroom - if: ${{ github.event_name != 'push' }} + if: ${{ github.event_name != 'push' && (github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute') }} timeout-minutes: 60 runs-on: ${{ (vars.USE_VPS_RUNNER == 'true' && fromJSON('["self-hosted","omni-light"]')) || 'ubuntu-latest' }} permissions: diff --git a/.github/workflows/nightly-resilience.yml b/.github/workflows/nightly-resilience.yml index 0961791828fd..516bd8aa06b3 100644 --- a/.github/workflows/nightly-resilience.yml +++ b/.github/workflows/nightly-resilience.yml @@ -9,6 +9,7 @@ permissions: jobs: heap: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: Heap-growth gate runs-on: ubuntu-latest steps: @@ -23,6 +24,7 @@ jobs: - run: npm run test:heap chaos: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: Resilience chaos (fault injection) runs-on: ubuntu-latest steps: @@ -37,6 +39,7 @@ jobs: - run: npm run test:chaos k6-soak: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: k6 load/soak runs-on: ubuntu-latest steps: @@ -77,6 +80,7 @@ jobs: run: kill "$(cat server.pid)" || true a11y: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: A11y axe (nightly, freeze-and-alert) # #11965: this job runs a backend-only `next build`; the hosted 7 GB runner cannot build # release/v3.8.51 (VM shutdown ~7 min in), so it targets the box's light pool (`omni-light`: diff --git a/.github/workflows/nightly-schemathesis.yml b/.github/workflows/nightly-schemathesis.yml index 33ec974698b0..4a7b02adcdc5 100644 --- a/.github/workflows/nightly-schemathesis.yml +++ b/.github/workflows/nightly-schemathesis.yml @@ -9,6 +9,7 @@ permissions: jobs: schemathesis: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} name: Schemathesis — OpenAPI contract fuzz (advisory) # #11965: this job runs a backend-only `next build`; the hosted 7 GB runner cannot build # release/v3.8.51 (VM shutdown ~7 min in), so it targets the box's light pool (`omni-light`: diff --git a/.github/workflows/radar-export.yml b/.github/workflows/radar-export.yml index 18f29e4d60c1..d93113104835 100644 --- a/.github/workflows/radar-export.yml +++ b/.github/workflows/radar-export.yml @@ -39,6 +39,7 @@ env: jobs: publish-export: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} runs-on: ubuntu-latest permissions: contents: write # gh release upload — clobra o asset estável do export diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 0f46beefbeb1..202a5f277ed3 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -12,7 +12,7 @@ permissions: read-all jobs: analysis: - if: ${{ github.event_name != 'push' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} + if: ${{ (github.event_name != 'push' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) && (github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute') }} name: Scorecard analysis runs-on: ubuntu-latest permissions: diff --git a/.github/workflows/test-quarantine.yml b/.github/workflows/test-quarantine.yml index 0e89add9d5c5..05b7003aa9d0 100644 --- a/.github/workflows/test-quarantine.yml +++ b/.github/workflows/test-quarantine.yml @@ -15,6 +15,7 @@ concurrency: jobs: quarantine: + if: ${{ github.event_name != 'schedule' || github.repository == 'diegosouzapw/OmniRoute' }} runs-on: ubuntu-latest timeout-minutes: 20 steps: diff --git a/changelog.d/maintenance/15398-guard-scheduled-workflows.md b/changelog.d/maintenance/15398-guard-scheduled-workflows.md new file mode 100644 index 000000000000..3d163041ae34 --- /dev/null +++ b/changelog.d/maintenance/15398-guard-scheduled-workflows.md @@ -0,0 +1 @@ +- **ci:** scheduled workflows now run only in the upstream repository, so forks with Actions enabled skip the inherited crons ([#15398](https://github.com/diegosouzapw/OmniRoute/pull/15398)) — thanks @maxmad64bis diff --git a/scripts/check/check-workflows.mjs b/scripts/check/check-workflows.mjs index 3384f3cdba6b..439910c7478a 100644 --- a/scripts/check/check-workflows.mjs +++ b/scripts/check/check-workflows.mjs @@ -40,6 +40,7 @@ import { execFileSync, spawnSync } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { pathToFileURL } from "node:url"; +import { load as yamlLoad } from "js-yaml"; import { findProvenanceOnSelfHosted, formatProvenanceFinding } from "./lib/provenanceRunner.mjs"; const ROOT = process.cwd(); @@ -282,6 +283,112 @@ export function runZizmor(workflowsDir) { // Main // --------------------------------------------------------------------------- +// --------------------------------------------------------------------------- +// Scheduled-run guard: scheduled executions stay in the upstream repository +// --------------------------------------------------------------------------- + +const SCHEDULED_GUARD_EVENT = "github.event_name != 'schedule'"; +const SCHEDULED_GUARD_REPO = "github.repository"; + +/** + * Reads the trigger section of a parsed workflow document. The `on` key is + * read defensively (`doc[true] ?? doc["on"]`) so both YAML 1.1 (boolean true) + * and YAML 1.2 (string "on") parses stay green across parser versions. + * @param {unknown} doc parsed workflow document + * @returns {unknown} the `on` section, or undefined + */ +function readTriggerSection(doc) { + if (!doc || typeof doc !== "object") return undefined; + const record = /** @type {Record} */ (doc); + return record[true] ?? record["on"]; +} + +/** + * Whether a parsed trigger section declares a `schedule` trigger. Accepts the + * object form (`schedule:` with cron entries), the bare string form, and the + * array form of `on:`. + * @param {unknown} onSection parsed `on` section + * @returns {boolean} + */ +function hasScheduleTrigger(onSection) { + if (onSection == null) return false; + if (typeof onSection === "string") return onSection === "schedule"; + if (Array.isArray(onSection)) return onSection.includes("schedule"); + if (typeof onSection !== "object") return false; + return Object.prototype.hasOwnProperty.call(onSection, "schedule"); +} + +/** + * Whether a job-level `if` carries the upstream-only scheduled-run guard. + * @param {unknown} condition the job's `if` value + * @returns {boolean} + */ +function hasScheduledGuard(condition) { + return ( + typeof condition === "string" && + condition.includes(SCHEDULED_GUARD_EVENT) && + condition.includes(SCHEDULED_GUARD_REPO) + ); +} + +/** + * Lists scheduled jobs missing the upstream-only guard. Fail-closed: an + * unreadable file, invalid YAML, or a document without a usable `jobs` map is + * reported, never silently accepted. A workflow without a `schedule` trigger + * reports nothing. Never throws for these cases; a non-array argument is a + * usage error and still throws. + * @param {string[]} files absolute workflow paths + * @returns {{ file: string, job: string, reason: string }[]} + */ +export function findScheduledJobsWithoutGuard(files) { + if (!Array.isArray(files)) throw new TypeError("files must be an array"); + const findings = []; + for (const file of files) { + let text; + try { + text = fs.readFileSync(file, "utf8"); + } catch { + findings.push({ file, job: "", reason: "unreadable or missing jobs" }); + continue; + } + let doc; + try { + doc = yamlLoad(text); + } catch { + findings.push({ file, job: "", reason: "unreadable or missing jobs" }); + continue; + } + if (!hasScheduleTrigger(readTriggerSection(doc))) continue; + const jobs = doc && typeof doc === "object" ? doc.jobs : undefined; + if (!jobs || typeof jobs !== "object" || Array.isArray(jobs)) { + findings.push({ file, job: "", reason: "unreadable or missing jobs" }); + continue; + } + for (const [jobName, job] of Object.entries(jobs)) { + if (!job || typeof job !== "object" || Array.isArray(job)) { + findings.push({ file, job: jobName, reason: "unreadable or missing jobs" }); + continue; + } + if (!hasScheduledGuard(job.if)) { + findings.push({ file, job: jobName, reason: "scheduled job without upstream guard" }); + } + } + } + return findings; +} + +/** + * Runs the scheduled-run guard over the given workflow files. + * @param {string[]} files absolute workflow paths + * @returns {{ file: string, job: string, reason: string }[]} + */ +export function runScheduledGuardCheck(files) { + return findScheduledJobsWithoutGuard(files).map((f) => ({ + ...f, + file: path.relative(ROOT, f.file), + })); +} + /** * Hard rule (not a lint count): `--provenance` inside a job that runs on a * self-hosted runner. npm answers 422 at the registry, and in v3.8.50 that @@ -383,6 +490,18 @@ function main() { // version that produced it. See zizmorVersion(). process.stdout.write(`zizmorVersion=${scannerVersion}\n`); process.stdout.write(`provenanceRunnerFindings=${provenanceFindings.length}\n`); + const scheduledGuardFindings = runScheduledGuardCheck(workflowFiles); + if (scheduledGuardFindings.length > 0) { + console.error( + `[check-workflows] scheduled-guard: ${scheduledGuardFindings.length} finding(s) — HARD RULE:` + ); + scheduledGuardFindings.forEach((f) => + console.error(` ${f.file}: job "${f.job}" — ${f.reason}`) + ); + } else if (!QUIET) { + console.log("[check-workflows] scheduled-guard: OK (0 findings)"); + } + process.stdout.write(`scheduledGuardFindings=${scheduledGuardFindings.length}\n`); if ((STRICT || RATCHET) && provenanceFindings.length > 0) { console.error( `\n[check-workflows] FAIL — ${provenanceFindings.length} job(s) publish with --provenance from a self-hosted runner.\n` + @@ -392,6 +511,15 @@ function main() { process.exit(1); } + if ((STRICT || RATCHET) && scheduledGuardFindings.length > 0) { + console.error( + `\n[check-workflows] FAIL — ${scheduledGuardFindings.length} scheduled job(s) without the upstream-only guard.\n` + + " Scheduled runs must stay in diegosouzapw/OmniRoute: keep the job-level `if:` naming both\n" + + " `github.event_name != 'schedule'` and `github.repository`." + ); + process.exit(1); + } + if (STRICT && total > 0) { console.error(`\n[check-workflows] FAIL — ${total} workflow finding(s) total (--strict mode).`); process.exit(1); diff --git a/tests/unit/build/check-workflows.test.ts b/tests/unit/build/check-workflows.test.ts index cbd8f1a8ce8c..48c0c0837476 100644 --- a/tests/unit/build/check-workflows.test.ts +++ b/tests/unit/build/check-workflows.test.ts @@ -17,6 +17,7 @@ import assert from "node:assert/strict"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; +import { fileURLToPath } from "node:url"; import { parseActionlintOutput, parseZizmorOutput, @@ -24,6 +25,8 @@ import { isBinaryAvailable, evaluateZizmorRatchet, readBaselineZizmorValue, + runScheduledGuardCheck, + findScheduledJobsWithoutGuard, // @ts-expect-error — .mjs helper has no type declarations; runtime shape is known. } from "../../../scripts/check/check-workflows.mjs"; @@ -34,6 +37,117 @@ const evaluateZizmor = evaluateZizmorRatchet as ( ) => RatchetVerdict; const readZizmorBaseline = readBaselineZizmorValue as (p?: string) => number | null; const qualityWorkflowPath = new URL("../../../.github/workflows/quality.yml", import.meta.url); +const scheduledGuard = findScheduledJobsWithoutGuard as ( + files: string[] +) => { file: string; job: string; reason: string }[]; + +// ───────────────────────────────────────────────────────────────────────────── +// scheduled-run guard — every scheduled workflow runs only in the upstream repo +// ───────────────────────────────────────────────────────────────────────────── + +const EXPECTED_SCHEDULED_WORKFLOWS = [ + "nightly-compat.yml", + "nightly-llm-security.yml", + "nightly-mutation.yml", + "nightly-property.yml", + "nightly-release-green.yml", + "nightly-resilience.yml", + "nightly-schemathesis.yml", + "radar-export.yml", + "scorecard.yml", + "test-quarantine.yml", +]; + +function readWorkflowFiles(): string[] { + return collectWorkflowFiles( + fileURLToPath(new URL("../../../.github/workflows", import.meta.url)) + ) as unknown as string[]; +} + +test("scheduled runs carry the upstream-only guard on every job", () => { + const dir = new URL("../../../.github/workflows/", import.meta.url); + const files = EXPECTED_SCHEDULED_WORKFLOWS.map((f) => new URL(f, dir).pathname); + assert.ok(readWorkflowFiles().length >= files.length); + const findings = scheduledGuard(files); + assert.deepEqual(findings, []); +}); + +test("a scheduled job without the guard is reported", () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "check-workflows-guard-")); + try { + fs.writeFileSync( + path.join(dir, "nightly-demo.yml"), + "on:\n schedule:\n - cron: '0 0 * * *'\njobs:\n demo:\n runs-on: ubuntu-latest\n steps:\n - run: echo hi\n" + ); + const findings = scheduledGuard([path.join(dir, "nightly-demo.yml")]); + assert.equal(findings.length, 1); + assert.equal(findings[0].job, "demo"); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } +}); + +test("an unreadable scheduled workflow is reported, never silently accepted", () => { + const findings = scheduledGuard([ + path.join(os.tmpdir(), "check-workflows-guard-missing-99999.yml"), + ]); + assert.equal(findings.length, 1); +}); + +test("invalid yaml and workflows without jobs are reported, never silently accepted", () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "check-workflows-guard-")); + try { + fs.writeFileSync(path.join(dir, "broken.yml"), "on:\n schedule:\n\t- broken: [unclosed\n"); + fs.writeFileSync(path.join(dir, "no-jobs.yml"), "on:\n schedule:\n - cron: '0 0 * * *'\n"); + assert.equal(scheduledGuard([path.join(dir, "broken.yml")]).length, 1); + assert.equal(scheduledGuard([path.join(dir, "no-jobs.yml")]).length, 1); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } +}); + +test("the guard lets manual and push runs through anywhere, schedule only upstream", () => { + const evaluate = (eventName: string, repository: string) => + eventName !== "schedule" || repository === "diegosouzapw/OmniRoute"; + assert.equal(evaluate("workflow_dispatch", "someone/else"), true); + assert.equal(evaluate("push", "someone/else"), true); + assert.equal(evaluate("schedule", "diegosouzapw/OmniRoute"), true); + assert.equal(evaluate("schedule", "someone/else"), false); +}); + +test("a workflow without a schedule trigger reports nothing", () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "check-workflows-guard-")); + try { + fs.writeFileSync( + path.join(dir, "push-only.yml"), + "on:\n push:\n branches: [main]\njobs:\n demo:\n runs-on: ubuntu-latest\n steps:\n - run: echo hi\n" + ); + assert.deepEqual(scheduledGuard([path.join(dir, "push-only.yml")]), []); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } +}); + +test("the scheduled-guard check reports repository-relative paths", () => { + const runCheck = runScheduledGuardCheck as (files: string[]) => { + file: string; + job: string; + reason: string; + }[]; + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "check-workflows-guard-")); + try { + const file = path.join(dir, "nightly-demo.yml"); + fs.writeFileSync( + file, + "on:\n schedule:\n - cron: '0 0 * * *'\njobs:\n demo:\n runs-on: ubuntu-latest\n steps:\n - run: echo hi\n" + ); + const findings = runCheck([file]); + assert.equal(findings.length, 1); + assert.ok(!path.isAbsolute(findings[0].file)); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } +}); function readQualityWorkflow(): string { return fs.readFileSync(qualityWorkflowPath, "utf8");