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
60 changes: 56 additions & 4 deletions .github/workflows/selftest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# the fixtures in tests/fixtures:
# positive controls go-pass passes the gate and the scan with every fail-on
# category set; node-pass-npm / node-pass-bun pass the node
# gate; python-pass passes the python gate; this
# repository's own workflows lint clean
# gate; python-pass passes the python gate; shell-pass
# passes the shell gate and its build output reaches a
# later job; this repository's own workflows lint clean
# negative controls planted findings (fake key, reachable vulnerable call,
# secret logged to the console, root container, unpinned
# action, failing Go, Node and Python tests, a second or missing
# action, failing Go, Node, Python and bats tests, an
# unquoted shell expansion, a second or missing
# lockfile, a privileged container in a Helm chart) are each
# reported; a Helm chart trivy skips fails the scan
# Negative controls run report-only and are asserted from the outputs, so the
Expand Down Expand Up @@ -228,6 +230,56 @@ jobs:
fi
echo "just test failed as expected"

shell-gate-pass:
uses: ./.github/workflows/shell-gate.yml
with:
working-directory: tests/fixtures/shell-pass
build-args: out
build-artifact-path: tests/fixtures/shell-pass/out/greeting.txt
build-artifact-name: shell-gate-selftest
build-artifact-retention-days: 1
harness-ref: ${{ github.sha }}

# The build output of the gate must reach a later job of the caller (an
# image test, a release): the artifact is downloaded and checked here.
shell-gate-artifact:
needs: [shell-gate-pass]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: shell-gate-selftest
path: out
- name: the build output reached this job
run: grep -qx 'hello world' out/greeting.txt

shell-gate-fail:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: scripts/install-tool.sh just shellcheck shfmt
- run: |
sudo apt-get update -qq
sudo apt-get install -y -qq --no-install-recommends bats bats-support bats-assert
- name: the planted findings must fail `just lint` and `just test`
working-directory: tests/fixtures/shell-fail
run: |
fail=0
if just lint; then
echo "::error::just lint passed although greet.sh has an unquoted expansion"
fail=1
fi
if just test; then
echo "::error::just test passed although a bats test fails"
fail=1
fi
[ "$fail" = 0 ] && echo "just lint and just test failed as expected"
exit "$fail"

security-clean:
uses: ./.github/workflows/security.yml
permissions:
Expand Down Expand Up @@ -466,7 +518,7 @@ jobs:
# above succeeded (skipped or cancelled counts as failed).
selftest-ok:
if: ${{ always() }}
needs: [lint-self, lint-templates, lint-planted, scripts, gate-pass, gate-fail, node-gate-npm, node-gate-npm-tools, node-gate-bun, node-gate-fail, python-gate-pass, python-gate-fail, security-clean, security-clean-node, security-planted, config-scan-skipped-chart, security-helm, release-dry-run, release-dry-run-package-json, build-context-artifact, release-dry-run-build-context, release-dry-run-image-tag, assert-image-tag, assert-planted]
needs: [lint-self, lint-templates, lint-planted, scripts, gate-pass, gate-fail, node-gate-npm, node-gate-npm-tools, node-gate-bun, node-gate-fail, python-gate-pass, python-gate-fail, shell-gate-pass, shell-gate-artifact, shell-gate-fail, security-clean, security-clean-node, security-planted, config-scan-skipped-chart, security-helm, release-dry-run, release-dry-run-package-json, build-context-artifact, release-dry-run-build-context, release-dry-run-image-tag, assert-image-tag, assert-planted]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand Down
223 changes: 223 additions & 0 deletions .github/workflows/shell-gate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# Reusable gate for shell and just repositories (image builders, installers,
# script collections): lint, unit tests, build.
#
# Every logic step is a `just` recipe of the calling repository, so the gate
# runs the same locally and in CI. `just` runs from `working-directory` and
# finds the repository's Justfile upwards from there.
#
# Recipe contract (see README):
# lint non-mutating static checks: just --fmt --check, shellcheck,
# shfmt -d, yamllint where configured
# test hermetic unit tests (bats)
# build the repository's artefact build, without publishing
#
# The gate provides the tools, the recipes decide how to use them: just,
# shellcheck and shfmt from tools.lock in every job, yamllint (lint) and bats
# with bats-support and bats-assert (unit) from the Ubuntu archive. A build
# that needs more (mmdebstrap, genimage, qemu) names them in
# `build-apt-packages`. `build-artifact-path` hands the build output to a
# later job of the caller (an image test, a release), as an artifact.
#
# Job names stay `lint` / `unit` / `build`, as in the other gates.
name: shell-gate

