diff --git a/.github/workflows/cd-built-branch.yml b/.github/workflows/cd-built-branch.yml index be86bff..1f29a89 100644 --- a/.github/workflows/cd-built-branch.yml +++ b/.github/workflows/cd-built-branch.yml @@ -11,6 +11,10 @@ name: CD / Built Branch on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' targets: description: >- JSON array of build target objects. Each needs "dir" (repo-relative; "." for a flat repo) @@ -110,7 +114,7 @@ on: jobs: discover: name: Resolve build targets - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} permissions: contents: read outputs: @@ -292,7 +296,7 @@ jobs: build: name: Build ${{ matrix.name }} needs: [discover] - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} timeout-minutes: 30 # Read-only on purpose: this job runs third-party dependency code, so it must never hold a # writable token. Only publish does, and it runs no dependency code. @@ -416,7 +420,7 @@ jobs: publish: name: Publish to ${{ inputs.target-branch }} needs: [discover, build] - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} timeout-minutes: 10 permissions: contents: write diff --git a/.github/workflows/cd-github-release.yml b/.github/workflows/cd-github-release.yml index d1c4c80..ded32b2 100644 --- a/.github/workflows/cd-github-release.yml +++ b/.github/workflows/cd-github-release.yml @@ -3,6 +3,10 @@ name: CD / GitHub Release on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' tag: description: "Tag that triggered the release, e.g. v1.2.3." type: string @@ -49,7 +53,7 @@ permissions: jobs: release: name: Publish GitHub Release - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} steps: # An empty artifact-name would make download-artifact fetch every artifact in the run. - name: Validate inputs diff --git a/.github/workflows/cd-s3.yml b/.github/workflows/cd-s3.yml index a64554e..30bcc37 100644 --- a/.github/workflows/cd-s3.yml +++ b/.github/workflows/cd-s3.yml @@ -3,6 +3,10 @@ name: CD / S3 Deploy on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' tag: description: "Release tag, e.g. v1.2.3. Used as the versioned object key (.zip)." type: string @@ -41,7 +45,7 @@ permissions: jobs: deploy: name: Upload to S3 - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} steps: # An empty tag would silently upload to '.zip'; an empty artifact-name # downloads every artifact in the run. diff --git a/.github/workflows/cd-wp-org.yml b/.github/workflows/cd-wp-org.yml index e141858..a613809 100644 --- a/.github/workflows/cd-wp-org.yml +++ b/.github/workflows/cd-wp-org.yml @@ -3,6 +3,10 @@ name: CD / WordPress.org Deploy on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' slug: description: "Plugin slug on wordpress.org (the directory under plugins.svn.wordpress.org)." type: string @@ -44,7 +48,7 @@ permissions: jobs: deploy: name: Deploy to WordPress.org - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} steps: # An empty slug would fall back to the deploy action's repo-name default and # deploy to the wrong plugin; an empty artifact-name downloads every artifact. diff --git a/.github/workflows/ci-build-artifact-gate.yml b/.github/workflows/ci-build-artifact-gate.yml index 882f2c9..be19a7b 100644 --- a/.github/workflows/ci-build-artifact-gate.yml +++ b/.github/workflows/ci-build-artifact-gate.yml @@ -3,6 +3,10 @@ name: CI / Build Artifact Gate on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' gated-paths: description: "Newline-separated path prefixes whose contents must not be committed in a PR." type: string @@ -18,7 +22,7 @@ permissions: jobs: build-artifact-gate: name: Block committed build artifacts - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} steps: - name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 9dab2ff..6ab8ea2 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -3,6 +3,10 @@ name: CI / Build on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' install-node-deps: description: "Install Node dependencies before the build." type: boolean @@ -54,7 +58,7 @@ permissions: jobs: build: name: Build - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} defaults: run: working-directory: ${{ inputs.working-dir }} diff --git a/.github/workflows/ci-detect-changes.yml b/.github/workflows/ci-detect-changes.yml index 9798e2f..29f7393 100644 --- a/.github/workflows/ci-detect-changes.yml +++ b/.github/workflows/ci-detect-changes.yml @@ -3,6 +3,10 @@ name: CI / Detect Changes on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' node-version: description: "Node.js version used to run the wp-tooling CLI." type: string @@ -68,7 +72,7 @@ permissions: jobs: detect: name: Detect changes - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} outputs: # css/js/php come from the scope step; total/ignored/gha stay repo-wide on detect. total-count: ${{ steps.detect.outputs.total-count }} diff --git a/.github/workflows/ci-lint-css.yml b/.github/workflows/ci-lint-css.yml index 989dd98..0683c7d 100644 --- a/.github/workflows/ci-lint-css.yml +++ b/.github/workflows/ci-lint-css.yml @@ -3,6 +3,10 @@ name: CI / Lint CSS on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' node-version: description: "Node.js version." type: string @@ -26,7 +30,7 @@ permissions: jobs: lint-css: name: Stylelint - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} defaults: run: working-directory: ${{ inputs.working-dir }} diff --git a/.github/workflows/ci-lint-js.yml b/.github/workflows/ci-lint-js.yml index f76fa2b..03da43e 100644 --- a/.github/workflows/ci-lint-js.yml +++ b/.github/workflows/ci-lint-js.yml @@ -3,6 +3,10 @@ name: CI / Lint JS on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' node-version: description: "Node.js version." type: string @@ -30,7 +34,7 @@ permissions: jobs: lint-js: name: ESLint - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} defaults: run: working-directory: ${{ inputs.working-dir }} diff --git a/.github/workflows/ci-lint-php.yml b/.github/workflows/ci-lint-php.yml index 2e5dd56..c6d2dc2 100644 --- a/.github/workflows/ci-lint-php.yml +++ b/.github/workflows/ci-lint-php.yml @@ -3,6 +3,10 @@ name: CI / Lint PHP on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' php-version: description: "PHP version." type: string @@ -46,7 +50,7 @@ permissions: jobs: lint-php: name: Lint PHP - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} defaults: run: working-directory: ${{ inputs.working-dir }} diff --git a/.github/workflows/ci-self-check.yml b/.github/workflows/ci-self-check.yml index 1cdae54..c53d75a 100644 --- a/.github/workflows/ci-self-check.yml +++ b/.github/workflows/ci-self-check.yml @@ -17,7 +17,7 @@ concurrency: jobs: self-check: name: Lint workflows and verify examples - runs-on: [self-hosted] + runs-on: ubuntu-latest env: ACTIONLINT_VERSION: "1.7.12" ACTIONLINT_SHA256: "8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8" diff --git a/.github/workflows/ci-test-a11y.yml b/.github/workflows/ci-test-a11y.yml index 392ab82..77c1e73 100644 --- a/.github/workflows/ci-test-a11y.yml +++ b/.github/workflows/ci-test-a11y.yml @@ -3,6 +3,10 @@ name: CI / Test a11y on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' node-version: description: "Node.js version to install." type: string @@ -26,7 +30,7 @@ permissions: jobs: test-a11y: name: pa11y-ci - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} defaults: run: working-directory: ${{ inputs.working-dir }} diff --git a/.github/workflows/ci-test-build-artifact.yml b/.github/workflows/ci-test-build-artifact.yml index 8aa32b9..dcfa52f 100644 --- a/.github/workflows/ci-test-build-artifact.yml +++ b/.github/workflows/ci-test-build-artifact.yml @@ -3,6 +3,10 @@ name: CI / Test Build Artifact on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' artifact-name: description: "Artifact to download. Must match the artifact-name uploaded by ci-build.yml in the same run." type: string @@ -48,7 +52,7 @@ permissions: jobs: test-build-artifact: name: Boot artifact in wp-env - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} timeout-minutes: 10 defaults: run: diff --git a/.github/workflows/ci-test-js.yml b/.github/workflows/ci-test-js.yml index d431a58..9e4bc97 100644 --- a/.github/workflows/ci-test-js.yml +++ b/.github/workflows/ci-test-js.yml @@ -3,6 +3,10 @@ name: CI / Test JS on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' node-version: description: "Node.js version." type: string @@ -29,7 +33,7 @@ permissions: jobs: test-js: name: Jest - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} defaults: run: working-directory: ${{ inputs.working-dir }} diff --git a/.github/workflows/ci-test-php.yml b/.github/workflows/ci-test-php.yml index d01d39f..900e41f 100644 --- a/.github/workflows/ci-test-php.yml +++ b/.github/workflows/ci-test-php.yml @@ -3,6 +3,10 @@ name: CI / Test PHP on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' php-version: description: "PHP version. Installed on the host (used directly in standalone mode) and passed to wp-env as WP_ENV_PHP_VERSION so the container runs the same version." type: string @@ -40,7 +44,7 @@ permissions: jobs: test-php: name: PHPUnit - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} # Pin the wp-env container's PHP/WordPress core via env: (not $GITHUB_ENV, which is # newline-injectable) at job scope, so start/run/stop resolve the same environment. # An empty WP_ENV_CORE is ignored by wp-env (falls back to the consumer's .wp-env.json). diff --git a/.github/workflows/version-monitor.yml b/.github/workflows/version-monitor.yml index 8d16fe8..d48da83 100644 --- a/.github/workflows/version-monitor.yml +++ b/.github/workflows/version-monitor.yml @@ -3,6 +3,10 @@ name: Version Monitor on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' node-version: description: "Node.js version used to install and run wp-tooling" type: string @@ -35,7 +39,7 @@ concurrency: jobs: version-monitor: name: Check for version bumps - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} timeout-minutes: 20 permissions: contents: write diff --git a/.github/workflows/wp-cd.yml b/.github/workflows/wp-cd.yml index 75338f2..af5a0de 100644 --- a/.github/workflows/wp-cd.yml +++ b/.github/workflows/wp-cd.yml @@ -3,6 +3,10 @@ name: CD / Orchestrator on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' tag: description: "Release tag that triggered the deploy, e.g. v1.2.3. Forwarded to every target." type: string @@ -93,7 +97,7 @@ jobs: # deploy nothing, and a missing input/secret would fail mid-deploy. validate-inputs: name: Validate inputs - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} steps: - name: Check deploy targets and their required inputs and secrets env: @@ -158,6 +162,7 @@ jobs: if: contains(format(',{0},', inputs.deploy-target), ',github,') uses: ./.github/workflows/cd-github-release.yml with: + runs-on: ${{ inputs.runs-on }} tag: ${{ inputs.tag }} artifact-name: ${{ inputs.artifact-name }} slug: ${{ inputs.slug }} @@ -172,6 +177,7 @@ jobs: if: contains(format(',{0},', inputs.deploy-target), ',wporg,') uses: ./.github/workflows/cd-wp-org.yml with: + runs-on: ${{ inputs.runs-on }} slug: ${{ inputs.slug }} tag: ${{ inputs.tag }} artifact-name: ${{ inputs.artifact-name }} @@ -188,6 +194,7 @@ jobs: if: contains(format(',{0},', inputs.deploy-target), ',s3,') uses: ./.github/workflows/cd-s3.yml with: + runs-on: ${{ inputs.runs-on }} tag: ${{ inputs.tag }} artifact-name: ${{ inputs.artifact-name }} bucket: ${{ inputs.bucket }} diff --git a/.github/workflows/wp-ci.yml b/.github/workflows/wp-ci.yml index f1fd425..417ba89 100644 --- a/.github/workflows/wp-ci.yml +++ b/.github/workflows/wp-ci.yml @@ -3,6 +3,10 @@ name: CI / Orchestrator on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]." + type: string + default: '"ubuntu-latest"' project-type: description: "Shape of the project at working-dir, selecting the job preset: plugin | theme | package. Describes the one unit this call targets, not the repository." type: string @@ -87,7 +91,7 @@ permissions: jobs: validate-inputs: name: Validate inputs - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} outputs: # Children must consume this, NOT inputs.working-dir: an unnormalised "" or # "./themes/foo" breaks cache-dependency-path and defeats artifact-gate's anchor. @@ -162,6 +166,7 @@ jobs: needs: [validate-inputs] uses: ./.github/workflows/ci-detect-changes.yml with: + runs-on: ${{ inputs.runs-on }} # A path scope, not a cwd — the detector still diffs from the repo root. working-dir: ${{ needs.validate-inputs.outputs.working-dir }} ignore-paths: ${{ inputs.ignore-paths }} @@ -177,6 +182,7 @@ jobs: && !contains(format(',{0},', inputs.skip), ',lint-css,') uses: ./.github/workflows/ci-lint-css.yml with: + runs-on: ${{ inputs.runs-on }} changed-files: ${{ needs.detect-changes.outputs.css-files }} working-dir: ${{ needs.validate-inputs.outputs.working-dir }} @@ -189,6 +195,7 @@ jobs: && !contains(format(',{0},', inputs.skip), ',lint-js,') uses: ./.github/workflows/ci-lint-js.yml with: + runs-on: ${{ inputs.runs-on }} changed-files: ${{ needs.detect-changes.outputs.js-files }} working-dir: ${{ needs.validate-inputs.outputs.working-dir }} @@ -201,6 +208,7 @@ jobs: && !contains(format(',{0},', inputs.skip), ',lint-php,') uses: ./.github/workflows/ci-lint-php.yml with: + runs-on: ${{ inputs.runs-on }} changed-files: ${{ needs.detect-changes.outputs.php-files }} enable-phpstan: ${{ inputs.enable-phpstan }} working-dir: ${{ needs.validate-inputs.outputs.working-dir }} @@ -214,6 +222,7 @@ jobs: && !contains(format(',{0},', inputs.skip), ',test-js,') uses: ./.github/workflows/ci-test-js.yml with: + runs-on: ${{ inputs.runs-on }} working-dir: ${{ needs.validate-inputs.outputs.working-dir }} test-php: @@ -234,6 +243,7 @@ jobs: exclude: ${{ fromJSON(inputs.test-php-exclude) }} uses: ./.github/workflows/ci-test-php.yml with: + runs-on: ${{ inputs.runs-on }} php-version: ${{ matrix.php }} wp-version: ${{ matrix.wp }} use-wp-env: ${{ inputs.use-wp-env }} @@ -248,6 +258,7 @@ jobs: && !contains(format(',{0},', inputs.skip), ',build,') uses: ./.github/workflows/ci-build.yml with: + runs-on: ${{ inputs.runs-on }} # Only upload when build-artifact runs (it consumes this); otherwise build just compiles. upload-artifact: ${{ inputs.build-artifact-path != '' }} artifact-name: ${{ needs.validate-inputs.outputs.artifact-name }} @@ -267,6 +278,7 @@ jobs: && !contains(format(',{0},', inputs.skip), ',build-artifact,') uses: ./.github/workflows/ci-test-build-artifact.yml with: + runs-on: ${{ inputs.runs-on }} artifact-name: ${{ needs.validate-inputs.outputs.artifact-name }} slug: ${{ needs.validate-inputs.outputs.artifact-slug }} install-path: ${{ needs.validate-inputs.outputs.install-path }} @@ -284,6 +296,7 @@ jobs: && !contains(format(',{0},', inputs.skip), ',a11y,') uses: ./.github/workflows/ci-test-a11y.yml with: + runs-on: ${{ inputs.runs-on }} working-dir: ${{ needs.validate-inputs.outputs.working-dir }} # Opt-in via gated-paths: fails a PR that commits build output, which is only correct where @@ -297,5 +310,6 @@ jobs: && !contains(format(',{0},', inputs.skip), ',artifact-gate,') uses: ./.github/workflows/ci-build-artifact-gate.yml with: + runs-on: ${{ inputs.runs-on }} gated-paths: ${{ inputs.gated-paths }} working-dir: ${{ needs.validate-inputs.outputs.working-dir }} diff --git a/AGENTS.md b/AGENTS.md index 40baae1..fbd85ef 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -41,6 +41,10 @@ name: CI / Lint PHP on: workflow_call: inputs: + runs-on: + description: "Runner for every job, as JSON" + type: string + default: '"ubuntu-latest"' php-version: description: "PHP version to install" type: string @@ -48,7 +52,7 @@ on: jobs: lint-php: name: Lint PHP - runs-on: [self-hosted] + runs-on: ${{ fromJSON(inputs.runs-on) }} steps: - name: Checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -56,7 +60,7 @@ jobs: - 2-space indent, `kebab-case` input names, a `description:` on every input, a `name:` on every job and step. `bin/check-workflows.sh` enforces all four. - Third-party actions pinned to a commit SHA with a trailing `# vX.Y.Z` comment. -- Every job runs on `runs-on: [self-hosted]`. rtCamp policy puts private repos on self-hosted runners, and a reusable workflow's jobs run in the caller's repo, so this is the consumer's runner too. `bin/check-workflows.sh` applies the org runner-policy allow-list (`self-hosted`, `high-performance`, `macOS`, `self-hosted-arm64`); use plain `[self-hosted]`, since every pool it reached in testing was linux-x64 and the pinned binaries this repo downloads are x86_64. +- Every job in a reusable workflow runs on `runs-on: ${{ fromJSON(inputs.runs-on) }}`, from a `runs-on` input that defaults to `'"ubuntu-latest"'`, and `wp-ci.yml` and `wp-cd.yml` forward it to every leaf. A reusable workflow's jobs run in the caller's repo: a public repo cannot use rtCamp's self-hosted runners, and rtCamp policy puts private repos on them, so the caller chooses (`'["self-hosted"]'` for private repos). This repo's own CI (`ci-self-check.yml`) runs on `ubuntu-latest` because the repo is public. `bin/check-workflows.sh` enforces all three. On self-hosted, pass plain `["self-hosted"]`: every pool it reached in testing was linux-x64, and the pinned binaries this repo downloads are x86_64. - Caller values reach a `run:` body through step `env:`, never through `${{ }}` interpolation. `bin/check-workflows.sh` enforces this — interpolation is still fine in `env:`, `with:` and `if:`, which are not shell. Two shapes: **Value inputs** (`composer-flags`, `phpstan-level`, `changed-files`) become argv, so shell metacharacters stay literal: diff --git a/CHANGELOG.md b/CHANGELOG.md index fae3bd4..60ef148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to `@rtcamp/wp-shared-workflows` are documented in this file The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## Unreleased + +### Changed + +- Every reusable workflow takes its runner from a new `runs-on` input (JSON: a label or a list of labels), defaulting to GitHub-hosted `"ubuntu-latest"`, and `wp-ci.yml` and `wp-cd.yml` forward it to every workflow they call. Hard-coding `[self-hosted]` left public callers (and this public repository's own CI) queued with no runner, since a reusable workflow's jobs run in the calling repository. rtCamp's private repositories pass `'["self-hosted"]'`, as the org runner policy requires. `ci-self-check.yml` runs on `ubuntu-latest`, and `bin/check-workflows.sh` now requires reusable workflows to use and forward the input instead of checking a label allow-list. + ## v1.0.0 - 2026-09-30 First tagged release. Consumers pin `@v1`. diff --git a/README.md b/README.md index d8e9a41..a5ac712 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,17 @@ jobs: That is a complete CI setup: lint CSS/JS/PHP, Jest, PHPUnit, and build — each job gated on what actually changed, so a docs-only PR runs almost nothing. -Every job runs on rtCamp's self-hosted runners (`runs-on: [self-hosted]`). A reusable workflow's -jobs run in the calling repository, so it needs access to the org's self-hosted runner group. +Every job runs on the runner the caller picks with the `runs-on` input, as JSON. It defaults to +GitHub-hosted `"ubuntu-latest"`. A reusable workflow's jobs run in the calling repository, so a public +repository cannot use rtCamp's self-hosted runners, while rtCamp's private repositories must (org +runner policy) and pass: + +```yaml + with: + runs-on: '["self-hosted"]' +``` + +`wp-ci.yml` and `wp-cd.yml` forward it to every workflow they call. ## Workflows diff --git a/bin/check-workflows.sh b/bin/check-workflows.sh index 20f7e71..c523ebc 100755 --- a/bin/check-workflows.sh +++ b/bin/check-workflows.sh @@ -6,7 +6,8 @@ # 3. Every `with:` / `secrets:` key an example passes is actually declared by that # workflow, and every required input/secret is supplied. # 4. Repo conventions: kebab-case input names, every input documented, every step named, -# no caller value interpolated into a `run:` body, and only allowed runner labels. +# no caller value interpolated into a `run:` body, reusable workflows take their runner +# from the runs-on input, and this repo's own CI runs on an allowed label. # # Requires: yq (v4) and jq. Locally, `brew install yq jq`. # Run from anywhere: bin/check-workflows.sh @@ -21,7 +22,11 @@ EXAMPLE_DIR="examples" SELF_CHECK="ci-self-check.yml" EXPECTED_REF="v1" USES_PREFIX="rtCamp/wp-shared-workflows/.github/workflows" -ALLOWED_RUNNER_LABELS=(self-hosted high-performance macOS self-hosted-arm64) +# Reusable workflows run in the caller's repo, so the caller picks the runner. +RUNS_ON_EXPR='${{ fromJSON(inputs.runs-on) }}' +RUNS_ON_FORWARD='${{ inputs.runs-on }}' +# This repo is public, so its own CI runs on GitHub-hosted runners. +OWN_CI_RUNNER_LABELS=(ubuntu-latest) fail=0 @@ -161,17 +166,37 @@ for wf in "$WORKFLOW_DIR"/*.yml; do | select((.value.run // "") | test("\\$\\{\\{\\s*(inputs|matrix)\\.")) | "job \($j.key) step #\(.key) (\(.value.name // "unnamed"))"' <<<"$wf_json") - # Every runs-on label must be on the org runner-policy allow-list. - while IFS= read -r loc; do - [ -n "$loc" ] || continue - err "$base $loc — allowed: ${ALLOWED_RUNNER_LABELS[*]}; use runs-on: [self-hosted]" - done < <(jq -r --args '$ARGS.positional as $allowed | (.jobs // {}) | to_entries[] - | select(.value["runs-on"] != null) - | (.value["runs-on"] | if type == "object" then (.labels // []) else . end | [.] | flatten - | map(tostring) | map(select(. as $l | $allowed | index($l) | not))) as $bad - | select($bad | length > 0) - | "job \(.key) runs on disallowed label(s) \($bad | join(", "))"' \ - "${ALLOWED_RUNNER_LABELS[@]}" <<<"$wf_json") + # A public caller cannot use rtCamp's self-hosted runners, and rtCamp's private repos must + # (org policy), so no reusable workflow hard-codes a label: every job runs on the runs-on + # input, and the orchestrators forward it to every leaf. + if jq -e '.["on"] | type == "object" and has("workflow_call")' >/dev/null <<<"$wf_json"; then + jq -e '.["on"].workflow_call.inputs["runs-on"] != null' >/dev/null <<<"$wf_json" || + err "$base declares no runs-on input" + while IFS= read -r loc; do + [ -n "$loc" ] || continue + err "$base $loc — use runs-on: $RUNS_ON_EXPR" + done < <(jq -r --arg expr "$RUNS_ON_EXPR" '(.jobs // {}) | to_entries[] + | select(.value["runs-on"] != null and .value["runs-on"] != $expr) + | "job \(.key) runs on \(.value["runs-on"] | tostring)"' <<<"$wf_json") + while IFS= read -r loc; do + [ -n "$loc" ] || continue + err "$base $loc — pass runs-on: $RUNS_ON_FORWARD" + done < <(jq -r --arg fwd "$RUNS_ON_FORWARD" '(.jobs // {}) | to_entries[] + | select((.value.uses // "") | startswith("./.github/workflows/")) + | select((.value.with // {})["runs-on"] != $fwd) + | "job \(.key) does not forward runs-on to \(.value.uses)"' <<<"$wf_json") + else + while IFS= read -r loc; do + [ -n "$loc" ] || continue + err "$base $loc — allowed: ${OWN_CI_RUNNER_LABELS[*]}" + done < <(jq -r --args '$ARGS.positional as $allowed | (.jobs // {}) | to_entries[] + | select(.value["runs-on"] != null) + | (.value["runs-on"] | if type == "object" then (.labels // []) else . end | [.] | flatten + | map(tostring) | map(select(. as $l | $allowed | index($l) | not))) as $bad + | select($bad | length > 0) + | "job \(.key) runs on disallowed label(s) \($bad | join(", "))"' \ + "${OWN_CI_RUNNER_LABELS[@]}" <<<"$wf_json") + fi done if [ "$fail" -ne 0 ]; then