Skip to content

Workflow parallel ci

github-actions[bot] edited this page Nov 8, 2026 · 1 revision

parallel-ci

What it does. Runs a project's build once, then its checks as separate jobs that share the build, and ends in one CI green gate. A project whose CI is a single long job (build, then a dozen checks and test scripts one after another) finishes in the build plus its slowest check instead of the sum. It holds no token.

Why it exists. The blog behind the first caller spent 16 to 19 minutes in one sequential job. Nothing could be dropped (every check and pin stays), so the answer is to run the same commands side by side. The generic part is here: a build artifact, a matrix over a list of commands, path rules, caches and a gate. Everything specific to the project stays in the caller.

The jobs

Job What it does
changes Validates every input (failing the run on a bad one) and decides which checks this change needs
build Runs build-command once; uploads build-output-path as a one-day artifact named with the run attempt
checks A matrix over the selected jobs; each leg downloads the build and runs its command
ci-green CI green: red on any failed, cancelled or unexplained-skipped job

Which checks run

Give areas as a JSON object from an area name to glob patterns, and a job a list of areas. On a pull request the change is git diff --no-renames --name-only between the base and the merge result; each path takes the first area that matches. A job with areas runs only when the change touches one of them.

It fails closed. A push, a schedule, a manual run, an empty diff, a diff that could not be taken, a path no rule matches and a path with a control character or invalid UTF-8 in its name all run every job. Moving a file out of a protected path shows the old path too (--no-renames), so it is not a docs-only change. Put a catch-all last ("site": ["*"]).

The gate

ci-green needs every other job and runs if: always(). A job is green only if it is success. The one skip it accepts is the checks job when changes succeeded and the rules selected no check at all; a checks job skipped because the build failed is a failure. There is no continue-on-error and no || true in the workflow.

Setup, PATH and caches

setup-command runs in the same shell as the command that needs it, so export PATH=... there reaches that command and nothing else. The workflow never writes $GITHUB_PATH or $GITHUB_ENV. A setup that exits early cannot make a step pass.

cache-pip-files and cache-tool-path with cache-tool-key-files cache downloads only, keyed on a hash of the files you name, and only where the egress policy is block. Keep --require-hashes on installs and verify a downloaded tool against a checksum fetched fresh every run.

A minimal caller

jobs:
  ci:
    uses: ChiefGyk3D/git-your-ship-together/.github/workflows/parallel-ci.yml@<sha> # vX.Y.Z
    permissions:
      contents: read
    with:
      build-command: hugo --minify --gc
      build-output-path: public
      areas: '{"docs": ["docs/*.md", "README.md"], "site": ["*"]}'
      jobs: |
        [
          {"name": "output checks", "command": "scripts/check-output.sh public"},
          {"name": "size budget", "command": "scripts/check-budget.sh public", "areas": ["site"]}
        ]

The check run is ci / CI green. With other workflows beside it, put ci-gate over all of them.

Inputs (17), read from parallel-ci.yml:

Input Type Default Meaning
build-command string required Shell command that builds the project once, from the repository root. It must write the output into build-output-path. Runs after setup-command, in the same shell. (required)
build-output-path string required Directory the build writes, relative to the workspace (plain path segments only). It is uploaded after the build and downloaded to the same path in every check job that needs the build. (required)
extra-output-path string empty Optional second directory to share, for a variant built elsewhere. Relative to the workspace, or RUNNER_TEMP/<path> for a directory under the runner's temporary directory. Uploaded and downloaded to the same absolute path.
jobs string required JSON list of check jobs, one object each. name (required, letters, digits, space and ._()-), command (required shell), timeout (minutes, default 15), areas (list of area names; empty or absent means always run), pip-cache (true to restore pip's download cache), tools (true to run setup-command first), build (false to skip the build download; default true). Unknown keys fail the job. (required)
areas string {} JSON object mapping an area name to shell-style glob patterns (* matches across /), for example {"docs": ["docs/.md", "README.md"], "site": [""]}. The first area whose pattern matches a path wins. A path that matches none runs every job, so end with a catch-all.
setup-command string empty Shell run before build-command and before the command of every job with tools true, in the same shell, for installing a tool. Put the tool on PATH with export PATH=... there; nothing may write to the Actions PATH or environment files.
cache-pip-files string [] JSON list of pin files (requirements with hashes) whose contents key pip's download cache. Empty means no pip cache. Installs should keep --require-hashes, so a cached wheel that does not match its pin is rejected.
build-pip-cache boolean false Also restore the pip download cache in the build job.
cache-tool-path string empty Optional directory holding one cached tool download (the tarball, never the verified binary), relative to the workspace or RUNNER_TEMP/<path>. Used with cache-tool-key-files. The setup command must verify the download against a checksum fetched fresh from the release every run.
cache-tool-key-files string [] JSON list of files (a version pin) whose contents key the tool cache, so a changed pin misses it.
artifact-name string gyst-build Prefix of the artifact names (<prefix>-<run attempt>, and <prefix>-extra-<run attempt>). Change it when one workflow run calls this workflow twice, so the two do not share an artifact.
artifact-retention-days number 1 Days the build artifact is kept, 1 to 7. It is generated output and no secret; one day is enough for the run and its re-runs.
build-timeout-minutes number 15 Timeout of the build job.
egress-policy string block harden-runner egress policy - audit logs outbound connections, block allows only allowed-endpoints. Jobs that hold no secret follow egress-policy-secretless instead (EX-0001); this workflow has none, so the input is only validated.
egress-policy-secretless string block harden-runner egress policy for every job here, none of which holds a stored secret, an OIDC token or a write-scoped token - exactly audit or block. Defaults to block since security exception EX-0001 was closed on 2026-11-02; see docs/security/exceptions/. Set audit to opt out if the defect recurs. Any other value fails the job.
allowed-endpoints string api.github.com:443 github.com:443 harden-runner allow-list for block, space-separated host:port entries. The default is what the checkout needs; artifacts and the Actions cache use the runner's own infrastructure. Wildcards are not supported and a newline-separated list matches nothing.
extra-allowed-endpoints string empty Appended to allowed-endpoints, for hosts only your build and checks reach (a package index, a release download). Same format. It applies to every job.

Outputs a caller job can read:

Output Meaning
result success or failure, the verdict of the gate.
skipped-jobs Comma-separated names of the check jobs the path rules skipped on purpose.
everything true when every job was selected because the change could not or should not be narrowed (a push, an unmatched path), false when the path rules chose.

What it refuses to do

It never runs a caller value as part of a shell script it wrote (values arrive in environment variables), never passes a gate over nothing, never skips a check on an unreadable change, and never gives a job more than contents: read.

Clone this wiki locally