64 Commits
Author SHA1 Message Date
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
4cb9470389 chore(deps): update renovatebot/github-action action to v46.3.13 (#16)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-11-12 06:20:32 +00:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
fa71d6bb44 chore(deps): update sigstore/cosign-installer action to v4.1.3 (#15)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-11-08 00:21:59 +00:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
65988d996b chore(deps): update renovatebot/github-action action to v46.3.12 (#14)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-11-05 06:20:57 +00:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
a8a86485a9 chore(deps): update renovatebot/github-action action to v46.3.11 (#13)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-11-02 18:22:34 +00:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
42c623fc6c chore(deps): update renovatebot/github-action action to v46.3.10 (#12)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-10-29 06:19:10 +00:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
3d5fe9d4f8 chore(deps): update renovatebot/github-action action to v46.3.9 (#11)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-10-22 11:19:33 +00:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
e70a775c27 chore(deps): update renovatebot/github-action action to v46.3.8 (#10)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-10-15 05:20:29 +00:00
lukaszraczyloandGitHub 87651c95dc feat(autoupdate): add build-tags input to renovate-autoupdate (#9)
The default Go build and test step has no way to pass build tags.
A repository that needs tags, such as fts5, fails its scheduled run.

The new build-tags input defaults to an empty string.
With tags set, the step must run go build and go test with -tags.
It also sets CGO_ENABLED=1, as go-pr.yaml does.
Without tags, the commands stay unchanged.
The go-test-command input still replaces the default commands.
2026-10-10 01:31:40 +01:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
38e5cb0968 chore(deps): update renovatebot/github-action action to v46.3.7 (#8)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-10-08 05:20:34 +00:00
lukaszraczylo 31cb4a7f8b fix(autoupdate): follow go.mod for the Go version
A dependency update can raise the go directive past the input range, which
made the test step fail with GOTOOLCHAIN=local. Raise the version to the
merged go.mod and let the test step fetch a toolchain when one is needed.
2026-10-05 11:47:37 +01:00
lukaszraczylo 33fdaf6689 fix(autoupdate): skip a branch whose lockfile the default branch also changed
A lockfile changed on both sides merges as text and can come out broken,
so a tested merge differs from the merge that lands. Skip the branch and
let Renovate regenerate it on the next run.
2026-10-05 11:11:27 +01:00
lukaszraczylo a0032ad2f8 fix(release): pass the Homebrew tap token to the cgo release 2026-10-04 00:38:35 +01:00
lukaszraczylo b7bb0468b2 Merge branch 'main' into feat/node-registry-workspace 2026-10-03 23:18:26 +01:00
lukaszraczylo 459d448941 fix(autoupdate): give pnpm workspace lockfile updates the registry token 2026-10-03 23:08:39 +01:00
lukaszraczyloandGitHub c42cf115b8 chore(autoupdate): author the update merge as Lukasz Raczylo (#7)
The Renovate autoupdate workflow merged each update branch with the
github-actions bot identity. It now uses [email protected], the same
author as the cluster Renovate runner.
2026-10-03 23:05:07 +01:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
ffbec959bc chore(deps): update actions/checkout action to v7 (#4)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-10-03 23:01:11 +01:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
5cb1998345 chore(deps): update actions/setup-go action to v7 (#5)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-10-03 23:00:59 +01:00
tozuo-home-cluster-eso[bot]GitHubtozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
852afeb5aa chore(deps): update actions/setup-node action to v7 (#6)
Co-authored-by: tozuo-home-cluster-eso[bot] <287217661+tozuo-home-cluster-eso[bot]@users.noreply.github.com>
2026-10-03 23:00:46 +01:00
lukaszraczylo b23191de71 fix(autoupdate): retry the PR merge on a transient GitHub error 2026-10-03 22:58:15 +01:00
lukaszraczyloandGitHub 8f20f32137 fix(renovate): do not post status checks (#3)
The GitHub App reads statuses but cannot write them. Renovate posts a
renovate/stability-days status on each branch for minimumReleaseAge. The
403 aborted the run as "repository changed" right after the first
branch was created. Turn the Renovate status checks off. minimumReleaseAge
still holds a release back.
2026-10-03 22:54:08 +01:00
lukaszraczylo 26ad486b78 Merge branch 'feat/pnpm-workspace' into feat/node-registry-workspace 2026-10-03 22:45:36 +01:00
lukaszraczylo 73983972db feat(node): support pnpm workspaces 2026-10-03 22:45:11 +01:00
lukaszraczylo caaad0efab feat(npm): support a private registry token 2026-10-03 22:44:30 +01:00
lukaszraczyloandGitHub cce3d04588 Merge pull request #2 from lukaszraczylo/feat/renovate-validation
feat: validate workflows and actions, and prepare Renovate bumps
2026-10-03 22:30:41 +01:00
lukaszraczylo b7c4914104 fix(renovate): leave tool-version inputs and the GoReleaser version alone 2026-10-03 22:28:58 +01:00
lukaszraczylo 86ba34bab5 fix(validate): run on every pull request so the required check always reports 2026-10-03 22:25:22 +01:00
lukaszraczylo 1aece66c7f feat: validate workflows and actions, and prepare Renovate bumps
scripts/check-actions.sh runs actionlint and checks that every external
uses: reference resolves. The validate workflow runs it, then runs the
go-test and node-build actions and the node-pr workflow against small
fixtures, so a bump of an action they use is exercised before it merges.

renovate.json bumps the actions this repository uses. Minor and patch
bumps merge themselves once validate is green. Major bumps wait for a
person, because every consumer calls these actions at @main. The same
script runs as a Renovate post-upgrade task and marks a failing branch so
no PR opens.
2026-10-03 22:22:22 +01:00
lukaszraczylo 2e49670452 feat(autoupdate): make go mod tidy optional
Encore adds imports at build time, so go mod tidy prunes go.sum entries
that the Encore build needs, and every batch failed with a missing go.sum
entry. Add go-mod-tidy, on by default, so an Encore app can turn it off.
2026-10-03 21:48:33 +01:00
lukaszraczylo 85900e7304 fix(autoupdate): give Renovate the pnpm version the tests use
Renovate wrote the lockfile with its own pnpm, in a form the pinned pnpm
rejected as an overrides mismatch, so every branch failed to install. Pass
pnpm-version to Renovate as a constraint.
2026-10-03 21:31:19 +01:00
lukaszraczylo 319b564d14 feat(autoupdate): let a repo set its own Go prepare and test commands
An Encore app cannot be tested with plain go build and go test. Add
go-prepare-command, which runs before the tests, and go-test-command, which
replaces the default Go build and test commands.
2026-10-03 21:30:17 +01:00
lukaszraczylo f854725a97 feat(node): let a caller pin the pnpm version
A repo with no packageManager field got the newest pnpm through Corepack.
Several repos pin pnpm in their own workflows instead. Add a pnpm-version
input to node-pr and renovate-autoupdate and activate it with corepack.
2026-10-03 21:05:05 +01:00
lukaszraczylo b06a5bb1b1 feat(autoupdate): dispatch several workflows after a merge
A repo can have more than one workflow that a push used to trigger, such
as a Docker build and a site deploy. Let release-workflow take a
comma-separated list and dispatch each one.
2026-10-03 21:04:20 +01:00
lukaszraczylo bdbd313c0d fix(autoupdate): let Renovate read issues in a private repo
Renovate queries the repository issues when it starts. The job token had
no issues permission, so a private repo returned FORBIDDEN and Renovate
stopped with platform-unknown-error. Public repos expose issues, which hid
the problem. Grant issues: read to the Renovate job.
2026-10-03 20:17:52 +01:00
lukaszraczylo 5e0790e131 feat(autoupdate): add a log-level input for Renovate
A Renovate failure at info level hides the cause. Let a caller raise the
level to debug for one run.
2026-10-03 20:13:26 +01:00
lukaszraczylo 8126310820 feat(node-pr): add pull request checks for Node projects
Add a reusable workflow that installs without changing the lockfile and
runs lint, typecheck, test and build, skipping scripts that do not exist.
It follows go-pr: a push to a branch with an open PR skips the duplicate
run, and stale runs are cancelled.
2026-10-03 18:53:55 +01:00
lukaszraczylo 114812c70e feat(autoupdate): update only the directories that are tested
Renovate updated every go.mod and package.json in a repo, while the tests
cover one module and one Node project. An update outside them would merge
untested. Restrict the managers to the configured directories, and add go
and node switches for a repo that has no Go code or no frontend to test.
2026-10-03 18:42:09 +01:00
lukaszraczylo c12df22051 fix(autoupdate): make Go major updates real
A Go major update changes the import path. Without rewriting imports the
PR only added the new module to go.mod, the tests passed, and Renovate
proposed it again. Rewrite the imports with gomodUpdateImportPaths so the
build tests the actual update, and cap indirect dependencies at their
current major, which the parent module decides.
2026-10-03 18:11:40 +01:00
lukaszraczylo 46d523860a fix(autoupdate): test the default branch and handle merge conflicts
The checkout used the triggering ref, so a run started from another
branch tested a stale tree and then hit conflicts. Check out the default
branch explicitly. When a passing PR conflicts, close it and skip, and
when the merge fails, close the PR and fail the job. Only a real test
failure goes to the issue.
2026-10-03 17:52:11 +01:00
lukaszraczylo 6f8fec0956 fix(autoupdate): recreate update branches whose PR was closed
Renovate skips a branch when a PR with the same title was closed, and
adds a comment to that PR. A PR closed after a merge or by hand must not
block the next update, so set recreateWhen to always.
2026-10-03 17:13:44 +01:00
lukaszraczylo 94d1fe3409 feat(autoupdate): report failing updates with their test output
A failing update has no PR, so its test output had nowhere to go. Capture
the output of the Go and Node steps. On failure, write it as a comment on
one sticky issue, one comment per branch, updated on every run. A final
job removes comments for branches that are gone and closes the issue when
no update fails. The step is best effort and also writes the run summary.
2026-10-03 17:05:17 +01:00
lukaszraczylo dc0437151c feat(autoupdate): open a PR only after the tests pass
Renovate now prepares branches and opens no PR. Each branch is merged
into the default branch locally and tested, one at a time. Only a branch
that passes gets a PR, which merges at once, so a failing update never
shows up as a PR. Majors default to one branch each. The release is
dispatched once, after anything merged.
2026-10-03 16:52:15 +01:00
lukaszraczylo aca729f8f7 fix(autoupdate): skip major updates by default
A repo with a backlog of majors got one PR per major on the first run.
Replace include-major with major-updates: ignore (default), separate or
batch. Ignore uses a version cap, because rules that disable by update
type have no effect.
2026-10-03 16:47:43 +01:00
lukaszraczylo 97b4c0ec7e fix(autoupdate): run the Renovate workflow with the workflow token only
The workflow runs inside the calling repository, so its own token is
enough and no PAT is needed. Drop the PAT fallbacks and make admin merge
opt-in, because the workflow token cannot bypass branch protection.
A merge made with that token does not trigger push workflows, so add a
release-workflow input that dispatches the release after the merge.
2026-10-03 16:07:46 +01:00
lukaszraczylo 413f9c3064 feat(autoupdate): add a Renovate workflow for Go and Node projects
Renovate batches every minor and patch update in one PR. The workflow
tests that branch with go build and go test for Go and with the
package.json scripts for npm, pnpm and yarn. It squash-merges the PR only
when every test passes. Major updates get their own PR and never merge by
themselves. A renovate.json in the calling repo adds project rules.
2026-10-03 16:01:34 +01:00
lukaszraczylo fe70d4c707 fix(release): pass a GoReleaser timeout of 60 minutes
The continue command that merges split builds stops after 30 minutes by
default. A slow multi-architecture docker build under QEMU hit that
limit and the superclaw release failed with context canceled after
30 minutes.

The goreleaser action takes a timeout input, default 60m, and passes it
to release, release --split and continue --merge. The release workflows
expose it as release-timeout.
2026-10-03 00:05:15 +01:00
lukaszraczylo ac32cb03c4 feat(release): make the QEMU binfmt image an input
The default stays qemu-v8.1.5. A caller whose arm64 build crashes under that version can pass another image.
2026-10-02 15:49:16 +01:00
lukaszraczylo a6a9c55bdf fix(release): pin QEMU binfmt image to qemu-v8.1.5
The unpinned latest binfmt image can crash arm64 apt installs with a segmentation fault.
Pin the image to a known stable release for reproducible multi-arch builds.
2026-10-02 11:17:50 +01:00
lukaszraczylo 9a042ecafd fix(go-pr): read only the total line of the coverage report
The coverage step matched every line that contains the word total, so a
function name such as subtotal added a second value. GitHub then
rejected the multi-line step output. The step now reads the line that
starts with total:.
2026-10-02 04:33:59 +01:00
lukaszraczylo 5390791174 fix(go-autoupdate): fall back to direct dependencies when a full update breaks the build
go get -u updates indirect modules past the versions their parents
support. For Kubernetes projects the build then fails and the daily
update has failed since early September. The step now builds after a
full update. On failure it restores go.mod and go.sum and updates the
direct dependencies only.

The Go toolchain also uses check-latest so a range such as >=1.24
resolves to the newest release.
2026-10-02 02:48:47 +01:00
lukaszraczylo 4f53b0593e fix(go-pr): skip the report job when the run is cancelled
A run cancelled by a newer push still ran the report job. The gate then
failed and marked the superseded run as failed. The report job now
skips when the run is cancelled.
2026-10-02 02:35:03 +01:00
lukaszraczylo c9823f320e fix(workflows): parenthesise the runner fallback chain
The && operator bound to the first operand only, so the label branch
returned the bare label before the format call. Parentheses keep the
whole fallback chain on the && branch.
2026-10-02 01:32:09 +01:00
lukaszraczylo 5bc07d18ae fix(workflows): quote the runner label with format instead of toJSON
GitHub rejected the runs-on expression: fromJSON received the bare
label. The expression now wraps the label in quotes with format.
2026-10-02 01:31:55 +01:00
lukaszraczylo 9533a6518f feat(preflight): probe release and ghcr push access
A caller can grant narrower permissions than the release job needs. The
release then fails at the end, when it creates the tag or pushes an
image.

The preflight job now declares the same contents and packages
permissions as the release job and probes with the real token. A git
push dry run checks that the token can create the tag and release. A
ghcr.io token request and a blob upload session check that the token can
push the image. The upload session creates no package.

The release-cgo workflow probes ghcr only when the GoReleaser config
builds ghcr.io images. The release workflow probes it when
docker-enabled is true and the registry is ghcr.io. A probe that cannot
reach a verdict warns and does not fail.
2026-10-02 01:27:01 +01:00
lukaszraczylo f9b22ef8d9 feat(preflight): fail early when a secret or repository access is missing
A release run used to fail at the GoReleaser step when a secret was
empty, after the tests and the version job had finished.

A new preflight action checks the required names, the .Env references
in the GoReleaser config and push access to optional repositories. It
lists every problem in one run. The release and release-cgo workflows
run it in a first job, so a missing secret fails in seconds.

The release-cgo workflow requires GORELEASER_PRO. The release workflow
requires the secrets that the GoReleaser config references. Set the
preflight input to false to skip the check. Set preflight-repos to check
access to a Homebrew tap or helm-charts repository.
2026-10-02 01:23:56 +01:00
lukaszraczylo 6b47cbd317 feat(go-pr): add runner input and a single PR checks report
The workflow takes the same runner input as the release workflows.

Findings from go vet and staticcheck now appear as inline annotations
on the pull request diff. A new report job posts one comment with the
result of every check and the coverage. It fails when a check fails or
coverage is below the threshold. It no longer needs the bc command.

A push to a branch with an open pull request now skips its run, because
the pull_request event already runs the checks. Stale runs on the same
branch are cancelled. Every job has a timeout.
2026-10-02 01:20:26 +01:00
lukaszraczylo cce6b9d88c feat(workflows): add runner input, timeouts and release concurrency
The release, release-cgo and autoupdate workflows must run on a runner
the caller chooses. Each workflow now takes a runner input. It accepts
a label or a JSON object that selects a runner group.

The workflow uses inputs.runner first. It then uses the
SHARED_ACTIONS_RUNNER variable and falls back to ubuntu-latest. Callers
that set nothing keep the old behaviour.

Every job now has a timeout. Release and autoupdate runs use a
concurrency group that never cancels a running job.
2026-10-02 01:20:24 +01:00
lukaszraczylo 5cf1402555 fix(go-autoupdate): fall back to github.token when HOMEBREW_TAP_TOKEN is unset
create-pull-request and the gh pr merge step both hard-required HOMEBREW_TAP_TOKEN,
so any consumer repo without that secret got 'Input token not supplied' and the
whole Autoupdate run failed. A same-repo PR needs only the caller's
contents/pull-requests write; fall back to the auto-provisioned github.token.
Consumers that do set the tap token keep current behavior.
2026-08-10 10:25:57 +01:00
lukaszraczylo 72ef4441eb feat(go-release): add optional runner input (default ubuntu-latest)
Lets a caller run the release jobs on a self-hosted runner via with.runner,
e.g. runner: self-hosted. Defaults to ubuntu-latest so existing consumers are
unaffected.
2026-06-18 13:36:28 +01:00
lukaszraczylo a4cf065ea1 ci(goreleaser): commit build-time source changes into the tagged commit
Before tagging, fold any working-tree changes left by a repo-local workflow-prepare.sh (e.g. version stamping) into the tagged commit. Without this the tag captured the unstamped source AND GoReleaser's 'release --clean' failed on the dirty tree. The commit is reachable only via the tag (the branch is not pushed), so a 0.0.0-dev placeholder on main is preserved. No-op when the tree is clean, so repos that do not stamp are unaffected.
2026-05-30 13:09:30 +01:00
lukaszraczylo 58ab34e4cf ci: expose computed VERSION/VERSION_TAG to workflow-prepare.sh in release job
The release job now passes the calculated semver (bare VERSION and v-prefixed VERSION_TAG) into the repo-local workflow-prepare.sh hook's environment, so a consumer repo can stamp its version into source at build time. Needed for runtimes that cannot resolve their version from build info at runtime (e.g. Yaegi-interpreted Traefik plugins). Additive and backward-compatible: the test/version jobs run the hook without a version, and repos with no hook (or one that ignores VERSION) are unaffected.
2026-05-30 13:06:13 +01:00
lukaszraczylo fb34ae51e5 Revert "fixup! chore(goreleaser): pin sigstore/cosign-installer to v4.1.2"
This reverts commit cc643787c5.
2026-05-22 00:33:40 +01:00
lukaszraczylo cc643787c5 fixup! chore(goreleaser): pin sigstore/cosign-installer to v4.1.2 2026-05-22 00:22:12 +01:00
lukaszraczylo 486ef6e3a1 chore(goreleaser): pin sigstore/cosign-installer to v4.1.2 2026-05-21 03:28:54 +01:00
lukaszraczylo e4dac8969a chore(actions): bump shared actions to latest major versions
- actions/checkout v4 -> v6
- actions/setup-go v5 -> v6
- actions/setup-node v4 -> v6
- actions/upload-artifact v4 -> v7
- actions/download-artifact v4 -> v8
- actions/github-script v7 -> v9
- goreleaser/goreleaser-action v6 -> v7
- docker/login-action v3 -> v4
- docker/setup-buildx-action v3 -> v4
- docker/setup-qemu-action v3 -> v4
- sigstore/cosign-installer v3 -> v4
- peter-evans/create-pull-request v7 -> v8
2026-05-21 03:14:01 +01:00
20 changed files with 2053 additions and 127 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ runs:
using: "composite" using: "composite"
steps: steps:
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
+25 -7
View File
@@ -20,6 +20,10 @@ inputs:
description: "GoReleaser Pro license key (for split/merge)" description: "GoReleaser Pro license key (for split/merge)"
required: false required: false
default: "" default: ""
timeout:
description: "GoReleaser timeout for the whole step (Go duration, e.g. 60m). The continue command defaults to 30m, which cuts off slow multi-architecture docker builds."
required: false
default: "60m"
homebrew-tap-token: homebrew-tap-token:
description: "Homebrew tap token (optional)" description: "Homebrew tap token (optional)"
required: false required: false
@@ -33,21 +37,33 @@ runs:
run: | run: |
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com" git config user.email "github-actions[bot]@users.noreply.github.com"
# Fold any build-time source changes (e.g. version stamping by a
# repo-local workflow-prepare.sh) into the tagged commit. This is needed
# so consumers that fetch the tag's SOURCE — e.g. Yaegi-interpreted
# Traefik plugins, which Traefik never compiles — see the stamped value,
# and so GoReleaser's `release --clean` sees a clean working tree. The
# commit is reachable only via the tag; the branch is NOT advanced, so a
# source-tree placeholder (e.g. 0.0.0-dev on main) is preserved. No-op
# when the tree is already clean → unchanged for repos that don't stamp.
if ! git diff --quiet || ! git diff --cached --quiet; then
git add -A
git commit -m "chore(release): ${{ inputs.version-tag }}"
fi
git tag -a ${{ inputs.version-tag }} -m "Release ${{ inputs.version-tag }}" || true git tag -a ${{ inputs.version-tag }} -m "Release ${{ inputs.version-tag }}" || true
if [[ "${{ inputs.mode }}" != "split" ]]; then if [[ "${{ inputs.mode }}" != "split" ]]; then
git push origin ${{ inputs.version-tag }} || true git push origin ${{ inputs.version-tag }} || true
fi fi
- name: Install cosign - name: Install cosign
uses: sigstore/cosign-installer@v3 uses: sigstore/cosign-installer@v4.1.3
- name: Run GoReleaser (full) - name: Run GoReleaser (full)
if: inputs.mode == 'full' if: inputs.mode == 'full'
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
distribution: goreleaser distribution: goreleaser
version: "~> v2" version: "~> v2"
args: release --clean args: release --clean --timeout ${{ inputs.timeout }}
env: env:
GITHUB_TOKEN: ${{ inputs.github-token }} GITHUB_TOKEN: ${{ inputs.github-token }}
HOMEBREW_TAP_TOKEN: ${{ inputs.homebrew-tap-token }} HOMEBREW_TAP_TOKEN: ${{ inputs.homebrew-tap-token }}
@@ -55,23 +71,25 @@ runs:
- name: Run GoReleaser Pro (split) - name: Run GoReleaser Pro (split)
if: inputs.mode == 'split' if: inputs.mode == 'split'
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
distribution: goreleaser-pro distribution: goreleaser-pro
version: "~> v2" version: "~> v2"
args: release --clean --split args: release --clean --split --timeout ${{ inputs.timeout }}
env: env:
GITHUB_TOKEN: ${{ inputs.github-token }} GITHUB_TOKEN: ${{ inputs.github-token }}
GORELEASER_KEY: ${{ inputs.goreleaser-key }} GORELEASER_KEY: ${{ inputs.goreleaser-key }}
HOMEBREW_TAP_TOKEN: ${{ inputs.homebrew-tap-token }}
CGO_ENABLED: ${{ inputs.cgo-enabled }} CGO_ENABLED: ${{ inputs.cgo-enabled }}
- name: Run GoReleaser Pro (merge) - name: Run GoReleaser Pro (merge)
if: inputs.mode == 'merge' if: inputs.mode == 'merge'
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
distribution: goreleaser-pro distribution: goreleaser-pro
version: "~> v2" version: "~> v2"
args: continue --merge args: continue --merge --timeout ${{ inputs.timeout }}
env: env:
GITHUB_TOKEN: ${{ inputs.github-token }} GITHUB_TOKEN: ${{ inputs.github-token }}
GORELEASER_KEY: ${{ inputs.goreleaser-key }} GORELEASER_KEY: ${{ inputs.goreleaser-key }}
HOMEBREW_TAP_TOKEN: ${{ inputs.homebrew-tap-token }}
+1 -1
View File
@@ -18,7 +18,7 @@ runs:
using: "composite" using: "composite"
steps: steps:
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v7
with: with:
node-version: ${{ inputs.node-version }} node-version: ${{ inputs.node-version }}
cache: "npm" cache: "npm"
+163
View File
@@ -0,0 +1,163 @@
name: "Preflight"
description: "Fail early when a required secret, env var or repository access is missing"
inputs:
require:
description: "Comma-separated names that must be set and non-empty in the step env"
required: false
default: ""
goreleaser-scan:
description: "Also require every .Env.NAME referenced by the GoReleaser config"
required: false
default: "true"
repo-access:
description: "Comma-separated owner/repo list the token must have push access to"
required: false
default: ""
repo-token-env:
description: "Name of the env var that holds the token for repo-access"
required: false
default: "HOMEBREW_TAP_TOKEN"
release-write:
description: "Probe that GITHUB_TOKEN can push to this repository (needed to create tags and releases)"
required: false
default: "false"
ghcr-push:
description: "Probe push access to ghcr.io: true, false, or auto (only when the GoReleaser config builds ghcr.io images)"
required: false
default: "false"
ghcr-image:
description: "Image path (owner/name) for the ghcr probe. Default: first ghcr.io path in the GoReleaser config, else the repository"
required: false
default: ""
ghcr-token-env:
description: "Name of the env var that holds the ghcr token"
required: false
default: "GITHUB_TOKEN"
runs:
using: "composite"
steps:
- name: Check prerequisites
shell: bash
env:
PF_REQUIRE: ${{ inputs.require }}
PF_SCAN: ${{ inputs.goreleaser-scan }}
PF_REPOS: ${{ inputs.repo-access }}
PF_TOKEN_ENV: ${{ inputs.repo-token-env }}
PF_RELEASE_WRITE: ${{ inputs.release-write }}
PF_GHCR: ${{ inputs.ghcr-push }}
PF_GHCR_IMAGE: ${{ inputs.ghcr-image }}
PF_GHCR_TOKEN_ENV: ${{ inputs.ghcr-token-env }}
run: |
missing=()
add_missing() { # name reason
case " ${missing[*]-} " in *" $1 "*) return ;; esac
missing+=("$1")
echo "::error title=Missing $1::$2"
}
is_set() { [ -n "${!1:-}" ]; }
IFS=',' read -r -a required <<< "$PF_REQUIRE"
for name in "${required[@]-}"; do
name="${name// /}"
[ -z "$name" ] && continue
is_set "$name" || add_missing "$name" "Required by this workflow but empty. Set the repository or organisation secret $name and make sure the caller passes 'secrets: inherit'."
done
if [ "$PF_SCAN" = "true" ]; then
for cfg in .goreleaser.yaml .goreleaser.yml goreleaser.yaml goreleaser.yml; do
[ -f "$cfg" ] || continue
echo "Scanning $cfg for .Env references"
while IFS= read -r ref; do
name="${ref#.Env.}"
is_set "$name" || add_missing "$name" "$cfg references .Env.$name but it is not available to the GoReleaser step. GoReleaser would fail at the end of the run."
done < <(grep -vE '^[[:space:]]*#' "$cfg" | grep -oE '\.Env\.[A-Za-z_][A-Za-z0-9_]*' | sort -u)
break
done
fi
if [ -n "$PF_REPOS" ]; then
token="${!PF_TOKEN_ENV:-}"
if [ -z "$token" ]; then
add_missing "$PF_TOKEN_ENV" "repo-access needs this token but it is empty."
else
IFS=',' read -r -a repos <<< "$PF_REPOS"
for repo in "${repos[@]}"; do
repo="${repo// /}"
[ -z "$repo" ] && continue
body="$(mktemp)"
code="$(curl -sS -o "$body" -w '%{http_code}' \
-H "Authorization: Bearer $token" \
-H "Accept: application/vnd.github+json" \
"${GITHUB_API_URL:-https://api.github.com}/repos/$repo")" || code="000"
if [ "$code" != "200" ]; then
add_missing "access:$repo" "$PF_TOKEN_ENV cannot read $repo (HTTP $code). Check the token scope, expiry and repository access."
elif ! grep -qE '"push": *true' "$body"; then
add_missing "access:$repo" "$PF_TOKEN_ENV can read $repo but has no push access."
fi
rm -f "$body"
done
fi
fi
if [ "$PF_RELEASE_WRITE" = "true" ]; then
out="$(git push --dry-run origin HEAD:refs/heads/preflight-probe 2>&1)" && rc=0 || rc=$?
if [ "$rc" -ne 0 ]; then
if printf '%s' "$out" | grep -qiE 'denied|403|401|not permitted|could not read Username'; then
add_missing "contents:write" "The token cannot push to this repository, so it cannot create the tag or release. Grant 'contents: write' in the caller workflow permissions and check the repository Actions settings. Git said: $(printf '%s' "$out" | tail -n 1)"
else
echo "::warning title=Push probe inconclusive::$(printf '%s' "$out" | tail -n 1)"
fi
fi
fi
ghcr_wanted="$PF_GHCR"
cfg_found=""
for cfg in .goreleaser.yaml .goreleaser.yml goreleaser.yaml goreleaser.yml; do
[ -f "$cfg" ] && { cfg_found="$cfg"; break; }
done
if [ "$ghcr_wanted" = "auto" ]; then
ghcr_wanted=false
if [ -n "$cfg_found" ] && grep -qE '^(dockers|dockers_v2|docker_manifests):' "$cfg_found" && grep -q 'ghcr\.io' "$cfg_found"; then
ghcr_wanted=true
fi
fi
if [ "$ghcr_wanted" = "true" ]; then
gtoken="${!PF_GHCR_TOKEN_ENV:-}"
image="$PF_GHCR_IMAGE"
if [ -z "$image" ] && [ -n "$cfg_found" ]; then
image="$(grep -oE 'ghcr\.io/[A-Za-z0-9._/-]+' "$cfg_found" | head -n 1 | sed 's|^ghcr\.io/||')"
fi
image="${image:-$GITHUB_REPOSITORY}"
image="$(printf '%s' "$image" | tr '[:upper:]' '[:lower:]')"
if [ -z "$gtoken" ]; then
add_missing "$PF_GHCR_TOKEN_ENV" "ghcr push needs this token but it is empty."
else
tbody="$(mktemp)"
code="$(curl -sS -o "$tbody" -w '%{http_code}' -u "${GITHUB_ACTOR:-token}:$gtoken" \
"https://ghcr.io/token?service=ghcr.io&scope=repository:$image:push,pull")" || code="000"
btoken="$(sed -n 's/.*"token" *: *"\([^"]*\)".*/\1/p' "$tbody" | head -n 1)"
rm -f "$tbody"
if [ "$code" = "200" ] && [ -n "$btoken" ]; then
ucode="$(curl -sS -o /dev/null -w '%{http_code}' -X POST -H "Authorization: Bearer $btoken" \
"https://ghcr.io/v2/$image/blobs/uploads/")" || ucode="000"
case "$ucode" in
202) ;;
401|403) add_missing "packages:write" "The token cannot push ghcr.io/$image (HTTP $ucode). Grant 'packages: write' in the caller workflow permissions, and for an existing package allow this repository under Package settings, Manage Actions access." ;;
*) echo "::warning title=ghcr probe inconclusive::upload session for $image returned HTTP $ucode" ;;
esac
elif [ "$code" = "401" ] || [ "$code" = "403" ]; then
add_missing "packages:write" "ghcr.io refused the token for $image (HTTP $code). Grant 'packages: write' in the caller workflow permissions."
else
echo "::warning title=ghcr probe inconclusive::token request for $image returned HTTP $code"
fi
fi
fi
if [ "${#missing[@]}" -gt 0 ]; then
echo "Preflight failed: ${missing[*]}"
exit 1
fi
echo "Preflight passed"
+33 -8
View File
@@ -19,14 +19,25 @@ on:
type: boolean type: boolean
default: false default: false
runner:
description: "Runner label, or JSON object such as {\"group\":\"ci\",\"labels\":[\"linux\"]} to select a runner group. Falls back to vars.SHARED_ACTIONS_RUNNER, then ubuntu-latest."
required: false
type: string
default: ""
concurrency:
group: autoupdate-${{ github.repository }}-${{ github.ref }}
cancel-in-progress: false
jobs: jobs:
autoupdate: autoupdate:
name: Update dependencies and test name: Update dependencies and test
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 30
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -40,15 +51,29 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
check-latest: true
cache: true cache: true
- name: Update dependencies - name: Update dependencies
shell: bash
run: | run: |
go get -u ./... # Indirect modules can move ahead of their parents (for example
go mod tidy # kube-openapi ahead of apimachinery), which breaks the build.
update_all() { go get -u ./... && go mod tidy && go build ./...; }
update_direct() {
local mods=()
while IFS= read -r m; do mods+=("$m"); done < <(go list -m -f '{{if and (not .Indirect) (not .Main)}}{{.Path}}@latest{{end}}' all)
if [ "${#mods[@]}" -gt 0 ]; then go get "${mods[@]}"; fi
go mod tidy
}
if ! update_all; then
echo "::warning title=Full update failed::Falling back to direct dependencies only"
git checkout -- go.mod go.sum
update_direct
fi
- name: Run tests - name: Run tests
run: go test -race -cover ./... run: go test -race -cover ./...
@@ -65,9 +90,9 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
id: create-pr id: create-pr
if: steps.changes.outputs.changes_detected == 'true' if: steps.changes.outputs.changes_detected == 'true'
uses: peter-evans/create-pull-request@v7 uses: peter-evans/create-pull-request@v8
with: with:
token: ${{ secrets.HOMEBREW_TAP_TOKEN }} token: ${{ secrets.HOMEBREW_TAP_TOKEN || github.token }}
commit-message: "Update go.mod and go.sum" commit-message: "Update go.mod and go.sum"
title: "Update Go dependencies" title: "Update Go dependencies"
body: | body: |
@@ -82,4 +107,4 @@ jobs:
if: steps.create-pr.outputs.pull-request-number if: steps.create-pr.outputs.pull-request-number
run: gh pr merge --squash --delete-branch --admin "${{ steps.create-pr.outputs.pull-request-number }}" run: gh pr merge --squash --delete-branch --admin "${{ steps.create-pr.outputs.pull-request-number }}"
env: env:
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN || github.token }}
+148 -74
View File
@@ -24,19 +24,61 @@ on:
type: string type: string
default: "" default: ""
runner:
description: "Runner label, or JSON object such as {\"group\":\"ci\",\"labels\":[\"linux\"]} to select a runner group. Falls back to vars.SHARED_ACTIONS_RUNNER, then ubuntu-latest."
required: false
type: string
default: ""
# Caller must declare these permissions: # Caller must declare these permissions:
# permissions: # permissions:
# contents: read # contents: read
# pull-requests: write # pull-requests: write
# security-events: write # security-events: write
concurrency:
group: go-pr-${{ github.repository }}-${{ github.event_name }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
jobs: jobs:
pre:
name: Detect duplicate run
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 5
outputs:
skip: ${{ steps.dup.outputs.skip }}
steps:
# A push to a branch with an open PR also fires pull_request; run only the PR one.
- name: Skip push run when a PR is open
id: dup
uses: actions/github-script@v9
with:
script: |
let skip = false;
if (context.eventName === 'push') {
try {
const { data } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`,
state: 'open',
});
skip = data.length > 0;
} catch (e) {
core.warning(`PR lookup failed, running checks: ${e.message}`);
}
}
core.setOutput('skip', String(skip));
if (skip) core.notice('Open PR found for this branch; checks run on the pull_request event.');
static-analysis: static-analysis:
name: Static Analysis name: Static Analysis
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
needs: pre
if: needs.pre.outputs.skip != 'true'
timeout-minutes: 15
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -50,7 +92,7 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
cache: true cache: true
@@ -58,6 +100,14 @@ jobs:
- name: Install staticcheck - name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Register problem matcher
shell: bash
run: |
cat > "$RUNNER_TEMP/go-problem-matcher.json" <<'JSON'
{"problemMatcher":[{"owner":"go-lint","severity":"error","pattern":[{"regexp":"^(?:vet: )?([^\\s:]+\\.go):(\\d+):(\\d+): (.+)$","file":1,"line":2,"column":3,"message":4}]}]}
JSON
echo "::add-matcher::$RUNNER_TEMP/go-problem-matcher.json"
- name: Run go vet - name: Run go vet
run: go vet ./... run: go vet ./...
@@ -66,10 +116,13 @@ jobs:
security-scan: security-scan:
name: Security Scan name: Security Scan
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
needs: pre
if: needs.pre.outputs.skip != 'true'
timeout-minutes: 20
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -83,7 +136,7 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
cache: true cache: true
@@ -123,13 +176,16 @@ jobs:
gosec: gosec:
name: Gosec SARIF name: Gosec SARIF
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
needs: pre
if: needs.pre.outputs.skip != 'true'
timeout-minutes: 15
permissions: permissions:
contents: read contents: read
security-events: write security-events: write
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -143,7 +199,7 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
cache: true cache: true
@@ -164,10 +220,13 @@ jobs:
goreleaser-check: goreleaser-check:
name: GoReleaser Config Validation name: GoReleaser Config Validation
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
needs: pre
if: needs.pre.outputs.skip != 'true'
timeout-minutes: 10
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -181,14 +240,14 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
cache: true cache: true
- name: Check goreleaser config - name: Check goreleaser config
if: hashFiles('.goreleaser.yml', '.goreleaser.yaml') != '' if: hashFiles('.goreleaser.yml', '.goreleaser.yaml') != ''
uses: goreleaser/goreleaser-action@v6 uses: goreleaser/goreleaser-action@v7
with: with:
distribution: goreleaser distribution: goreleaser
version: "~> v2" version: "~> v2"
@@ -196,13 +255,16 @@ jobs:
codeql: codeql:
name: CodeQL Analysis name: CodeQL Analysis
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
needs: pre
if: needs.pre.outputs.skip != 'true'
timeout-minutes: 45
permissions: permissions:
contents: read contents: read
security-events: write security-events: write
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -215,7 +277,7 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
cache: true cache: true
@@ -233,12 +295,15 @@ jobs:
test: test:
name: Tests & Coverage name: Tests & Coverage
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
needs: pre
if: needs.pre.outputs.skip != 'true'
timeout-minutes: 30
outputs: outputs:
coverage: ${{ steps.coverage.outputs.coverage }} coverage: ${{ steps.coverage.outputs.coverage }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -252,7 +317,7 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
cache: true cache: true
@@ -272,70 +337,79 @@ jobs:
- name: Calculate coverage - name: Calculate coverage
id: coverage id: coverage
run: | run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//') COVERAGE=$(go tool cover -func=coverage.out | awk '/^total:/ {print $3}' | sed 's/%//')
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "Total Coverage: $COVERAGE%" echo "Total Coverage: $COVERAGE%"
coverage-report: report:
name: Coverage Report name: PR Checks Report
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
needs: test needs: [pre, static-analysis, security-scan, gosec, goreleaser-check, codeql, test]
if: always() && needs.test.result == 'success' if: ${{ !cancelled() && needs.pre.outputs.skip != 'true' }}
timeout-minutes: 10
permissions:
contents: read
pull-requests: write
steps: steps:
- name: Comment coverage on PR - name: Summarise, comment and gate
if: github.event_name == 'pull_request' uses: actions/github-script@v9
uses: actions/github-script@v7 env:
NEEDS: ${{ toJSON(needs) }}
THRESHOLD: ${{ inputs.coverage-threshold }}
with: with:
script: | script: |
const coverage = '${{ needs.test.outputs.coverage }}'; const needs = JSON.parse(process.env.NEEDS);
const threshold = ${{ inputs.coverage-threshold }}; const threshold = Number(process.env.THRESHOLD);
const coverageNum = parseFloat(coverage); const labels = {
const hasThreshold = threshold > 0; 'static-analysis': 'Static analysis (vet, staticcheck)',
const meetsThreshold = !hasThreshold || coverageNum >= threshold; 'security-scan': 'Security scan (TruffleHog, govulncheck)',
const emoji = meetsThreshold ? '✅' : '⚠️'; 'gosec': 'Gosec',
const status = hasThreshold ? (meetsThreshold ? 'meets' : 'below') + ' threshold' : 'reported'; 'goreleaser-check': 'GoReleaser config',
'codeql': 'CodeQL',
let body = `## ${emoji} Test Coverage Report\n\n| Metric | Value |\n|--------|-------|\n| **Total Coverage** | ${coverage}% |`; 'test': 'Tests (race) & coverage',
if (hasThreshold) { };
body += `\n| **Threshold** | ${threshold}% |\n| **Status** | ${emoji} Coverage ${status} |`; const icon = { success: '✅', failure: '❌', cancelled: '🚫', skipped: '⏭️' };
const failed = [];
let body = '<!-- go-pr-report -->\n## PR checks\n\n| Check | Result |\n|---|---|\n';
for (const [key, label] of Object.entries(labels)) {
const result = needs[key]?.result ?? 'skipped';
if (result === 'failure' || result === 'cancelled') failed.push(label);
body += `| ${label} | ${icon[result] ?? result} ${result} |\n`;
} }
const { data: comments } = await github.rest.issues.listComments({ const coverage = parseFloat(needs.test?.outputs?.coverage);
issue_number: context.issue.number, const hasCoverage = !Number.isNaN(coverage);
owner: context.repo.owner, if (hasCoverage) {
repo: context.repo.repo, body += `\n**Total coverage:** ${coverage}%`;
}); if (threshold > 0) {
const ok = coverage >= threshold;
body += ` (threshold ${threshold}%: ${ok ? '✅ met' : '❌ below'})`;
if (!ok) failed.push(`Coverage ${coverage}% below ${threshold}%`);
}
body += '\n';
}
body += `\n[Workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
const botComment = comments.find(comment => await core.summary.addRaw(body, true).write();
comment.user.type === 'Bot' &&
comment.body.includes('Test Coverage Report')
);
if (botComment) { if (context.eventName === 'pull_request') {
await github.rest.issues.updateComment({ try {
comment_id: botComment.id, const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
body: body issue_number: context.issue.number,
}); });
} else { const existing = comments.find(c => c.user.type === 'Bot' &&
await github.rest.issues.createComment({ (c.body.includes('<!-- go-pr-report -->') || c.body.includes('Test Coverage Report')));
issue_number: context.issue.number, const args = { owner: context.repo.owner, repo: context.repo.repo, body };
owner: context.repo.owner, if (existing) {
repo: context.repo.repo, await github.rest.issues.updateComment({ ...args, comment_id: existing.id });
body: body } else {
}); await github.rest.issues.createComment({ ...args, issue_number: context.issue.number });
}
} catch (e) {
core.warning(`Could not post PR comment (fork PR or missing pull-requests: write): ${e.message}`);
}
} }
- name: Check coverage threshold if (failed.length) core.setFailed(`Failed: ${failed.join('; ')}`);
if: inputs.coverage-threshold > 0
run: |
COVERAGE=${{ needs.test.outputs.coverage }}
THRESHOLD=${{ inputs.coverage-threshold }}
echo "Coverage: $COVERAGE%"
echo "Threshold: $THRESHOLD%"
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "❌ Coverage $COVERAGE% is below threshold $THRESHOLD%"
exit 1
fi
echo "✅ Coverage $COVERAGE% meets threshold $THRESHOLD%"
+86 -23
View File
@@ -60,6 +60,26 @@ on:
required: false required: false
type: boolean type: boolean
default: false default: false
runner:
description: "Runner label, or JSON object such as {\"group\":\"ci\",\"labels\":[\"linux\"]} to select a runner group. Falls back to vars.SHARED_ACTIONS_RUNNER, then ubuntu-latest."
required: false
type: string
default: ""
preflight:
description: "Fail early when a required secret, env var or GoReleaser .Env reference is missing"
required: false
type: boolean
default: true
preflight-repos:
description: "Comma-separated owner/repo list the token must have push access to (e.g. a Homebrew tap or helm-charts repo)"
required: false
type: string
default: ""
release-timeout:
description: "GoReleaser timeout for the release step (Go duration)"
required: false
type: string
default: "60m"
outputs: outputs:
version: version:
description: "The calculated version (without v prefix)" description: "The calculated version (without v prefix)"
@@ -68,13 +88,47 @@ on:
description: "The version tag (with v prefix)" description: "The version tag (with v prefix)"
value: ${{ jobs.version.outputs.version_tag }} value: ${{ jobs.version.outputs.version_tag }}
concurrency:
group: release-cgo-${{ github.repository }}-${{ github.ref }}
cancel-in-progress: false
jobs: jobs:
test: preflight:
name: Test name: Preflight
runs-on: ubuntu-latest permissions:
contents: write
packages: write
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 5
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 if: inputs.preflight
uses: actions/checkout@v7
with:
lfs: false
- name: Check secrets and access
if: inputs.preflight
uses: lukaszraczylo/shared-actions/.github/actions/preflight@main
with:
require: GITHUB_TOKEN,GORELEASER_KEY
release-write: "true"
ghcr-push: auto
repo-access: ${{ inputs.preflight-repos }}
repo-token-env: GITHUB_TOKEN
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_KEY: ${{ secrets.GORELEASER_PRO }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
test:
name: Test
needs: preflight
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -95,11 +149,13 @@ jobs:
frontend: frontend:
name: Build Frontend name: Build Frontend
needs: preflight
if: inputs.node-enabled && inputs.node-build-script != '' if: inputs.node-enabled && inputs.node-build-script != ''
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 20
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -112,7 +168,7 @@ jobs:
fi fi
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v7
with: with:
node-version: ${{ inputs.node-version }} node-version: ${{ inputs.node-version }}
cache: "npm" cache: "npm"
@@ -123,7 +179,7 @@ jobs:
run: ${{ inputs.node-build-script }} run: ${{ inputs.node-build-script }}
- name: Upload frontend artifact - name: Upload frontend artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v7
with: with:
name: frontend-dist name: frontend-dist
path: ${{ inputs.node-output-path }} path: ${{ inputs.node-output-path }}
@@ -132,13 +188,14 @@ jobs:
version: version:
name: Calculate Version name: Calculate Version
needs: test needs: test
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
outputs: outputs:
version: ${{ steps.semver.outputs.version }} version: ${{ steps.semver.outputs.version }}
version_tag: ${{ steps.semver.outputs.version_tag }} version_tag: ${{ steps.semver.outputs.version_tag }}
timeout-minutes: 10
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -170,9 +227,10 @@ jobs:
matrix: matrix:
include: ${{ fromJson(inputs.platforms) }} include: ${{ fromJson(inputs.platforms) }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -189,14 +247,14 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
cache: true cache: true
- name: Download frontend artifact - name: Download frontend artifact
if: inputs.node-enabled && inputs.node-embed-path != '' if: inputs.node-enabled && inputs.node-embed-path != ''
uses: actions/download-artifact@v4 uses: actions/download-artifact@v8
with: with:
name: frontend-dist name: frontend-dist
path: ${{ inputs.node-embed-path }} path: ${{ inputs.node-embed-path }}
@@ -207,7 +265,7 @@ jobs:
# are Linux-only in the projects that consume this workflow. # are Linux-only in the projects that consume this workflow.
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
if: matrix.goos == 'linux' if: matrix.goos == 'linux'
uses: docker/login-action@v3 uses: docker/login-action@v4
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
@@ -215,7 +273,7 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
if: matrix.goos == 'linux' if: matrix.goos == 'linux'
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v4
with: with:
driver-opts: image=moby/buildkit:latest driver-opts: image=moby/buildkit:latest
@@ -223,13 +281,15 @@ jobs:
uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main
with: with:
version-tag: ${{ needs.version.outputs.version_tag }} version-tag: ${{ needs.version.outputs.version_tag }}
timeout: ${{ inputs.release-timeout }}
mode: split mode: split
cgo-enabled: "1" cgo-enabled: "1"
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
goreleaser-key: ${{ secrets.GORELEASER_PRO }} goreleaser-key: ${{ secrets.GORELEASER_PRO }}
homebrew-tap-token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Upload artifacts - name: Upload artifacts
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v7
with: with:
name: release-${{ matrix.platform }} name: release-${{ matrix.platform }}
path: dist/ path: dist/
@@ -242,14 +302,15 @@ jobs:
always() && always() &&
needs.version.result == 'success' && needs.version.result == 'success' &&
needs.build.result == 'success' needs.build.result == 'success'
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
permissions: permissions:
contents: write contents: write
packages: write packages: write
id-token: write id-token: write
timeout-minutes: 60
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -263,24 +324,24 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v4
with: with:
driver-opts: image=moby/buildkit:latest driver-opts: image=moby/buildkit:latest
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v4
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Download all artifacts - name: Download all artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v8
with: with:
path: dist path: dist
pattern: release-* pattern: release-*
@@ -289,7 +350,7 @@ jobs:
- name: Download frontend artifact - name: Download frontend artifact
if: inputs.node-enabled && inputs.node-output-path != '' if: inputs.node-enabled && inputs.node-output-path != ''
continue-on-error: true continue-on-error: true
uses: actions/download-artifact@v4 uses: actions/download-artifact@v8
with: with:
name: frontend-dist name: frontend-dist
path: ${{ inputs.node-output-path }} path: ${{ inputs.node-output-path }}
@@ -301,9 +362,11 @@ jobs:
uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main
with: with:
version-tag: ${{ needs.version.outputs.version_tag }} version-tag: ${{ needs.version.outputs.version_tag }}
timeout: ${{ inputs.release-timeout }}
mode: merge mode: merge
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
goreleaser-key: ${{ secrets.GORELEASER_PRO }} goreleaser-key: ${{ secrets.GORELEASER_PRO }}
homebrew-tap-token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Rolling release - name: Rolling release
if: inputs.rolling-release-tag != '' if: inputs.rolling-release-tag != ''
+82 -12
View File
@@ -18,6 +18,11 @@ on:
required: false required: false
type: boolean type: boolean
default: false default: false
qemu-image:
description: "binfmt image that registers QEMU for multi-arch Docker builds"
required: false
type: string
default: "tonistiigi/binfmt:qemu-v8.1.5"
docker-registry: docker-registry:
description: "Docker registry to push to" description: "Docker registry to push to"
required: false required: false
@@ -33,6 +38,26 @@ on:
required: false required: false
type: boolean type: boolean
default: false default: false
runner:
description: "Runner label, or JSON object such as {\"group\":\"ci\",\"labels\":[\"linux\"]} to select a runner group. Falls back to vars.SHARED_ACTIONS_RUNNER, then ubuntu-latest."
required: false
type: string
default: ""
preflight:
description: "Fail early when a required secret, env var or GoReleaser .Env reference is missing"
required: false
type: boolean
default: true
preflight-repos:
description: "Comma-separated owner/repo list the token must have push access to (e.g. a Homebrew tap or helm-charts repo)"
required: false
type: string
default: ""
release-timeout:
description: "GoReleaser timeout for the release step (Go duration)"
required: false
type: string
default: "60m"
outputs: outputs:
version: version:
description: "The calculated version (without v prefix)" description: "The calculated version (without v prefix)"
@@ -41,13 +66,45 @@ on:
description: "The version tag (with v prefix)" description: "The version tag (with v prefix)"
value: ${{ jobs.version.outputs.version_tag }} value: ${{ jobs.version.outputs.version_tag }}
concurrency:
group: release-${{ github.repository }}-${{ github.ref }}
cancel-in-progress: false
jobs: jobs:
test: preflight:
name: Test name: Preflight
runs-on: ubuntu-latest permissions:
contents: write
packages: write
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 5
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 if: inputs.preflight
uses: actions/checkout@v7
with:
lfs: false
- name: Check secrets and access
if: inputs.preflight
uses: lukaszraczylo/shared-actions/.github/actions/preflight@main
with:
require: GITHUB_TOKEN
release-write: "true"
ghcr-push: ${{ inputs.docker-enabled && inputs.docker-registry == 'ghcr.io' && 'true' || 'false' }}
repo-access: ${{ inputs.preflight-repos }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
test:
name: Test
needs: preflight
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v7
with: with:
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -67,13 +124,14 @@ jobs:
version: version:
name: Calculate Version name: Calculate Version
needs: test needs: test
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
outputs: outputs:
version: ${{ steps.semver.outputs.version }} version: ${{ steps.semver.outputs.version }}
version_tag: ${{ steps.semver.outputs.version_tag }} version_tag: ${{ steps.semver.outputs.version_tag }}
timeout-minutes: 10
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
@@ -96,19 +154,28 @@ jobs:
name: Release name: Release
needs: version needs: version
if: needs.version.outputs.version_tag != '' if: needs.version.outputs.version_tag != ''
runs-on: ubuntu-latest runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
permissions: permissions:
contents: write contents: write
packages: write packages: write
id-token: write id-token: write
timeout-minutes: 60
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 0
lfs: ${{ inputs.lfs }} lfs: ${{ inputs.lfs }}
- name: Run workflow prepare script - name: Run workflow prepare script
# Expose the computed release version to a repo-local workflow-prepare.sh
# (e.g. to stamp the version into source for runtimes that cannot resolve
# it at build time, such as Yaegi-interpreted Traefik plugins). Only the
# release job has a version; the test/version jobs run the hook without
# it. VERSION is the bare semver (1.2.3); VERSION_TAG keeps the v prefix.
env:
VERSION: ${{ needs.version.outputs.version }}
VERSION_TAG: ${{ needs.version.outputs.version_tag }}
shell: bash shell: bash
run: | run: |
if [ -f "./workflow-prepare.sh" ]; then if [ -f "./workflow-prepare.sh" ]; then
@@ -117,22 +184,24 @@ jobs:
fi fi
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v7
with: with:
go-version: ${{ inputs.go-version }} go-version: ${{ inputs.go-version }}
# Docker setup (optional) # Docker setup (optional)
- name: Set up QEMU - name: Set up QEMU
if: inputs.docker-enabled if: inputs.docker-enabled
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v4
with:
image: ${{ inputs.qemu-image }}
- name: Set up Docker Buildx - name: Set up Docker Buildx
if: inputs.docker-enabled if: inputs.docker-enabled
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v4
- name: Login to GHCR - name: Login to GHCR
if: inputs.docker-enabled if: inputs.docker-enabled
uses: docker/login-action@v3 uses: docker/login-action@v4
with: with:
registry: ${{ inputs.docker-registry }} registry: ${{ inputs.docker-registry }}
username: ${{ github.actor }} username: ${{ github.actor }}
@@ -142,6 +211,7 @@ jobs:
uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main
with: with:
version-tag: ${{ needs.version.outputs.version_tag }} version-tag: ${{ needs.version.outputs.version_tag }}
timeout: ${{ inputs.release-timeout }}
mode: full mode: full
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
homebrew-tap-token: ${{ secrets.HOMEBREW_TAP_TOKEN }} homebrew-tap-token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
+259
View File
@@ -0,0 +1,259 @@
name: Node Pull Request
# Checks for a Node, Vue or Astro project: install without touching the lockfile,
# then run lint, typecheck, test and build. A script that does not exist is skipped.
on:
workflow_call:
inputs:
node-version:
description: "Node.js version to use"
required: false
type: string
default: "22"
working-directory:
description: "Directory that holds package.json"
required: false
type: string
default: "."
workspace:
description: "The project is a pnpm workspace. working-directory then holds pnpm-workspace.yaml and pnpm-lock.yaml, and needs no package.json. Dependencies install once there, and scripts run in each of packages."
required: false
type: boolean
default: false
packages:
description: "With workspace, comma-separated workspace package directories, relative to working-directory."
required: false
type: string
default: ""
scripts:
description: "Comma-separated package.json scripts to run, in order. A script that does not exist is skipped."
required: false
type: string
default: "lint,typecheck,test,build"
pnpm-version:
description: "pnpm version to use, for a repo whose package.json has no packageManager field. Empty uses the packageManager field, or the newest pnpm."
required: false
type: string
default: ""
require-tests:
description: "Fail when package.json has no test script"
required: false
type: boolean
default: false
lfs:
description: "Enable Git LFS checkout (for repos with large files)"
required: false
type: boolean
default: false
npm-registry-scope:
description: "Scope served by a private npm registry, for example '@fortawesome'. Used only when npm-registry-url and the npm-registry-token secret are also set."
required: false
type: string
default: ""
npm-registry-url:
description: "URL of the private npm registry, for example 'https://npm.fontawesome.com/'. Used only when npm-registry-scope and the npm-registry-token secret are also set."
required: false
type: string
default: ""
runner:
description: "Runner label, or JSON object such as {\"group\":\"ci\",\"labels\":[\"linux\"]} to select a runner group. Falls back to vars.SHARED_ACTIONS_RUNNER, then ubuntu-latest."
required: false
type: string
default: ""
secrets:
npm-registry-token:
description: "Auth token for the private npm registry"
required: false
concurrency:
group: node-pr-${{ github.repository }}-${{ github.event_name }}-${{ github.head_ref || github.ref_name }}-${{ inputs.working-directory }}
cancel-in-progress: true
jobs:
pre:
name: Detect duplicate run
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 5
permissions:
pull-requests: read
outputs:
skip: ${{ steps.dup.outputs.skip }}
steps:
# A push to a branch with an open PR also fires pull_request; run only the PR one.
- name: Skip push run when a PR is open
id: dup
uses: actions/github-script@v9
with:
script: |
let skip = false;
if (context.eventName === 'push') {
try {
const { data } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`,
state: 'open',
});
skip = data.length > 0;
} catch (e) {
core.warning(`PR lookup failed, running checks: ${e.message}`);
}
}
core.setOutput('skip', String(skip));
if (skip) core.notice('Open PR found for this branch; checks run on the pull_request event.');
checks:
name: Checks (${{ inputs.working-directory }})
needs: pre
if: needs.pre.outputs.skip != 'true'
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 30
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v7
with:
lfs: ${{ inputs.lfs }}
- name: Run workflow prepare script
shell: bash
run: |
if [ -f "./workflow-prepare.sh" ]; then
chmod +x ./workflow-prepare.sh
./workflow-prepare.sh
fi
- name: Detect the package manager
id: detect
working-directory: ${{ inputs.working-directory }}
env:
WORKSPACE: ${{ inputs.workspace }}
PACKAGES: ${{ inputs.packages }}
run: |
if [ "$WORKSPACE" = true ]; then
if [ ! -f pnpm-workspace.yaml ] || [ ! -f pnpm-lock.yaml ]; then
echo "::error::workspace needs pnpm-workspace.yaml and pnpm-lock.yaml in ${{ inputs.working-directory }}."
exit 1
fi
count=0
IFS=',' read -r -a packages <<<"$PACKAGES"
for package in "${packages[@]}"; do
package=$(echo "$package" | xargs)
[ -n "$package" ] || continue
if [ ! -f "$package/package.json" ]; then
echo "::error::packages lists $package, but ${{ inputs.working-directory }}/$package/package.json does not exist."
exit 1
fi
count=$((count + 1))
done
if [ "$count" -eq 0 ]; then
echo "::error::workspace needs packages: the packages to check."
exit 1
fi
echo "pm=pnpm" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ ! -f package.json ]; then
echo "::error::No package.json in ${{ inputs.working-directory }}."
exit 1
fi
pm=npm
if [ -f pnpm-lock.yaml ]; then pm=pnpm
elif [ -f yarn.lock ]; then pm=yarn
fi
echo "pm=$pm" >> "$GITHUB_OUTPUT"
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: ${{ inputs.node-version }}
# The npmrc lives in RUNNER_TEMP, not the checkout, so no git command can pick the token up.
- name: Configure the private npm registry
env:
NPM_SCOPE: ${{ inputs.npm-registry-scope }}
NPM_URL: ${{ inputs.npm-registry-url }}
NPM_TOKEN: ${{ secrets.npm-registry-token }}
run: |
[ -n "$NPM_SCOPE" ] && [ -n "$NPM_URL" ] && [ -n "$NPM_TOKEN" ] || exit 0
echo "::add-mask::$NPM_TOKEN"
url="${NPM_URL%/}/"
npmrc="$RUNNER_TEMP/private-registry.npmrc"
(umask 077 && printf '%s:registry=%s\n//%s:_authToken=%s\n' "$NPM_SCOPE" "$url" "${url#*://}" "$NPM_TOKEN" > "$npmrc")
echo "NPM_CONFIG_USERCONFIG=$npmrc" >> "$GITHUB_ENV"
echo "Using a private npm registry for $NPM_SCOPE."
- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
env:
PM: ${{ steps.detect.outputs.pm }}
PNPM_VERSION: ${{ inputs.pnpm-version }}
run: |
# Install without updating the lockfile, so a lockfile that does not match package.json fails.
case "$PM" in
pnpm | yarn)
command -v corepack >/dev/null || npm install --global corepack
corepack enable "$PM"
;;
esac
if [ "$PM" = pnpm ] && [ -n "$PNPM_VERSION" ]; then
corepack prepare "pnpm@$PNPM_VERSION" --activate
fi
case "$PM" in
pnpm) pnpm install --frozen-lockfile ;;
yarn) yarn install --immutable ;;
npm)
if [ -f package-lock.json ]; then npm ci; else npm install; fi
;;
esac
- name: Run scripts
working-directory: ${{ inputs.working-directory }}
env:
PM: ${{ steps.detect.outputs.pm }}
SCRIPTS: ${{ inputs.scripts }}
REQUIRE_TESTS: ${{ inputs.require-tests }}
WORKSPACE: ${{ inputs.workspace }}
PACKAGES: ${{ inputs.packages }}
run: |
# A single project is the one package ".". A workspace is each listed package.
packages=(.)
if [ "$WORKSPACE" = true ]; then
IFS=',' read -r -a packages <<<"$PACKAGES"
fi
if [ "$REQUIRE_TESTS" = true ]; then
for package in "${packages[@]}"; do
package=$(echo "$package" | xargs)
[ -n "$package" ] || continue
if ! jq -e '.scripts.test' "$package/package.json" >/dev/null; then
echo "::error::$package/package.json has no test script."
exit 1
fi
done
fi
ran=()
IFS=',' read -r -a scripts <<<"$SCRIPTS"
for script in "${scripts[@]}"; do
script=$(echo "$script" | xargs)
[ -n "$script" ] || continue
for package in "${packages[@]}"; do
package=$(echo "$package" | xargs)
[ -n "$package" ] || continue
where=""
[ "$package" = . ] || where=" ($package)"
if jq -e --arg s "$script" '.scripts[$s]' "$package/package.json" >/dev/null; then
echo "::group::$PM run $script$where"
(cd "$package" && "$PM" run "$script")
echo "::endgroup::"
ran+=("$script$where")
else
echo "::notice::No '$script' script$where, skipping."
fi
done
done
if [ "${#ran[@]}" -eq 0 ]; then
echo "::warning::None of the scripts ($SCRIPTS) exist in package.json, so nothing was checked."
fi
echo "Ran: ${ran[*]:-none} (${PM})" >> "$GITHUB_STEP_SUMMARY"
+750
View File
@@ -0,0 +1,750 @@
name: Renovate Autoupdate
# Renovate prepares branches with every Go and npm/pnpm/yarn update and opens no PR.
# Each branch is merged into the default branch and tested. Only when the tests
# pass does the workflow open a PR and merge it. Replaces go-autoupdate.
# A renovate.json in the calling repository adds to these defaults.
on:
workflow_call:
inputs:
go-version:
description: "Go version to use"
required: false
type: string
default: ">=1.24"
go:
description: "Update and test the Go module. Turn off for a repo with no Go code."
required: false
type: boolean
default: true
go-working-directory:
description: "Directory that holds go.mod. Only this module is updated and tested."
required: false
type: string
default: "."
node-version:
description: "Node.js version to use"
required: false
type: string
default: "22"
go-mod-tidy:
description: "Run go mod tidy after a Go update. Turn it off for an Encore app: Encore adds imports at build time, so tidy prunes go.sum entries the build needs."
required: false
type: boolean
default: true
go-prepare-command:
description: "Shell commands to run before the Go tests, for example installing a CLI. To put a tool on PATH, append its directory to $GITHUB_PATH."
required: false
type: string
default: ""
go-test-command:
description: "Replaces the default Go build and test commands, for example 'encore test ./...' for an Encore app. It runs in go-working-directory."
required: false
type: string
default: ""
build-tags:
description: "Build tags to pass to go build and go test (e.g., 'fts5'). The default commands then run with CGO_ENABLED=1. Ignored when go-test-command is set."
required: false
type: string
default: ""
node:
description: "Update and test the Node project. Turn off for a repo with no frontend to test."
required: false
type: boolean
default: true
node-working-directory:
description: "Directory that holds package.json. Only this project is updated and tested."
required: false
type: string
default: "."
node-scripts:
description: "Comma-separated package.json scripts to run, in order. A script that does not exist is skipped."
required: false
type: string
default: "lint,typecheck,test,build"
node-workspace:
description: "The Node project is a pnpm workspace. node-working-directory then holds pnpm-workspace.yaml and pnpm-lock.yaml, and needs no package.json. Dependencies install once there, and node-scripts run in each of node-packages."
required: false
type: boolean
default: false
node-packages:
description: "With node-workspace, comma-separated workspace package directories, relative to node-working-directory. Only these are updated and tested."
required: false
type: string
default: ""
pnpm-version:
description: "pnpm version to use, for a repo whose package.json has no packageManager field. Empty uses the packageManager field, or the newest pnpm."
required: false
type: string
default: ""
require-node-tests:
description: "Fail when a Node project has no test script, so an untested update never merges"
required: false
type: boolean
default: true
major-updates:
description: "What to do with major updates: 'separate' gives each its own branch, tested and merged on its own, 'batch' puts them in the one batch, 'ignore' skips them."
required: false
type: string
default: "separate"
minimum-release-age:
description: "Skip releases younger than this, for example '2 days'"
required: false
type: string
default: "2 days"
renovate-version:
description: "Renovate version for the action"
required: false
type: string
default: "44"
release-workflow:
description: "Workflow file to dispatch after a merge, for example release.yaml. Give several as a comma-separated list. Each must have a workflow_dispatch trigger and the caller needs actions: write. Empty means no dispatch."
required: false
type: string
default: ""
admin-merge:
description: "Merge with --admin, which bypasses branch protection. The workflow token cannot do this, so leave it off unless you pass a token that can."
required: false
type: boolean
default: false
log-level:
description: "Renovate log level: info, debug or trace. Use debug to see why Renovate fails."
required: false
type: string
default: "info"
lfs:
description: "Enable Git LFS checkout (for repos with large files)"
required: false
type: boolean
default: false
npm-registry-scope:
description: "Scope served by a private npm registry, for example '@fortawesome'. Used only when npm-registry-url and the npm-registry-token secret are also set."
required: false
type: string
default: ""
npm-registry-url:
description: "URL of the private npm registry, for example 'https://npm.fontawesome.com/'. Used only when npm-registry-scope and the npm-registry-token secret are also set."
required: false
type: string
default: ""
runner:
description: "Runner label, or JSON object such as {\"group\":\"ci\",\"labels\":[\"linux\"]} to select a runner group. Falls back to vars.SHARED_ACTIONS_RUNNER, then ubuntu-latest."
required: false
type: string
default: ""
secrets:
npm-registry-token:
description: "Auth token for the private npm registry"
required: false
concurrency:
group: renovate-autoupdate-${{ github.repository }}
cancel-in-progress: false
env:
BATCH_BRANCH: deps-autoupdate/batch
ISSUE_TITLE: Dependency updates failing tests
jobs:
renovate:
name: Prepare the updates
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 45
permissions:
contents: write
# Renovate reads the repository's issues when it starts. A private repo refuses that without this.
issues: read
pull-requests: write
outputs:
branches: ${{ steps.list.outputs.branches }}
base-sha: ${{ steps.base.outputs.sha }}
steps:
- name: Record the default branch commit
id: base
env:
GH_TOKEN: ${{ github.token }}
run: |
branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch)
echo "sha=$(gh api "repos/$GITHUB_REPOSITORY/commits/$branch" --jq .sha)" >> "$GITHUB_OUTPUT"
- name: Write Renovate config
env:
MIN_AGE: ${{ inputs.minimum-release-age }}
MAJOR_UPDATES: ${{ inputs.major-updates }}
USE_GO: ${{ inputs.go }}
USE_NODE: ${{ inputs.node }}
GO_DIR: ${{ inputs.go-working-directory }}
NODE_DIR: ${{ inputs.node-working-directory }}
NODE_WORKSPACE: ${{ inputs.node-workspace }}
NODE_PACKAGES: ${{ inputs.node-packages }}
PNPM_VERSION: ${{ inputs.pnpm-version }}
GO_MOD_TIDY: ${{ inputs.go-mod-tidy }}
NPM_SCOPE: ${{ inputs.npm-registry-scope }}
NPM_URL: ${{ inputs.npm-registry-url }}
NPM_TOKEN: ${{ secrets.npm-registry-token }}
CONFIG_FILE: ${{ runner.temp }}/renovate-autoupdate-config.json
run: |
# The token goes to jq through the environment, never argv, and the config print below hides it.
export NPMRC=""
if [ -n "$NPM_SCOPE" ] && [ -n "$NPM_URL" ] && [ -n "$NPM_TOKEN" ]; then
echo "::add-mask::$NPM_TOKEN"
url="${NPM_URL%/}/"
NPMRC=$(printf '%s:registry=%s\n//%s:_authToken=%s\n' "$NPM_SCOPE" "$url" "${url#*://}" "$NPM_TOKEN")
# Renovate writes its npmrc option into the package directory, but a pnpm workspace install reads
# only the root, so the lockfile update gets a 404. The Renovate container shares /tmp with the host.
RENOVATE_NPMRC_FILE="/tmp/renovate-npmrc-$GITHUB_RUN_ID"
(umask 022 && printf '%s\n' "$NPMRC" > "$RENOVATE_NPMRC_FILE")
echo "RENOVATE_NPMRC_FILE=$RENOVATE_NPMRC_FILE" >> "$GITHUB_ENV"
export RENOVATE_NPMRC_FILE
fi
jq -n \
--arg repo "$GITHUB_REPOSITORY" \
--arg age "$MIN_AGE" \
--arg branch_prefix "${BATCH_BRANCH%%/*}/" \
--arg majors "$MAJOR_UPDATES" \
--argjson use_go "$USE_GO" \
--argjson use_node "$USE_NODE" \
--arg go_dir "$GO_DIR" \
--arg node_dir "$NODE_DIR" \
--argjson node_workspace "$NODE_WORKSPACE" \
--arg node_packages "$NODE_PACKAGES" \
--arg pnpm_version "$PNPM_VERSION" \
--argjson go_tidy "$GO_MOD_TIDY" \
'
# A regex for files directly inside a directory, so only what the tests cover is updated.
def prefix($d): (if $d == "." or $d == "" then "" else ($d | ltrimstr("./") | rtrimstr("/")) + "/" end) | gsub("\\."; "\\.");
def pkgprefix($d; $p): prefix($d) + ($p | ltrimstr("./") | rtrimstr("/") | gsub("\\."; "\\.")) + "/";
# A workspace updates only its listed packages. The root lockfile is rewritten by pnpm with them.
def node_files:
if $node_workspace
then [$node_packages | split(",")[] | gsub("^\\s+|\\s+$"; "") | select(length > 0) | "/^" + pkgprefix($node_dir; .) + "package\\.json$/"]
else ["/^" + prefix($node_dir) + "package\\.json$/"]
end;
{
platform: "github",
repositories: [$repo],
onboarding: false,
requireConfig: "optional",
branchPrefix: $branch_prefix,
enabledManagers: ((if $use_go then ["gomod"] else [] end) + (if $use_node then ["npm"] else [] end)),
# Renovate writes the lockfile with its own pnpm. Use the version the tests install with.
constraints: (if $pnpm_version != "" then {pnpm: $pnpm_version} else {} end),
gomod: {managerFilePatterns: ["/^" + prefix($go_dir) + "go\\.mod$/"]},
npm: {managerFilePatterns: (node_files + ["/^" + prefix($node_dir) + "pnpm-workspace\\.yaml$/"])},
dependencyDashboard: false,
# Branches only: with no dashboard, no PR is ever opened. The workflow opens it after the tests.
prCreation: "approval",
# A PR closed after a merge or by hand must not stop a later update of the same package.
recreateWhen: "always",
rebaseWhen: "behind-base-branch",
semanticCommits: "enabled",
semanticCommitType: "chore",
semanticCommitScope: "deps",
minimumReleaseAge: $age,
prConcurrentLimit: 0,
prHourlyLimit: 0,
branchConcurrentLimit: 0,
# A Go major update changes the import path: rewrite the imports, so the build tests the real update.
postUpdateOptions: ((if $go_tidy then ["gomodTidy"] else [] end) + ["gomodUpdateImportPaths"]),
statusCheckNames: {
artifactError: null,
configValidation: null,
mergeConfidence: null,
minimumReleaseAge: null
},
packageRules: (
[
({
matchManagers: ["gomod", "npm"],
groupName: "dependencies",
groupSlug: "batch"
} + (if $majors == "batch" then {} else {matchUpdateTypes: ["minor", "patch", "pin", "pinDigest", "digest"]} end)),
{matchManagers: ["gomod"], matchDepTypes: ["indirect"], enabled: true},
# The parent module chooses the major version of an indirect dependency.
{matchManagers: ["gomod"], matchDepTypes: ["indirect"], allowedVersions: "<{{add major 1}}.0.0"},
{matchPackageNames: ["typescript"], allowedVersions: "<7"}
]
# Rules that disable by update type are ignored, but a version cap works.
+ (if $majors == "ignore" then [{matchManagers: ["gomod", "npm"], allowedVersions: "<{{add major 1}}.0.0"}] else [] end)
)
}
| if $ENV.NPMRC != "" then .npmrc = $ENV.NPMRC | .customEnvVariables = {NPM_CONFIG_USERCONFIG: $ENV.RENOVATE_NPMRC_FILE} else . end' > "$CONFIG_FILE"
jq 'if has("npmrc") then .npmrc = "<redacted>" else . end' "$CONFIG_FILE"
- name: Run Renovate
uses: renovatebot/[email protected]
with:
configurationFile: ${{ runner.temp }}/renovate-autoupdate-config.json
token: ${{ github.token }}
renovate-version: ${{ inputs.renovate-version }}
env:
LOG_LEVEL: ${{ inputs.log-level }}
- name: Remove the registry token file
if: always() && env.RENOVATE_NPMRC_FILE != ''
run: rm -f "$RENOVATE_NPMRC_FILE"
- name: List the update branches
id: list
env:
GH_TOKEN: ${{ github.token }}
run: |
prefix="${BATCH_BRANCH%%/*}/"
all=$(gh api --paginate "repos/$GITHUB_REPOSITORY/branches" --jq '.[].name' | grep -F "$prefix" || true)
# The batch first, then each major update.
ordered=$({ printf '%s\n' "$all" | grep -Fx "$BATCH_BRANCH" || true; printf '%s\n' "$all" | grep -vFx "$BATCH_BRANCH" || true; } | sed '/^$/d')
json=$(printf '%s\n' "$ordered" | jq -R . | jq -sc 'map(select(length > 0))')
echo "branches=$json" >> "$GITHUB_OUTPUT"
echo "Update branches: $json"
test-and-merge:
name: Test and merge ${{ matrix.branch }}
needs: renovate
if: needs.renovate.outputs.branches != '[]'
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 60
permissions:
contents: write
issues: write
pull-requests: write
strategy:
fail-fast: false
# One at a time, so each branch is tested on top of the ones merged before it.
max-parallel: 1
matrix:
branch: ${{ fromJSON(needs.renovate.outputs.branches) }}
env:
BRANCH: ${{ matrix.branch }}
GH_TOKEN: ${{ github.token }}
steps:
- name: Find the default branch
id: default
run: echo "branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch)" >> "$GITHUB_OUTPUT"
# Not the triggering ref: a push or a manual run from another branch must still test the default branch.
- name: Checkout the default branch
uses: actions/checkout@v7
with:
ref: ${{ steps.default.outputs.branch }}
fetch-depth: 0
lfs: ${{ inputs.lfs }}
- name: Merge the update branch locally
id: merge
run: |
git config user.name "Lukasz Raczylo"
git config user.email "[email protected]"
git fetch origin "$BRANCH"
echo "head=$(git rev-parse FETCH_HEAD)" >> "$GITHUB_OUTPUT"
echo "subject=$(git log -1 --format=%s FETCH_HEAD)" >> "$GITHUB_OUTPUT"
if git merge-base --is-ancestor FETCH_HEAD HEAD; then
echo "::notice::$BRANCH is already in the default branch."
echo "skip=true" >> "$GITHUB_OUTPUT"
elif git merge --no-ff --no-commit FETCH_HEAD; then
# A lockfile that both sides changed merges as text and can be broken. Renovate regenerates it on the next run.
base=$(git merge-base HEAD FETCH_HEAD)
stale=""
for lock in pnpm-lock.yaml package-lock.json yarn.lock; do
for f in $(git ls-tree -r --name-only FETCH_HEAD | grep -E "(^|/)${lock//./\\.}$"); do
if ! git diff --quiet "$base" HEAD -- "$f" && ! git diff --quiet "$base" FETCH_HEAD -- "$f"; then stale="$stale $f"; fi
done
done
if [ -n "$stale" ]; then
git merge --abort
echo "::warning::$BRANCH and the default branch both changed${stale}. Renovate rebases it on the next run."
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
else
git merge --abort
echo "::warning::$BRANCH conflicts with the default branch. Renovate rebases it on the next run."
echo "skip=true" >> "$GITHUB_OUTPUT"
fi
- name: Run workflow prepare script
if: steps.merge.outputs.skip != 'true'
shell: bash
run: |
if [ -f "./workflow-prepare.sh" ]; then
chmod +x ./workflow-prepare.sh
./workflow-prepare.sh
fi
- name: Detect project types
id: detect
if: steps.merge.outputs.skip != 'true'
env:
GO_DIR: ${{ inputs.go-working-directory }}
NODE_DIR: ${{ inputs.node-working-directory }}
NODE_WORKSPACE: ${{ inputs.node-workspace }}
NODE_PACKAGES: ${{ inputs.node-packages }}
USE_GO: ${{ inputs.go }}
USE_NODE: ${{ inputs.node }}
run: |
go=false
node=false
pm=npm
if [ "$USE_GO" = true ] && [ -f "$GO_DIR/go.mod" ]; then go=true; fi
if [ "$USE_NODE" = true ] && [ "$NODE_WORKSPACE" = true ]; then
if [ ! -f "$NODE_DIR/pnpm-workspace.yaml" ] || [ ! -f "$NODE_DIR/pnpm-lock.yaml" ]; then
echo "::error::node-workspace needs pnpm-workspace.yaml and pnpm-lock.yaml in $NODE_DIR."
exit 1
fi
IFS=',' read -r -a packages <<<"$NODE_PACKAGES"
count=0
for package in "${packages[@]}"; do
package=$(echo "$package" | xargs)
[ -n "$package" ] || continue
if [ ! -f "$NODE_DIR/$package/package.json" ]; then
echo "::error::node-packages lists $package, but $NODE_DIR/$package/package.json does not exist."
exit 1
fi
count=$((count + 1))
done
if [ "$count" -eq 0 ]; then
echo "::error::node-workspace needs node-packages: the packages to update and test."
exit 1
fi
node=true
pm=pnpm
elif [ "$USE_NODE" = true ] && [ -f "$NODE_DIR/package.json" ]; then
node=true
if [ -f "$NODE_DIR/pnpm-lock.yaml" ]; then pm=pnpm
elif [ -f "$NODE_DIR/yarn.lock" ]; then pm=yarn
fi
fi
if [ "$go" = false ] && [ "$node" = false ]; then
echo "::error::Neither $GO_DIR/go.mod nor $NODE_DIR/package.json exists, so there is nothing to test."
exit 1
fi
{
echo "go=$go"
echo "node=$node"
echo "pm=$pm"
} >> "$GITHUB_OUTPUT"
# The merged go.mod can need a newer Go than the input allows, because a dependency update raises its go directive.
- name: Pick the Go version
id: goversion
if: steps.merge.outputs.skip != 'true' && steps.detect.outputs.go == 'true'
env:
GO_VERSION_INPUT: ${{ inputs.go-version }}
GO_DIR: ${{ inputs.go-working-directory }}
run: |
want=$(awk '$1=="go"{print $2; exit}' "$GO_DIR/go.mod")
floor=$(printf '%s' "$GO_VERSION_INPUT" | sed -E 's/^[^0-9]*//' | cut -d. -f1,2)
need=$(printf '%s' "$want" | cut -d. -f1,2)
version=$GO_VERSION_INPUT
if [ -n "$need" ] && [ "$(printf '%s\n%s\n' "$need" "${floor:-0}" | sort -V | tail -n 1)" != "${floor:-0}" ]; then
version=">=$want"
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "::notice::Go $version (input '$GO_VERSION_INPUT', go.mod '$want')"
- name: Setup Go
if: steps.merge.outputs.skip != 'true' && steps.detect.outputs.go == 'true'
uses: actions/setup-go@v7
with:
go-version: ${{ steps.goversion.outputs.version }}
check-latest: true
cache: true
cache-dependency-path: ${{ inputs.go-working-directory }}/go.sum
- name: Prepare Go
if: steps.merge.outputs.skip != 'true' && steps.detect.outputs.go == 'true' && inputs.go-prepare-command != ''
working-directory: ${{ inputs.go-working-directory }}
env:
GO_PREPARE_COMMAND: ${{ inputs.go-prepare-command }}
run: |
set -o pipefail
bash -c "$GO_PREPARE_COMMAND" 2>&1 | tee -a "$RUNNER_TEMP/test-output.log"
- name: Build and test Go
if: steps.merge.outputs.skip != 'true' && steps.detect.outputs.go == 'true'
working-directory: ${{ inputs.go-working-directory }}
env:
GO_TEST_COMMAND: ${{ inputs.go-test-command }}
TAGS: ${{ inputs.build-tags }}
GOTOOLCHAIN: auto
run: |
set -o pipefail
{
go mod verify
if [ -n "$GO_TEST_COMMAND" ]; then
bash -c "$GO_TEST_COMMAND"
elif [ -n "$TAGS" ]; then
export CGO_ENABLED=1
go build -tags "$TAGS" ./...
go test -tags "$TAGS" -race -cover ./...
else
go build ./...
go test -race -cover ./...
fi
} 2>&1 | tee -a "$RUNNER_TEMP/test-output.log"
- name: Setup Node.js
if: steps.merge.outputs.skip != 'true' && steps.detect.outputs.node == 'true'
uses: actions/setup-node@v7
with:
node-version: ${{ inputs.node-version }}
# The npmrc lives in RUNNER_TEMP, not the checkout, so no git command can pick the token up.
- name: Configure the private npm registry
if: steps.merge.outputs.skip != 'true' && steps.detect.outputs.node == 'true'
env:
NPM_SCOPE: ${{ inputs.npm-registry-scope }}
NPM_URL: ${{ inputs.npm-registry-url }}
NPM_TOKEN: ${{ secrets.npm-registry-token }}
run: |
[ -n "$NPM_SCOPE" ] && [ -n "$NPM_URL" ] && [ -n "$NPM_TOKEN" ] || exit 0
echo "::add-mask::$NPM_TOKEN"
url="${NPM_URL%/}/"
npmrc="$RUNNER_TEMP/private-registry.npmrc"
(umask 077 && printf '%s:registry=%s\n//%s:_authToken=%s\n' "$NPM_SCOPE" "$url" "${url#*://}" "$NPM_TOKEN" > "$npmrc")
echo "NPM_CONFIG_USERCONFIG=$npmrc" >> "$GITHUB_ENV"
echo "Using a private npm registry for $NPM_SCOPE."
- name: Install Node dependencies
if: steps.merge.outputs.skip != 'true' && steps.detect.outputs.node == 'true'
working-directory: ${{ inputs.node-working-directory }}
env:
PM: ${{ steps.detect.outputs.pm }}
PNPM_VERSION: ${{ inputs.pnpm-version }}
run: |
set -o pipefail
{
# The lockfile must match what Renovate wrote: install without updating it.
case "$PM" in
pnpm | yarn)
command -v corepack >/dev/null || npm install --global corepack
corepack enable "$PM"
;;
esac
if [ "$PM" = pnpm ] && [ -n "$PNPM_VERSION" ]; then
corepack prepare "pnpm@$PNPM_VERSION" --activate
fi
case "$PM" in
pnpm) pnpm install --frozen-lockfile ;;
yarn) yarn install --immutable ;;
npm)
if [ -f package-lock.json ]; then npm ci; else npm install; fi
;;
esac
} 2>&1 | tee -a "$RUNNER_TEMP/test-output.log"
- name: Run Node scripts
if: steps.merge.outputs.skip != 'true' && steps.detect.outputs.node == 'true'
working-directory: ${{ inputs.node-working-directory }}
env:
PM: ${{ steps.detect.outputs.pm }}
SCRIPTS: ${{ inputs.node-scripts }}
REQUIRE_TESTS: ${{ inputs.require-node-tests }}
NODE_WORKSPACE: ${{ inputs.node-workspace }}
NODE_PACKAGES: ${{ inputs.node-packages }}
run: |
set -o pipefail
log="$RUNNER_TEMP/test-output.log"
# A single project is the one package ".". A workspace is each listed package.
packages=(.)
if [ "$NODE_WORKSPACE" = true ]; then
IFS=',' read -r -a packages <<<"$NODE_PACKAGES"
fi
if [ "$REQUIRE_TESTS" = true ]; then
for package in "${packages[@]}"; do
package=$(echo "$package" | xargs)
[ -n "$package" ] || continue
if ! jq -e '.scripts.test' "$package/package.json" >/dev/null; then
echo "::error::$package/package.json has no test script. Add one, or set require-node-tests to false."
echo "$package/package.json has no test script, so the update was not tested." >>"$log"
exit 1
fi
done
fi
IFS=',' read -r -a scripts <<<"$SCRIPTS"
for script in "${scripts[@]}"; do
script=$(echo "$script" | xargs)
[ -n "$script" ] || continue
for package in "${packages[@]}"; do
package=$(echo "$package" | xargs)
[ -n "$package" ] || continue
where=""
[ "$package" = . ] || where=" ($package)"
if jq -e --arg s "$script" '.scripts[$s]' "$package/package.json" >/dev/null; then
echo "::group::$PM run $script$where"
(cd "$package" && "$PM" run "$script") 2>&1 | tee -a "$log"
echo "::endgroup::"
else
echo "::notice::No '$script' script$where, skipping."
fi
done
done
- name: Mark the tests as passed
if: steps.merge.outputs.skip != 'true'
run: touch "$RUNNER_TEMP/tests-passed"
- name: Open the PR and merge it
if: steps.merge.outputs.skip != 'true'
env:
HEAD_SHA: ${{ steps.merge.outputs.head }}
SUBJECT: ${{ steps.merge.outputs.subject }}
ADMIN: ${{ inputs.admin-merge && 'true' || '' }}
run: |
default=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch)
pr=$(gh pr list --repo "$GITHUB_REPOSITORY" --head "$BRANCH" --state open --json number --jq '.[0].number // empty')
if [ -z "$pr" ]; then
url=$(gh pr create --repo "$GITHUB_REPOSITORY" --head "$BRANCH" --base "$default" \
--title "$SUBJECT" \
--body "Automated dependency update. The tests passed on the result of merging this branch into $default.")
pr=${url##*/}
fi
# GitHub needs a moment to work out whether the PR can merge.
for _ in $(seq 1 12); do
state=$(gh pr view "$pr" --repo "$GITHUB_REPOSITORY" --json mergeable --jq .mergeable)
[ "$state" != UNKNOWN ] && break
sleep 5
done
if [ "$state" = CONFLICTING ]; then
gh pr close "$pr" --repo "$GITHUB_REPOSITORY" \
--comment "The tests passed, but the branch conflicts with $default. Renovate rebases it on the next run."
echo "::warning::$BRANCH conflicts with $default, so PR #$pr was closed. Renovate rebases it on the next run."
echo "\`$BRANCH\` passed its tests but conflicts with \`$default\`. Renovate rebases it on the next run." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
# --match-head-commit refuses to merge anything newer than the commit that was tested.
# GitHub answers 5xx now and then; a failed call may still have merged, so check the state before retrying.
merged=false
for _ in 1 2 3; do
if gh pr merge "$pr" --repo "$GITHUB_REPOSITORY" --squash --delete-branch \
--match-head-commit "$HEAD_SHA" \
--subject "$SUBJECT" \
--body "Automated dependency update. All tests passed." \
${ADMIN:+--admin}; then
merged=true
break
fi
sleep 10
[ "$(gh pr view "$pr" --repo "$GITHUB_REPOSITORY" --json state --jq .state)" = MERGED ] && { merged=true; break; }
done
if [ "$merged" != true ]; then
gh pr close "$pr" --repo "$GITHUB_REPOSITORY" --comment "The tests passed, but GitHub refused the merge. See the workflow run. The next run tries again."
exit 1
fi
echo "Merged #$pr ($BRANCH)." >> "$GITHUB_STEP_SUMMARY"
- name: Report the failure
if: failure()
# Best effort: the summary is always written, the issue needs issues: write.
continue-on-error: true
env:
HEAD_SHA: ${{ steps.merge.outputs.head }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ -e "$RUNNER_TEMP/tests-passed" ]; then
echo "The tests passed for \`$BRANCH\`, but the merge failed. See the log above. The next run tries again." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
echo "The tests failed for \`$BRANCH\`, so no PR was opened. Renovate retries on the next run." >> "$GITHUB_STEP_SUMMARY"
log="$RUNNER_TEMP/test-output.log"
esc=$(printf '\033')
marker="<!-- renovate-autoupdate:$BRANCH -->"
body="$RUNNER_TEMP/failure-comment.md"
{
echo "$marker"
echo "### \`$BRANCH\` failed its tests"
echo
echo "Commit \`${HEAD_SHA:0:8}\`, [workflow run]($RUN_URL), $(date -u '+%Y-%m-%d %H:%M') UTC. No PR was opened."
echo
echo "<details open><summary>Test output, last lines</summary>"
echo
echo '`````'
if [ -s "$log" ]; then
sed -E "s/${esc}\[[0-9;]*[A-Za-z]//g" "$log" | tail -c 50000
else
echo "No output was captured. See the workflow run."
fi
echo '`````'
echo
echo "</details>"
} > "$body"
issue=$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --search "\"$ISSUE_TITLE\" in:title" --json number,title \
--jq "[.[] | select(.title == \"$ISSUE_TITLE\")][0].number // empty")
if [ -z "$issue" ]; then
url=$(gh issue create --repo "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" \
--body "Updates that failed their tests, so no PR was opened. Each comment holds the output for one branch. Fix the cause on the branch or in the code. The workflow retries on every run, merges an update once it passes, and closes this issue when none fail.")
issue=${url##*/}
fi
id=$(gh api "repos/$GITHUB_REPOSITORY/issues/$issue/comments" --paginate \
--jq ".[] | select(.body | contains(\"$marker\")) | .id" | head -n 1)
if [ -n "$id" ]; then
gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$id" -F body=@"$body" >/dev/null
else
gh issue comment "$issue" --repo "$GITHUB_REPOSITORY" --body-file "$body"
fi
tidy-failures:
name: Tidy the failure issue
needs: [renovate, test-and-merge]
if: always() && needs.renovate.result == 'success'
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 10
permissions:
issues: write
contents: read
steps:
- name: Remove fixed updates and close the issue when none fail
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
issue=$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --search "\"$ISSUE_TITLE\" in:title" --json number,title \
--jq "[.[] | select(.title == \"$ISSUE_TITLE\")][0].number // empty")
[ -n "$issue" ] || exit 0
branches=$(gh api --paginate "repos/$GITHUB_REPOSITORY/branches" --jq '.[].name')
remaining=0
while IFS=$'\t' read -r id branch; do
[ -n "$id" ] || continue
if printf '%s\n' "$branches" | grep -Fxq "$branch"; then
remaining=$((remaining + 1))
else
gh api -X DELETE "repos/$GITHUB_REPOSITORY/issues/comments/$id"
fi
done < <(gh api "repos/$GITHUB_REPOSITORY/issues/$issue/comments" --paginate \
--jq '.[] | select(.body | startswith("<!-- renovate-autoupdate:")) | [.id, (.body | split("\n")[0] | sub("^<!-- renovate-autoupdate:"; "") | sub(" -->$"; ""))] | @tsv')
if [ "$remaining" -eq 0 ]; then
gh issue close "$issue" --repo "$GITHUB_REPOSITORY" --comment "Every dependency update now passes its tests."
fi
release:
name: Dispatch the release
needs: [renovate, test-and-merge]
if: always() && needs.renovate.outputs.branches != '[]' && inputs.release-workflow != ''
runs-on: ${{ fromJSON(startsWith(inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest', '{') && (inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest') || format('"{0}"', inputs.runner || vars.SHARED_ACTIONS_RUNNER || 'ubuntu-latest')) }}
timeout-minutes: 10
permissions:
actions: write
contents: read
steps:
- name: Dispatch when the default branch moved
env:
GH_TOKEN: ${{ github.token }}
RELEASE_WORKFLOW: ${{ inputs.release-workflow }}
BASE_SHA: ${{ needs.renovate.outputs.base-sha }}
run: |
# A push made with github.token does not trigger workflows, so dispatch the release explicitly.
branch=$(gh api "repos/$GITHUB_REPOSITORY" --jq .default_branch)
now=$(gh api "repos/$GITHUB_REPOSITORY/commits/$branch" --jq .sha)
if [ "$now" = "$BASE_SHA" ]; then
echo "Nothing was merged, so no release."
exit 0
fi
IFS=',' read -r -a workflows <<<"$RELEASE_WORKFLOW"
for workflow in "${workflows[@]}"; do
workflow=$(echo "$workflow" | xargs)
[ -n "$workflow" ] || continue
gh workflow run "$workflow" --repo "$GITHUB_REPOSITORY" --ref "$branch"
done
+89
View File
@@ -0,0 +1,89 @@
name: Validate
# Checks that a change to the workflows or composite actions still works. Renovate
# opens a PR for each action bump; this workflow is the gate those PRs must pass.
# The aggregate job "validate" is the one required status check.
# No paths filter: "validate" is a required status check, and a required check
# that never runs blocks a PR that touches only other files.
on:
pull_request:
workflow_dispatch:
permissions:
contents: read
pull-requests: read
concurrency:
group: validate-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
jobs:
static:
name: Static checks
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v7
# actionlint, then every external `uses:` reference must resolve.
- name: Check workflows and action references
run: scripts/check-actions.sh --ci
selftest-go:
name: Self-test go-test action
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v7
# The local path runs the action as it is on this branch, not at @main.
- name: Run the go-test action on the fixture module
uses: ./.github/actions/go-test
with:
working-directory: testdata/selftest/go
selftest-node-build:
name: Self-test node-build action
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Run the node-build action on the fixture project
uses: ./.github/actions/node-build
with:
build-script: cd testdata/selftest/node && npm ci && npm run build
cache-dependency-path: testdata/selftest/node/package-lock.json
selftest-node-pr:
name: Self-test node-pr workflow
uses: ./.github/workflows/node-pr.yaml
permissions:
contents: read
pull-requests: read
with:
working-directory: testdata/selftest/node
require-tests: true
validate:
name: validate
if: always()
needs: [static, selftest-go, selftest-node-build, selftest-node-pr]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Require every check to pass
env:
RESULTS: ${{ join(needs.*.result, ' ') }}
run: |
echo "results: $RESULTS"
for r in $RESULTS; do
if [ "$r" != success ]; then
echo "::error::a validation job finished as '$r'"
exit 1
fi
done
+181 -1
View File
@@ -4,6 +4,21 @@ Reusable workflows and composite actions for Go projects.
## Reusable Workflows ## Reusable Workflows
### Runner selection
Every reusable workflow accepts `runner` (label, or a JSON object to pick a runner group):
```yaml
with:
runner: self-hosted
# or
runner: '{"group":"ci-linux","labels":["x64"]}'
```
Resolution order: `inputs.runner`, repository/org variable `SHARED_ACTIONS_RUNNER`, `ubuntu-latest`.
Set the variable once to move every consumer. In `go-release-cgo.yaml` the build matrix keeps its
per-platform `os`; `runner` covers the other jobs. Runner groups exist only for organisations and enterprises.
### `go-release.yaml` ### `go-release.yaml`
Standard Go release workflow using GoReleaser. Standard Go release workflow using GoReleaser.
@@ -57,6 +72,11 @@ jobs:
Pull request checks: tests, linting, security scans. Pull request checks: tests, linting, security scans.
- `go vet` / `staticcheck` findings show as inline annotations on the PR diff; gosec and CodeQL post to code scanning.
- The `report` job posts one sticky comment with every check's result and coverage, and fails if any check fails or coverage is below `coverage-threshold`. Require `PR Checks Report` in branch protection.
- A push to a branch with an open PR skips the duplicate run; stale runs on the same branch are cancelled.
- Fork PRs cannot receive the comment; the report still lands in the job summary.
```yaml ```yaml
jobs: jobs:
pr-checks: pr-checks:
@@ -66,9 +86,55 @@ jobs:
secrets: inherit secrets: inherit
``` ```
### `node-pr.yaml`
Pull request checks for a Node, Vue or Astro project. It installs without changing the lockfile, then runs `lint`, `typecheck`, `test` and `build`. A script that does not exist is skipped. A push to a branch with an open PR skips the duplicate run, and stale runs on the same branch are cancelled. Call it once per project directory.
```yaml
name: Pull Request
on:
pull_request:
branches:
- main
push:
branches:
- "**"
- "!main"
permissions:
contents: read
pull-requests: read
jobs:
frontend:
uses: lukaszraczylo/shared-actions/.github/workflows/node-pr.yaml@main
with:
working-directory: web
```
**Inputs:**
| Input | Default | Description |
|-------|---------|-------------|
| `node-version` | `22` | Node.js version |
| `working-directory` | `.` | Directory that holds `package.json`. With `workspace`, the directory that holds `pnpm-workspace.yaml` and `pnpm-lock.yaml`. |
| `workspace` | `false` | pnpm workspace: install once in `working-directory`, then run `scripts` in each of `packages`. `working-directory` needs no `package.json`. |
| `packages` | | With `workspace`, comma-separated package directories relative to `working-directory`, for example `admin,public,packages/ui` |
| `scripts` | `lint,typecheck,test,build` | Scripts to run in order. A missing script is skipped. |
| `pnpm-version` | | pnpm version for a repo with no `packageManager` field. Empty uses the field, or the newest pnpm. |
| `require-tests` | `false` | Fail when there is no `test` script |
| `lfs` | `false` | Git LFS checkout |
| `npm-registry-scope` | | Scope served by a private npm registry, for example `@fortawesome`. |
| `npm-registry-url` | | URL of that registry, for example `https://npm.fontawesome.com/`. |
| `runner` | | Runner label or runner group, as in the other workflows |
pnpm is used when `pnpm-lock.yaml` exists, yarn for `yarn.lock`, otherwise npm. pnpm and yarn run through Corepack, so set `packageManager` in `package.json`. A workspace with no root `package.json` has no such field, so set `pnpm-version`. With `require-tests`, every listed package needs a `test` script.
**Private npm registry.** Set `npm-registry-scope`, `npm-registry-url` and the `npm-registry-token` secret together; with any one missing nothing changes. The token goes into an npmrc outside the checkout (`NPM_CONFIG_USERCONFIG`), is masked in logs, and works for npm, pnpm and yarn classic. Yarn 2+ ignores npmrc and needs its own `.yarnrc.yml`.
### `go-autoupdate.yaml` ### `go-autoupdate.yaml`
Automatic dependency updates. Automatic dependency updates for Go. See `renovate-autoupdate.yaml` for the Renovate-based replacement that also covers npm, pnpm and yarn.
```yaml ```yaml
jobs: jobs:
@@ -80,6 +146,95 @@ jobs:
secrets: inherit secrets: inherit
``` ```
### `renovate-autoupdate.yaml`
Daily dependency updates for Go and npm/pnpm/yarn projects, built on Renovate. It replaces `go-autoupdate.yaml`.
1. Renovate upgrades everything that can be upgraded on branches named `deps-autoupdate/*` and opens no PR. All minor and patch updates (direct and indirect Go modules, npm, pnpm and yarn packages) go on `deps-autoupdate/batch`. Each major update gets its own branch.
2. For each branch, one at a time, the workflow merges it into the default branch locally and runs the tests on that result: `go build` and `go test -race -cover` for Go, the `package.json` scripts for Node.
3. If the tests pass, it opens a PR and squash-merges it. If they fail, no PR is opened. The test output goes into a comment on one sticky issue (see below), and Renovate retries on the next run.
4. If anything merged and `release-workflow` is set, it dispatches the release once.
```yaml
name: Update dependencies
on:
workflow_dispatch:
schedule:
- cron: "0 3 * * *"
permissions:
actions: write # only to dispatch release-workflow
contents: write
issues: write # only to report failing updates
pull-requests: write
jobs:
update:
uses: lukaszraczylo/shared-actions/.github/workflows/renovate-autoupdate.yaml@main
with:
go-version: ">=1.24"
release-workflow: release.yaml
```
The workflow finds `go.mod` and `package.json` itself and tests what exists. A repo with both, such as a Go backend with a Vue frontend, gets both tested for every branch.
**Inputs:**
| Input | Default | Description |
|-------|---------|-------------|
| `go-version` | `>=1.24` | Go version |
| `go` | `true` | Update and test the Go module. Turn off for a repo with no Go code. |
| `go-working-directory` | `.` | Directory that holds `go.mod`. Only this module is updated and tested. |
| `go-mod-tidy` | `true` | Run `go mod tidy` after a Go update. Turn it off for an Encore app, where tidy prunes `go.sum` entries the build needs. |
| `go-prepare-command` | | Shell commands to run before the Go tests, for example installing a CLI. Append a tool directory to `$GITHUB_PATH` to put it on `PATH`. |
| `go-test-command` | | Replaces the default `go build` and `go test`, for example `encore test ./...` for an Encore app. |
| `build-tags` | | Build tags for the default `go build` and `go test`, for example `fts5`. Also sets `CGO_ENABLED=1`. Ignored when `go-test-command` is set. |
| `node-version` | `22` | Node.js version |
| `node` | `true` | Update and test the Node project. Turn off for a repo with no frontend to test. |
| `node-working-directory` | `.` | Directory that holds `package.json`. Only this project is updated and tested. With `node-workspace`, the directory that holds the workspace files. |
| `node-workspace` | `false` | pnpm workspace: `node-working-directory` holds `pnpm-workspace.yaml` and `pnpm-lock.yaml` and needs no `package.json`. Install once there, then run `node-scripts` in each of `node-packages`. |
| `node-packages` | | With `node-workspace`, comma-separated package directories relative to `node-working-directory`, for example `admin,public,packages/ui`. Only these are updated and tested. |
| `node-scripts` | `lint,typecheck,test,build` | Scripts to run in order. A missing script is skipped. |
| `pnpm-version` | | pnpm version for a repo with no `packageManager` field. Empty uses the field, or the newest pnpm. |
| `require-node-tests` | `true` | Fail when there is no `test` script, so an untested update never merges |
| `major-updates` | `separate` | `separate`: each major gets its own branch, tested and merged on its own. `batch`: majors join the batch. `ignore`: skip majors. |
| `minimum-release-age` | `2 days` | Skip releases younger than this |
| `renovate-version` | `44` | Renovate version |
| `release-workflow` | | Workflow file to dispatch after a merge, for example `release.yaml`. Give several as a comma-separated list. Each needs a `workflow_dispatch` trigger. Empty means no dispatch. |
| `admin-merge` | `false` | Merge with `--admin`. The workflow token cannot bypass branch protection. |
| `lfs` | `false` | Git LFS checkout |
| `npm-registry-scope` | | Scope served by a private npm registry, for example `@fortawesome`. |
| `npm-registry-url` | | URL of that registry, for example `https://npm.fontawesome.com/`. |
| `runner` | | Runner label or runner group, as in the other workflows |
**Private npm registry.** Set `npm-registry-scope`, `npm-registry-url` and the `npm-registry-token` secret together; with any one missing nothing changes. Renovate and the install step both use it. The token goes into an npmrc outside the checkout (`NPM_CONFIG_USERCONFIG`), is masked in logs, and works for npm, pnpm and yarn classic. Yarn 2+ ignores npmrc and needs its own `.yarnrc.yml`.
**Failing updates.** The last 50 KB of the test output goes into a comment on one issue titled "Dependency updates failing tests". Each failing branch has its own comment, updated on every run, and a header with the commit and the run link. When a branch passes and merges, its comment is removed. When no failing branch is left, the issue closes. The output is also in the run summary. Without `issues: write` the run still works, but the issue is skipped.
**Only what is tested is updated.** Renovate manages one Go module and one Node project: the ones in `go-working-directory` and `node-working-directory`. A second `package.json` (docs, e2e tests, another frontend) or a second `go.mod` is left alone, because nothing would test its updates. In a workspace the same rule applies to packages: only those in `node-packages` are updated, plus `pnpm-workspace.yaml` and the root `pnpm-lock.yaml`.
**Branches run one at a time**, so each one is tested on top of the ones merged before it. A branch that conflicts with the default branch is skipped, and Renovate rebases it on the next run.
**Package manager.** pnpm is used when `pnpm-lock.yaml` exists, yarn for `yarn.lock`, otherwise npm. The install step never changes the lockfile (`--frozen-lockfile`, `--immutable`, `npm ci`), so a lockfile that does not match `package.json` fails the run. pnpm and yarn run through Corepack, so set `packageManager` in `package.json`. A workspace with no root `package.json` has no such field, so set `pnpm-version`. With `require-node-tests`, every listed package needs a `test` script.
**Per-project rules.** Put a `renovate.json` in the calling repository. Renovate reads it and merges it with the defaults, so no extra input is needed:
```json
{
"ignoreDeps": ["some/package"],
"packageRules": [{ "matchPackageNames": ["vite"], "enabled": false }]
}
```
The defaults already cap `typescript` below 7, which breaks `vue-tsc`.
**Token.** No secret is needed. Everything runs inside the calling repository with the workflow's own token, which needs `contents: write` and `pull-requests: write`. Two repository settings matter:
- Settings, Actions, General: tick "Allow GitHub Actions to create and approve pull requests". Without it the workflow cannot open the PR.
- A push made with the workflow token does not trigger other workflows, so a release workflow that runs on `push` will not start after a merge. Set `release-workflow` to dispatch it, and grant `actions: write`.
**Commit message.** The squash commit subject is the Renovate commit message, for example `chore(deps): update dependencies`, and the body is fixed text. Neither contains `major` or `breaking`, which `semver-generator` matches in commit messages.
## Composite Actions ## Composite Actions
### `actions/go-test` ### `actions/go-test`
@@ -134,6 +289,31 @@ Run GoReleaser with mode support.
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
``` ```
### `actions/preflight`
Fail in seconds when a prerequisite is missing, instead of at the end of a long run. Reads names from the step `env`, so map secrets there.
```yaml
- uses: lukaszraczylo/shared-actions/.github/actions/preflight@main
with:
require: GITHUB_TOKEN,NPM_TOKEN # must be non-empty
repo-access: lukaszraczylo/helm-charts # token needs push access
repo-token-env: HOMEBREW_TAP_TOKEN
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
```
Optional probes use the real token, so they catch caller `permissions:` that are too narrow:
- `release-write: "true"` runs `git push --dry-run`, which fails when the token cannot push (no tag or release possible).
- `ghcr-push: true|auto` asks ghcr.io for a push token and opens a blob upload session (no package is created). `auto` probes only when the config has `dockers`/`dockers_v2`/`docker_manifests` and mentions `ghcr.io`. The image is the first `ghcr.io/...` path in the config, else the repository (`ghcr-image` overrides).
- A probe that cannot reach a verdict (network error, odd status) warns and does not fail.
It also scans `.goreleaser.y*ml` and requires every `{{ .Env.NAME }}` (comment lines ignored) to be set. All problems are listed in one run.
`go-release.yaml` and `go-release-cgo.yaml` run it in a first `preflight` job before tests. Set `preflight: false` to skip it, and `preflight-repos` to check access to a tap or helm-charts repo. An empty secret usually means the caller omitted `secrets: inherit`.
### `actions/rolling-release` ### `actions/rolling-release`
Create/update a rolling release tag. Create/update a rolling release tag.
+75
View File
@@ -0,0 +1,75 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"timezone": "Europe/London",
"enabledManagers": [
"github-actions"
],
"semanticCommits": "enabled",
"semanticCommitType": "chore",
"semanticCommitScope": "deps",
"dependencyDashboard": false,
"prConcurrentLimit": 0,
"prHourlyLimit": 0,
"minimumReleaseAge": "3 days",
"postUpgradeTasks": {
"commands": [
"scripts/check-actions.sh --renovate"
],
"fileFilters": [
".validation-failed"
],
"executionMode": "branch"
},
"packageRules": [
{
"description": "This repository's own composite actions are tracked at @main by design.",
"matchPackageNames": [
"lukaszraczylo/shared-actions"
],
"enabled": false
},
{
"description": "Tool versions in action inputs and defaults (Go, Node, GoReleaser) are policy, not pins. A bump would change what every consumer builds with.",
"matchDatasources": [
"golang-version",
"node-version"
],
"enabled": false
},
{
"description": "The GoReleaser version input is policy, not a pin.",
"matchDepNames": [
"goreleaser/goreleaser"
],
"enabled": false
},
{
"description": "Minor and patch bumps merge on their own once the validate check is green.",
"matchUpdateTypes": [
"minor",
"patch",
"digest",
"pin"
],
"automerge": true,
"automergeType": "pr",
"platformAutomerge": true
},
{
"description": "Every consumer calls these actions at @main, so a major bump waits for a human.",
"matchUpdateTypes": [
"major"
],
"automerge": false,
"addLabels": [
"major"
]
}
],
"statusCheckNames": {
"artifactError": null,
"configValidation": null,
"mergeConfidence": null,
"minimumReleaseAge": null
}
}
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env bash
# Static checks for the workflows and composite actions in this repository:
# 1. actionlint (schema, expressions, and shell steps through shellcheck when present)
# 2. every external `uses:` reference resolves to a real tag or branch
#
# Usage: scripts/check-actions.sh [--ci | --renovate]
# --ci exit 1 when a check fails (default)
# --renovate exit 0 and write .validation-failed when a check fails, so the
# Renovate runner deletes the branch before a PR can open
#
# Needs: bash, git, curl, tar, sha256sum or shasum. No other tools: actionlint is
# downloaded at a pinned version and checked against a pinned SHA-256.
set -u
mode=--ci
case "${1:-}" in
"" | --ci) mode=--ci ;;
--renovate) mode=--renovate ;;
*) echo "usage: $0 [--ci | --renovate]" >&2; exit 2 ;;
esac
ACTIONLINT_VERSION=1.7.12
ACTIONLINT_SHA256_AMD64=8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8
ACTIONLINT_SHA256_ARM64=325e971b6ba9bfa504672e29be93c24981eeb1c07576d730e9f7c8805afff0c6
marker=.validation-failed
cd "$(git rev-parse --show-toplevel)" || exit 2
fail=0
problem() {
echo "::error::$*" >&2
fail=1
}
sha256_of() {
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1; else shasum -a 256 "$1" | cut -d' ' -f1; fi
}
install_actionlint() {
local os arch want url tmp
case "$(uname -s)" in Linux) os=linux ;; Darwin) os=darwin ;; *) return 1 ;; esac
case "$(uname -m)" in
x86_64 | amd64) arch=amd64; want=$ACTIONLINT_SHA256_AMD64 ;;
aarch64 | arm64) arch=arm64; want=$ACTIONLINT_SHA256_ARM64 ;;
*) return 1 ;;
esac
# The pinned checksums are for the linux builds only.
[ "$os" = linux ] || return 1
tmp=$(mktemp -d)
url="https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_${os}_${arch}.tar.gz"
curl -fsSL --retry 3 -o "$tmp/a.tgz" "$url" || return 1
[ "$(sha256_of "$tmp/a.tgz")" = "$want" ] || { echo "actionlint checksum mismatch" >&2; return 1; }
tar -xzf "$tmp/a.tgz" -C "$tmp" actionlint || return 1
echo "$tmp/actionlint"
}
run_actionlint() {
local bin
if command -v actionlint >/dev/null 2>&1; then
bin=$(command -v actionlint)
else
bin=$(install_actionlint) || { problem "cannot install actionlint ${ACTIONLINT_VERSION}"; return; }
fi
# -shellcheck= disables the shellcheck pass when the binary is missing.
local opts=()
command -v shellcheck >/dev/null 2>&1 || opts+=(-shellcheck=)
# Info and style findings from shellcheck (for example SC2086 on intentional word
# splitting) do not fail the gate. Warnings and errors do. Composite actions are
# not linted by actionlint 1.7; workflows are.
opts+=(-ignore 'shellcheck reported issue.+SC[0-9]+:(info|style):')
if ! "$bin" "${opts[@]}" -color .github/workflows/*.y*ml; then
problem "actionlint reported problems"
fi
}
# Resolves every `uses: owner/repo[/path]@ref` that points outside this repository.
check_refs() {
local files uses ref repo path checked=""
files=$(find .github -type f \( -name '*.yml' -o -name '*.yaml' \))
uses=$(grep -hoE '^[[:space:]]*(-[[:space:]]+)?uses:[[:space:]]*[^[:space:]#]+' $files | sed -E 's/^[[:space:]]*(-[[:space:]]+)?uses:[[:space:]]*//' | sort -u)
while IFS= read -r u; do
[ -n "$u" ] || continue
case "$u" in ./* | docker://*) continue ;; esac
repo=${u%%@*}
ref=${u#*@}
[ "$repo" != "$u" ] || { problem "no @ref in 'uses: $u'"; continue; }
# owner/repo/sub/path -> owner/repo
path=$(echo "$repo" | cut -d/ -f1,2)
# This repository's own composite actions are tracked at @main by design.
[ "$path" = lukaszraczylo/shared-actions ] && continue
case " $checked " in *" $path@$ref "*) continue ;; esac
checked="$checked $path@$ref"
if ! git ls-remote --exit-code "https://github.com/$path" "refs/tags/$ref" "refs/heads/$ref" >/dev/null 2>&1; then
# A full commit SHA is not listed by ls-remote; accept it when the repository answers at all.
if echo "$ref" | grep -qE '^[0-9a-f]{40}$' && git ls-remote --exit-code "https://github.com/$path" HEAD >/dev/null 2>&1; then
continue
fi
problem "'uses: $u' does not resolve: no tag or branch $ref in $path"
fi
done <<<"$uses"
}
rm -f "$marker"
run_actionlint
check_refs
if [ "$fail" -ne 0 ]; then
if [ "$mode" = --renovate ]; then
echo "validation failed; writing $marker" >&2
printf 'actions validation failed\n' >"$marker"
exit 0
fi
exit 1
fi
echo "actions validation passed"
+5
View File
@@ -0,0 +1,5 @@
// Package selftest is a fixture that the validate workflow runs the go-test action against.
package selftest
// Add returns the sum of a and b.
func Add(a, b int) int { return a + b }
+9
View File
@@ -0,0 +1,9 @@
package selftest
import "testing"
func TestAdd(t *testing.T) {
if got := Add(2, 3); got != 5 {
t.Fatalf("Add(2, 3) = %d, want 5", got)
}
}
+3
View File
@@ -0,0 +1,3 @@
module example.com/selftest
go 1.24
+12
View File
@@ -0,0 +1,12 @@
{
"name": "selftest",
"version": "0.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "selftest",
"version": "0.0.0"
}
}
}
+10
View File
@@ -0,0 +1,10 @@
{
"name": "selftest",
"version": "0.0.0",
"private": true,
"scripts": {
"lint": "node -e \"process.exit(0)\"",
"test": "node --test",
"build": "node -e \"console.log('built')\""
}
}
+6
View File
@@ -0,0 +1,6 @@
const test = require('node:test');
const assert = require('node:assert');
test('addition', () => {
assert.strictEqual(2 + 3, 5);
});