diff --git a/.changeset/skip-storyboards-on-draft-prs.md b/.changeset/skip-storyboards-on-draft-prs.md new file mode 100644 index 00000000000..f48d3e90447 --- /dev/null +++ b/.changeset/skip-storyboards-on-draft-prs.md @@ -0,0 +1,5 @@ +--- +"adcontextprotocol": patch +--- + +Skip the training-agent storyboard CI matrix on draft pull requests and run it when a draft is marked ready for review. Push runs and non-draft PRs are unchanged, and so are storyboard selection and floors. diff --git a/.github/workflows/broken-links.yml b/.github/workflows/broken-links.yml index 71d74d48514..4ff6509b524 100644 --- a/.github/workflows/broken-links.yml +++ b/.github/workflows/broken-links.yml @@ -62,6 +62,12 @@ on: types: - completed +# Cancel a PR's superseded run when a newer commit is pushed. Non-PR runs +# each get their own group (run_id), so they are never cancelled or evicted. +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: broken-links: runs-on: ubuntu-latest diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 382791d4ef6..fd03c19ded1 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -8,6 +8,13 @@ on: schedule: - cron: "0 0 * * 0" +# Cancel a PR's superseded analysis when a newer commit is pushed. Push and +# schedule runs each get their own group (run_id), so main-branch analyses are +# never cancelled or evicted. +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: analyze: name: Analyze diff --git a/.github/workflows/migration-smoke-test.yml b/.github/workflows/migration-smoke-test.yml index cf52d2050da..2bcc4cd944f 100644 --- a/.github/workflows/migration-smoke-test.yml +++ b/.github/workflows/migration-smoke-test.yml @@ -28,6 +28,12 @@ on: - "server/tsconfig.json" - "Dockerfile" +# Cancel a PR's superseded run when a newer commit is pushed. Non-PR runs +# each get their own group (run_id), so they are never cancelled or evicted. +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: migrate: name: Built migrations against Postgres diff --git a/.github/workflows/semgrep.yml b/.github/workflows/semgrep.yml index 802c490fa50..f6de6b92118 100644 --- a/.github/workflows/semgrep.yml +++ b/.github/workflows/semgrep.yml @@ -9,6 +9,12 @@ on: permissions: contents: read +# Cancel a PR's superseded scan when a newer commit is pushed. Push runs each +# get their own group (run_id), so main-branch scans are never cancelled. +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: semgrep: name: Scan diff --git a/.github/workflows/training-agent-storyboards.yml b/.github/workflows/training-agent-storyboards.yml index 8d48996c503..b4f1a47bafc 100644 --- a/.github/workflows/training-agent-storyboards.yml +++ b/.github/workflows/training-agent-storyboards.yml @@ -3,6 +3,12 @@ name: Training Agent Storyboards on: pull_request: branches: [main, '3.2.x', '3.1.x', '3.0.x'] + # Draft PRs skip this matrix (see the job-level `if`s): it is ~22 jobs and + # ~200 runner-minutes per push, about half of the repo's Actions minutes, + # against an org-wide hosted-runner concurrency cap. `ready_for_review` + # runs the full matrix when a draft is marked ready. This workflow is not + # a required check, so skipped draft runs never block a merge. + types: [opened, synchronize, reopened, ready_for_review] paths: - 'server/src/training-agent/**' - 'server/src/services/hosted-compliance-version.ts' @@ -49,6 +55,8 @@ concurrency: jobs: storyboards: name: Storyboards (${{ matrix.surface }} /${{ matrix.tenant }}) + # Skip draft PRs; push events have no pull_request payload and always run. + if: github.event.pull_request.draft != true runs-on: ubuntu-latest timeout-minutes: 30 strategy: @@ -536,6 +544,7 @@ jobs: sales_storyboard_orchestrators: name: Sales storyboard orchestrator (${{ matrix.orchestrator }}/8) + if: github.event.pull_request.draft != true runs-on: ubuntu-latest timeout-minutes: 30 strategy: @@ -606,7 +615,7 @@ jobs: sales_storyboards: name: Storyboards (current /sales) - if: always() + if: always() && github.event.pull_request.draft != true needs: sales_storyboard_orchestrators runs-on: ubuntu-latest timeout-minutes: 10 diff --git a/tests/ci-runner-demand-workflows.test.mjs b/tests/ci-runner-demand-workflows.test.mjs new file mode 100644 index 00000000000..28519c032f5 --- /dev/null +++ b/tests/ci-runner-demand-workflows.test.mjs @@ -0,0 +1,42 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { describe, it, expect } from 'vitest'; +import YAML from 'yaml'; + +// The org's hosted runners are capped at 60 concurrent jobs shared across +// every AAO repo. These guards keep the heaviest PR workflows from spending +// that capacity on drafts and superseded commits. +const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const load = (name) => YAML.parse(fs.readFileSync(path.join(repoRoot, '.github/workflows', name), 'utf8')); + +describe('training-agent-storyboards.yml draft skipping', () => { + const wf = load('training-agent-storyboards.yml'); + + it('re-runs when a draft is marked ready for review', () => { + expect(wf.on.pull_request.types).toEqual(['opened', 'synchronize', 'reopened', 'ready_for_review']); + }); + + it('skips every job on draft PRs', () => { + for (const [id, job] of Object.entries(wf.jobs)) { + expect(job.if, `${id} must skip drafts`).toContain('github.event.pull_request.draft != true'); + } + }); +}); + +describe.each([ + ['codeql.yml'], + ['semgrep.yml'], + ['broken-links.yml'], + ['migration-smoke-test.yml'], +])('%s superseded-run cancellation', (name) => { + const wf = load(name); + + it('cancels only pull_request runs, grouped per PR', () => { + expect(wf.concurrency['cancel-in-progress']).toBe("${{ github.event_name == 'pull_request' }}"); + expect(wf.concurrency.group).toContain('github.event.pull_request.number'); + // Non-PR runs (push to main, schedule, workflow_run) each get a unique + // group so they are never cancelled or evicted from a pending slot. + expect(wf.concurrency.group).toContain('github.run_id'); + }); +});