Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/cd-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ jobs:
name: ${{ inputs.artifact-name }}
path: artifact

# Self-hosted runners do not ship the AWS CLI.
- name: Install AWS CLI
shell: bash
env:
AWS_CLI_VERSION: "2.37.6"
AWS_CLI_SHA256: "cd40c7d1f41b3a4964e77a65377e480d71fe6ebc96bbbb64eb2239d69af6fbb2"
run: |
set -euo pipefail
if command -v aws >/dev/null 2>&1; then
aws --version
exit 0
fi
tmp="$(mktemp -d)"
curl -sSfL -o "$tmp/awscliv2.zip" \
"https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip"
echo "${AWS_CLI_SHA256} $tmp/awscliv2.zip" | sha256sum -c -
unzip -q "$tmp/awscliv2.zip" -d "$tmp"
sudo "$tmp/aws/install"
aws --version

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@99214aa6889fcddfa57764031d71add364327e59 # v6.1.3
with:
Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/ci-detect-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,24 @@ jobs:
args+=(--ignore "$IGNORE_PATHS")
fi
if [ -n "$BASE_REF" ]; then
args+=(--base "$BASE_REF")
# The CLI does not fetch an explicit --base, and the shallow checkout rarely has it.
if ! base="$(git rev-parse --verify -q "${BASE_REF}^{commit}")"; then
git fetch --no-tags --depth=1 origin "${BASE_REF#origin/}" ||
{ echo "::error::base-ref '$BASE_REF' could not be fetched from origin"; exit 1; }
base="$(git rev-parse FETCH_HEAD)"
fi
args+=(--base "$base")
fi
wp-tooling detect-changes "${args[@]}"
# The CLI reports zero changes when git diff fails; fail instead of skipping every job.
err="$RUNNER_TEMP/detect-changes.stderr"
status=0
wp-tooling detect-changes "${args[@]}" 2>"$err" || status=$?
cat "$err" >&2
if grep -q 'git diff failed' "$err"; then
echo "::error::detect-changes could not diff against its base, so it cannot tell what changed. Failing instead of skipping every job."
exit 1
fi
exit "$status"

# The detector emits repo-root-relative paths but the linters run with cwd = working-dir,
# so an unscoped list resolves to <dir>/<dir>/<file>. At working-dir '.' this is a pure
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/ci-self-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ jobs:
env:
ACTIONLINT_VERSION: "1.7.12"
ACTIONLINT_SHA256: "8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8"
YQ_VERSION: "4.53.6"
YQ_SHA256: "c5f056448f973ae7d39b5401949648a78f2dc1947d6a8eb65be60d5c504b9385"
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Python
uses: actions/setup-python@v5
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.x"

