Reusable GitHub Workflows
Opinionated, security-hardened reusable GitHub Actions workflows for shipping
Go, Python, and Docker projects, plus ClawHub skill/plugin publishing and a
gate that closes PRs from non-collaborators. Add one uses: line to a caller
repo and inherit a full lint → test → scan → build → publish → release
pipeline that lives in one versioned place instead of being copy-pasted across
every repo.
See CHANGELOG.md for the per-release notes.
Contents
Shared conventions
Every workflow here holds to the same rules, so a caller inherits them for free:
- Third-party actions pinned by full commit SHA. Never use a floating tag. A re-pointed or compromised upstream tag cannot silently change what runs.
- Least-privilege permissions. The top level is
permissions: {}. Each job opts into only the scopes it needs (contents: read, security-events: write, …).
- Concurrency matches the resource. A newer push on the same ref supersedes ordinary in-flight work. Scheduled and manual runs use their own group, so they never cancel the push run a tag release waits for. Tag pushes always complete. Badge publishing serializes writers for each caller repository and output branch. Mirroring serializes per caller repository without cancellation because every run carries a real ref that must reach the targets.
- Release locks belong to the publisher. GitHub release creation and ClawHub publishing each lock the target tag within the calling repository. Their separate groups work for both tag pushes and explicit
tag inputs. Each group lets its active publication finish.
- Triggered from
push. You wire on: [push]. The workflow decides whether the ref applies and no-ops otherwise.
- Supply-chain discipline on tooling installs. Exact version pins, an age gate that rejects fresh releases, and
npm install --ignore-scripts.
- Network operations retry with exponential backoff. Clones, pushes, package installs, and release downloads retry transient failures. Scanners (
govulncheck, pip-audit) do not retry because a finding is a real failure. code-workflow.yml is the exception: it cannot tell a caller's failing command from a network failure inside it, so it retries every command, scans included, and a real finding still fails the step after the last attempt.
- Fail honestly without blocking unrelated work. An independent job goes red when it did not complete. Do not hide its failure to keep a run green.
Workflows
| Workflow |
What it does |
collaborators-only-workflow.yml |
Close (and optionally lock) PRs from non-collaborators. |
wait-for-default-branch.yml |
Block a tag's pipeline until the default branch's push run of the same commit finishes, so a release can reuse what it already built instead of rebuilding. |
docker-image-workflow.yml |
Buildx multi-arch / multi-target Docker Hub publish + SBOM/provenance + Grype scan → Security tab + GitHub Release. |
go-workflow.yml |
Go lint / test / govulncheck + GitHub Release on tag. |
python-package-workflow.yml |
Python lint matrix / test / build / pip-audit + PyPI publish (token or OIDC) + GitHub Release on tag. |
code-workflow.yml |
Chain a repo's own build / lint / test / sec / generate commands (no toolchain setup), upload coverage + a security SARIF, check codegen drift. For projects whose toolchain lives in their container. |
pages-workflow.yml |
Build a static documentation site with optional OpenAPI reference generation and publish it to GitHub Pages. |
make-checks.yml |
Deprecated compatibility runner for container-backed make lint and make test checks. Use code-workflow.yml for new callers. |
release-workflow.yml |
Cut a GitHub release for a tag (tag + notes, no artifacts) via the gh CLI. |
clawhub-publish.yml |
Validate + publish skills and plugins to ClawHub via the official CLI. |
regen-and-update-repo.yml |
Run generation and checks on every invocation, repair failures, then review and release any resulting changes. |
mcp-registry-publish.yml |
Publish a server.json to the official MCP Registry on tag, secretless via GitHub OIDC. |
apify-publish.yml |
Push an Apify Actor on tag, pin its FROM image to the promoted digest, and fail unless the Actor build succeeds. |
create-badges.yml |
Self-render coverage / license / version / imported-by SVG badges (no third-party service) and commit them to an orphan badges branch. |
git-mirror.yml |
Push-mirror every branch + tag to Codeberg / GitLab / Gitee, creating the repo and syncing description + topics. |
issue-pull.yml |
Copy mirror issues and replies into GitHub with linked source identities, track source edits and state changes, and preserve confidential GitLab issues as generic source links. |
archive.yml |
Push the repo into the Wayback Machine (pages), Software Heritage (git history) and archive.org (a browsable item of the source itself). |
Pinning
Reference the workflows at @master. Releases come often, and a pinned tag or SHA falls behind with every one of them. @master picks up each fix as soon as it lands:
uses: psyb0t/reusable-github-workflows/.github/workflows/go-workflow.yml@master
pages-workflow.yml
Builds the caller's static docs and publishes them with the official GitHub Pages actions. Pull requests build and validate the site. A push or manual run on the default branch can publish it. Set Settings → Pages → Source to GitHub Actions in the caller repository.
Inputs
| Input |
Type |
Default |
Description |
site_dir |
string |
Required |
Repository-relative output directory containing index.html. Use a dedicated build directory containing only public assets. Symlinks and hard links are rejected. |
build_command |
string |
make docs-build |
Builds the static site from the repository root. Use - or an empty string to publish prebuilt output. |
openapi_file |
string |
Empty |
Optional path to an existing OpenAPI .json, .yaml or .yml file in the checkout. Omit it for a site without a generated API reference. |
openapi_command |
string |
make docs-openapi |
Runs before the site build when openapi_file is set. Reads its path from the OPENAPI_FILE environment variable. Use - or an empty string when the site build handles generation itself. |
max_attempts |
number |
3 |
Maximum attempts per command, including the first. Use 1 to turn retries off. |
backoff_seconds |
number |
10 |
Seconds before the first retry. The delay doubles on each retry. |
The caller owns the generator and its pinned toolchain. For Docusaurus, have docs-openapi validate the supplied spec and generate the reference. Keep authored guides in docs/ and have docs-build assemble them with the generated pages. For an existing build that already generates the reference, set openapi_command: '-' and have docs-build read OPENAPI_FILE directly.
The workflow returns page_url after deployment. The build job gets contents: read. The deploy job alone gets pages: write and id-token: write and uses the github-pages environment. Grant all three scopes on the calling job. Keep build commands in the caller workflow and use pull_request for PR checks.
Example
name: Documentation
on: [push, pull_request, workflow_dispatch]
permissions: {}
jobs:
docs:
permissions:
contents: read
pages: write
id-token: write
uses: psyb0t/reusable-github-workflows/.github/workflows/pages-workflow.yml@master
with:
site_dir: website/build
openapi_file: docs/openapi.yaml
collaborators-only-workflow.yml
Closes (and optionally locks) any PR whose author is not a collaborator on the repository. Useful when you don't want to triage drive-by PRs from forks.
Caller MUST trigger with pull_request_target (not pull_request). The pull_request_target event runs with the base branch's token, which has permission to comment/close PRs from forks; pull_request from a fork has a read-only token and the workflow cannot close the PR.
Inputs
| Input |
Type |
Default |
Description |
close_message |
string |
"This repository does not accept external pull requests. Please open an issue instead." |
Comment posted when an unauthorized PR is closed. |
lock |
boolean |
true |
Lock the PR conversation after closing. |
allow_authors |
string |
dependabot[bot],dependabot-preview[bot] |
Comma-separated PR author logins that bypass the collaborator check. Use it for trusted bots whose PRs are meant to be reviewed and merged. Closing their PRs creates a dead notification path because nobody sees a bot-opened, bot-closed PR. |
Example
name: Collaborators Only
on:
pull_request_target:
types: [opened, reopened]
jobs:
gate:
uses: psyb0t/reusable-github-workflows/.github/workflows/collaborators-only-workflow.yml@master
with:
close_message: "This repo does not accept external PRs. Open an issue instead."
lock: true
wait-for-default-branch.yml
Lets a tag release what the default branch already built and tested, instead of rebuilding or retesting the same commit. A release tag is pushed on a commit that already ran on the default branch; this workflow blocks the tag's pipeline until that default-branch push run of this same caller workflow file finishes, and hands back its run id so a later job can reuse what it produced. docker-image-workflow.yml's promote_on_tag re-points the release tag at the image the default-branch run already pushed, and create-badges.yml's coverage_run_id reads the coverage artifact from it.
Three outcomes, reported as three distinct failures:
- the push run has not registered yet (a tag lands seconds after the commit it tags), polled for up to
appear_grace_minutes, then a message telling you to push the commit before tagging it;
- the push run is still in progress, polled for up to
timeout_minutes;
- the push run finished and failed, failing with its conclusion and URL and telling you to fix the default branch and re-run or re-tag.
A re-run of the default-branch push is read correctly: the run's own status and conclusion already reflect its latest attempt, so a plain re-fetch by run id is always enough.
Inputs
| Input |
Type |
Default |
Description |
branch |
string |
"" |
Default-branch name the push run must have run on. Empty uses github.event.repository.default_branch. |
timeout_minutes |
number |
120 |
Give up waiting for the default-branch run to COMPLETE after this many minutes, once it has been found. |
poll_seconds |
number |
30 |
Delay between polls of the GitHub Actions API. |