on:
workflow_call:
inputs:
working-directory:
description: Directory `just` runs from.
type: string
default: "."
skip:
description: Comma list of jobs to skip (lint, unit, build).
type: string
default: ""
tools:
description: Extra tools from tools.lock to install in every job (space-separated).
type: string
default: ""
apt-packages:
description: Extra Ubuntu packages for every job (space-separated).
type: string
default: ""
build-apt-packages:
description: Extra Ubuntu packages for the build job only (space-separated).
type: string
default: ""
lint-recipe:
type: string
default: lint
test-recipe:
type: string
default: test
build-recipe:
type: string
default: build
build-args:
description: Arguments of the build recipe (space-separated words), e.g. "amd64-efi base".
type: string
default: ""
build-runs-on:
description: Runner of the build job (ubuntu-24.04-arm for a native arm64 build).
type: string
default: ubuntu-latest
build-timeout-minutes:
type: number
default: 30
build-artifact-path:
description: Files the build leaves for later jobs, relative to the repository root (upload-artifact path syntax); empty uploads nothing.
type: string
default: ""
build-artifact-name:
type: string
default: build
build-artifact-retention-days:
type: number
default: 3
harness-ref:
description: Ref of IronFlock/workflows the harness scripts are taken from.
type: string
default: v1

permissions:
contents: read

defaults:
run:
shell: bash