Expand All @@ -48,5 +50,13 @@ jobs:
- name: Run actionlint
run: actionlint -color .github/workflows/*.yml examples/*.yml

- name: Install yq
run: |
set -euo pipefail
curl -sSfL -o yq \
"https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64"
echo "${YQ_SHA256} yq" | sha256sum -c -
sudo install -m 0755 yq /usr/local/bin/yq

- name: Verify examples match the workflows they call
run: bin/check-workflows.sh
3 changes: 2 additions & 1 deletion .github/workflows/ci-test-build-artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ jobs:
run: |
set -euo pipefail

npx --yes @wordpress/env run cli wp package install wp-cli/doctor-command:@stable
# 3.x requires WP-CLI 3; wp-env ships 2.12.
npx --yes @wordpress/env run cli wp package install wp-cli/doctor-command:2.3.1

# `wp doctor check` exits 1 on an error check; capture anyway (|| true) so the report prints before we gate.
result=$(npx --yes @wordpress/env run cli wp doctor check --all --format=json) || true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wp-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
# deploy nothing, and a missing input/secret would fail mid-deploy.
validate-inputs:
name: Validate inputs
runs-on: ubuntu-latest
runs-on: [self-hosted]
steps:
- name: Check deploy targets and their required inputs and secrets
env:
Expand Down
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ on:
jobs:
lint-php:
name: Lint PHP
runs-on: ubuntu-latest
runs-on: [self-hosted]
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
```

- 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.
- 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:
Expand Down Expand Up @@ -106,6 +107,7 @@ Use `bash -eo pipefail -c`, never bare `bash -c`: `-e` is not inherited, so a ba
- `working-dir` carries three different meanings. On the CI leaves it is a real working directory — tools install and run inside it. On `ci-detect-changes.yml` it is a **path scope**: the diff is always taken from the repository root, then the CSS/JS/PHP lists are filtered and re-rooted, while `total-count`, `ignored-count` and the `gha-*` outputs stay repo-wide. On `cd-github-release.yml` and `cd-wp-org.yml` it is a **path prefix** for source files they read (`changelog-path`, `assets-path`); the deployed files come from the artifact, and `wp-cd.yml` forwards it to both unchanged. `cd-built-branch.yml` scopes per entry in its `targets` JSON array, and `cd-s3.yml` by the artifact it downloads.
- `actions/download-artifact` only sees the current run. Anything consuming a build artifact must run in the same workflow as the `ci-build` job that produced it, wired with `needs:`.
- The default `wp-tooling-ref` SHA is duplicated in `ci-detect-changes.yml`, `wp-ci.yml` and `version-monitor.yml`. Changing one without the others silently splits behaviour across jobs.
- The self-hosted runners are ARC pods on Ubuntu 24.04 x64 with a minimal image, not GitHub's `ubuntu-latest`. They have `git`, `curl`, `jq`, `zip`, `rsync`, `python3`, `gh` and `docker`, but no `yq`, `pip`, `aws` or `svn`, and no Node or PHP until `setup-node`/`setup-php` run. `/usr/local/bin` needs `sudo`, which is passwordless. Install what a step needs, pinned and checksum-verified, as `ci-self-check.yml` does for `actionlint` and `yq` and `cd-s3.yml` does for the AWS CLI. apt's `yq` is kislyuk's jq wrapper, not the mikefarah `yq` this repo uses.
- `actionlint` shells out to whatever `shellcheck` is on `PATH`, and rule behaviour differs between shellcheck releases — a local pass does not guarantee a CI pass. Write shell that is clean on older versions too: prefer `guard || continue` and explicit `if` blocks over `A && B || C`, which SC2015 flags on shellcheck 0.10 and earlier.
- A green `bin/check-workflows.sh` proves input *names* are right, not input *values*. A wrong `build-command` or `artifact-path` only surfaces in a real consumer run.
- `cd-github-release.yml` extracts release notes by matching a version heading in `CHANGELOG.md`, and deliberately fails rather than publishing empty notes. Cut `## Unreleased` to `## vX.Y.Z - YYYY-MM-DD` before tagging.
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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/).

## v1.0.0 - 2026-08-10
## v1.0.0 - 2026-09-30

First tagged release. Consumers pin `@v1`.

Expand All @@ -24,6 +24,9 @@ First tagged release. Consumers pin `@v1`.
- Monorepo fixes across the CI leaves. All six `setup-node` steps that use `cache: npm` now pass `cache-dependency-path`, and `ci-lint-php.yml`'s Composer cache key is scoped to `<working-dir>/composer.lock`. `ci-build-artifact-gate.yml` normalises **and** regex-escapes `working-dir` before anchoring its pattern — previously a `./`-prefixed or metacharacter-containing value matched nothing, so the gate passed green on a PR that committed build output. `ci-test-build-artifact.yml` gains `working-dir`.
- `cd-github-release.yml` and `cd-wp-org.yml` gain `working-dir` as a **path prefix, not a working directory**: it scopes only the source-tree paths they read (`changelog-path`, `assets-path`), since the deployed files come from an already unit-scoped artifact. Both previously fell back to the repo root in a monorepo and failed silently — another unit's `CHANGELOG.md` still parses, and a missing `.wordpress-org` only emits a notice. Both now reject absolute and `..` paths. `cd-s3.yml` is unchanged.
- `cd-github-release.yml`, `cd-wp-org.yml` and `cd-s3.yml` fail fast in a first validation step when a required input arrives empty: `tag` and `artifact-name` everywhere, plus `slug` for wporg and `bucket` for s3. `required: true` does not reject an empty string, and an empty `artifact-name` makes `download-artifact` fetch every artifact in the run; an empty `slug` would fall back to the deploy action's repo-name default and could deploy to the wrong wordpress.org plugin, and an empty `tag` would upload to `<prefix>.zip`. `cd-wp-org.yml` and `cd-s3.yml` also presence-check their secrets as booleans, since a caller mapping an unset secret satisfies GitHub's required-secret check with an empty value.
- Every job runs on `runs-on: [self-hosted]`, per rtCamp's policy for private repositories. A reusable workflow's jobs run in the calling repository, so the caller needs access to the org's self-hosted runner group. `bin/check-workflows.sh` applies the same label allow-list as the org's runner-policy scanner, which stops checking a repository once it is public. These runners do not ship the AWS CLI, so `cd-s3.yml` installs a pinned, checksum-verified one when the runner has none.
- `ci-detect-changes.yml`, and so `wp-ci.yml`, now fetch an explicit `base-ref` before diffing. The CLI diffs an explicit base as-is, and the depth-2 checkout never holds a branch such as `main`, so the diff failed, the CLI reported zero changes, and every downstream job skipped while the run passed green. The step also fails when the CLI reports a failed diff in any mode, instead of passing with nothing checked.
- `ci-test-build-artifact.yml` pins `wp-cli/doctor-command` to 2.3.1. `@stable` resolved to v3.0.0 (released 2026-08-04), which requires wp-cli ^3.0, while the wp-env cli container ships 2.12, so the job failed at the package install for every caller.

### Added

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ 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.

## Workflows

Each workflow declares its inputs, secrets and outputs in its own `workflow_call` block, and GitHub
Expand Down
29 changes: 18 additions & 11 deletions bin/check-workflows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
# 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,
# and no caller value interpolated into a `run:` body.
# no caller value interpolated into a `run:` body, and only allowed runner labels.
#
# Requires: python3 (with PyYAML) and jq. Both are preinstalled on GitHub's
# ubuntu runners; locally, `brew install jq` and `pip install pyyaml`.
# Requires: yq (v4) and jq. Locally, `brew install yq jq`.
# Run from anywhere: bin/check-workflows.sh

set -euo pipefail
Expand All @@ -22,6 +21,7 @@ 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)

fail=0

Expand All @@ -30,19 +30,14 @@ err() {
fail=1
}

for tool in python3 jq; do
for tool in yq jq; do
command -v "$tool" >/dev/null 2>&1 || {
echo "$tool is required but not installed" >&2
echo "$tool is required but not installed — brew install yq jq" >&2
exit 127
}
done

as_json() { python3 -c "
import yaml,json,sys
class StrLoader(yaml.SafeLoader):pass
StrLoader.add_constructor('tag:yaml.org,2002:bool',lambda l,n:l.construct_scalar(n))
json.dump(yaml.load(open(sys.argv[1]),Loader=StrLoader),sys.stdout)
" "$1"; }
as_json() { yq -o=json '.' "$1"; }

# --- 1. one example per workflow, one workflow per example -------------------

Expand Down Expand Up @@ -165,6 +160,18 @@ for wf in "$WORKFLOW_DIR"/*.yml; do
| ($j.value.steps // []) | to_entries[]
| 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")
done

if [ "$fail" -ne 0 ]; then
Expand Down
Loading