jobs:
lint:
if: ${{ !contains(inputs.skip, 'lint') }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: IronFlock/workflows
ref: ${{ inputs.harness-ref }}
path: .harness
persist-credentials: false
sparse-checkout: |
scripts
tools.lock
sparse-checkout-cone-mode: false
- name: move harness out of the workspace
run: |
mv .harness "$RUNNER_TEMP/harness"
echo "HARNESS=$RUNNER_TEMP/harness" >> "$GITHUB_ENV"
- name: install just, shellcheck and shfmt (and extra tools)
env:
TOOLS: ${{ inputs.tools }}
run: |
# shellcheck disable=SC2086 # a space-separated list of tool names
"$HARNESS/scripts/install-tool.sh" just shellcheck shfmt $TOOLS
- name: install yamllint (and extra packages)
env:
PKGS: ${{ inputs.apt-packages }}
run: |
sudo apt-get update -qq
# shellcheck disable=SC2086 # a space-separated list of package names
sudo apt-get install -y -qq --no-install-recommends yamllint $PKGS
- name: just ${{ inputs.lint-recipe }}
working-directory: ${{ inputs.working-directory }}
env:
RECIPE: ${{ inputs.lint-recipe }}
run: just "$RECIPE"

unit:
if: ${{ !contains(inputs.skip, 'unit') }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: IronFlock/workflows
ref: ${{ inputs.harness-ref }}
path: .harness
persist-credentials: false
sparse-checkout: |
scripts
tools.lock
sparse-checkout-cone-mode: false
- name: move harness out of the workspace
run: |
mv .harness "$RUNNER_TEMP/harness"
echo "HARNESS=$RUNNER_TEMP/harness" >> "$GITHUB_ENV"
- name: install just, shellcheck and shfmt (and extra tools)
env:
TOOLS: ${{ inputs.tools }}
run: |
# shellcheck disable=SC2086 # a space-separated list of tool names
"$HARNESS/scripts/install-tool.sh" just shellcheck shfmt $TOOLS
- name: install bats (and extra packages)
env:
PKGS: ${{ inputs.apt-packages }}
run: |
sudo apt-get update -qq
# shellcheck disable=SC2086 # a space-separated list of package names
sudo apt-get install -y -qq --no-install-recommends bats bats-support bats-assert $PKGS
- name: just ${{ inputs.test-recipe }}
working-directory: ${{ inputs.working-directory }}
env:
RECIPE: ${{ inputs.test-recipe }}
run: just "$RECIPE"

build:
if: ${{ !contains(inputs.skip, 'build') }}
runs-on: ${{ inputs.build-runs-on }}
timeout-minutes: ${{ inputs.build-timeout-minutes }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: IronFlock/workflows
ref: ${{ inputs.harness-ref }}
path: .harness
persist-credentials: false
sparse-checkout: |
scripts
tools.lock
sparse-checkout-cone-mode: false
- name: move harness out of the workspace
run: |
mv .harness "$RUNNER_TEMP/harness"
echo "HARNESS=$RUNNER_TEMP/harness" >> "$GITHUB_ENV"
- name: install just, shellcheck and shfmt (and extra tools)
env:
TOOLS: ${{ inputs.tools }}
run: |
# shellcheck disable=SC2086 # a space-separated list of tool names
"$HARNESS/scripts/install-tool.sh" just shellcheck shfmt $TOOLS
- name: install build packages
if: ${{ inputs.apt-packages != '' || inputs.build-apt-packages != '' }}
env:
PKGS: ${{ inputs.apt-packages }} ${{ inputs.build-apt-packages }}
run: |
sudo apt-get update -qq
# shellcheck disable=SC2086 # a space-separated list of package names
sudo apt-get install -y -qq --no-install-recommends $PKGS
- name: just ${{ inputs.build-recipe }} ${{ inputs.build-args }}
working-directory: ${{ inputs.working-directory }}
env:
RECIPE: ${{ inputs.build-recipe }}
ARGS: ${{ inputs.build-args }}
run: |
# shellcheck disable=SC2086 # recipe arguments are space-separated words
just "$RECIPE" $ARGS
- name: upload the build output
if: ${{ inputs.build-artifact-path != '' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ inputs.build-artifact-name }}
path: ${{ inputs.build-artifact-path }}
if-no-files-found: error
retention-days: ${{ inputs.build-artifact-retention-days }}
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,23 @@ The inputs of each workflow are documented in its `on.workflow_call` block.
| [go-gate.yml](.github/workflows/go-gate.yml) | `lint`, `unit`, `build` | Go gate; cross-build matrix from `targets` / `targets-file` |
| [node-gate.yml](.github/workflows/node-gate.yml) | `lint`, `unit`, `build` | Node/Bun gate: `package-manager` bun or npm, installs from the lockfile only (`bun install --frozen-lockfile` / `npm ci`), fails on a lockfile of the other package manager; `skip` drops jobs a repository has no recipe for |
| [python-gate.yml](.github/workflows/python-gate.yml) | `lint`, `unit`, `build` | Python gate: uv from `tools.lock`; with a `uv.lock`, `uv sync --frozen` (all groups) before the recipes, otherwise the recipes bring their own tools (pinned `uvx`) |
| [shell-gate.yml](.github/workflows/shell-gate.yml) | `lint`, `unit`, `build` | Shell/just gate (image builders, installers, script collections): just, shellcheck, shfmt from `tools.lock`, yamllint and bats from the Ubuntu archive; `build-apt-packages` for build tools, `build-args` for the build recipe, `build-runs-on` for a native arm64 build, `build-artifact-path` hands the build output to a later job |
| [security.yml](.github/workflows/security.yml) | `gitleaks`, `deps`, `semgrep`, `sbom`, `config`, `licenses`, `image`, `report` | security screening; `report` applies `fail-on` |
| [workflows-lint.yml](.github/workflows/workflows-lint.yml) | `lint` | actionlint, zizmor, pinact on the caller's workflows; always blocking |
| [release-intent.yml](.github/workflows/release-intent.yml) | `intent` | the version file decides: a rise makes a release PR (title `release <name> <tag>` required), an unchanged version a no-release PR; output `kind` gates the release dry run; listed in the `needs` of `ci-ok` |
| [release-image.yml](.github/workflows/release-image.yml) | `verify`, `build`, `publish` | release of a container image on the merge of a release PR into the protected `main`; native multi-arch build, SBOM + provenance attached, keyless push; on a release PR a dry run (every platform build, no push); re-runs are safe; read rights only; `build-contexts-artifact` hands data an earlier job prepared (with secrets the build must not see) to the build as named contexts |
| [release-tag.yml](.github/workflows/release-tag.yml) | `tag` | the annotated git tag of a release, after every image job of the caller; a tag always means "in the registry"; written with a token of the release GitHub App from the caller's `release` environment |
| [selftest.yml](.github/workflows/selftest.yml) | — | proves the harness against [tests/fixtures](tests/fixtures) |

Gates for Node, Python and chart/shell repositories follow the same pattern
and are added when the first repository of that kind adopts the harness.
A gate for chart repositories follows the same pattern and is added when the
first repository of that kind adopts the harness.

## Recipe contract

| Recipe | Meaning |
|---|---|
| `lint` | non-mutating static checks. Go: `gofmt -l`, `go mod tidy -diff`, `go vet`, golangci-lint (incl. gosec, config in [templates/repo/.golangci.yml](templates/repo/.golangci.yml)) |
| `test` | hermetic unit tests. Go: `go test -race -shuffle=on -count=1 ./...` |
| `lint` | non-mutating static checks. Go: `gofmt -l`, `go mod tidy -diff`, `go vet`, golangci-lint (incl. gosec, config in [templates/repo/.golangci.yml](templates/repo/.golangci.yml)). Shell: `just --fmt --check`, `shellcheck`, `shfmt -d`, `yamllint` |
| `test` | hermetic unit tests. Go: `go test -race -shuffle=on -count=1 ./...`. Shell: `bats` |
| `build` | the artefact build, without publishing |
| `sarif`, `sbom` | optional (Go): write govulncheck SARIF / CycloneDX files; otherwise the harness runs govulncheck and cyclonedx-gomod itself |

Expand Down
Loading
Loading