My personal reusable GitHub Actions workflows (geared towards node.js)
(No versioning strategy for these ones, use as inspiration or at your own risk)
- dependency-review.yml – Wrapper around
actions/dependency-review-actionthar configures it to eg. fail for GPL and AGPL dependencies (as is typical in the JS ecosystem) - lint.yml – Runs the npm script
checkon your codebase for linting etc. - type-check.yml – Performs TypeScript type checking across multiple TS versions.
- release-please-4.yml – Full flow for googleapis/release-please-action@v4` – both PR generation and NPM publishing.
- release-please-bot.yml – Like
release-please-4.ymlbut uses a bot account rather than theGITHUB_TOKENwhen it generates PR:s etc. - release-please-oidc.yml – Like
release-please-bot.ymlbut uses OIDC authentication rather than aNPM_TOKEN.
- exit-silently-on-unsupported.yml – Tests that CLI tools exists silently on unsupported Node.js versions (see eg. version-guard).
- simple-test.yml – Runs
npm testonlts/*- nothing more, nothing less. - test-pg.yml – Like
test.ymlbut starts a Postgres service before and includes Postgres version as another dimension in the test matrix. - test.yml – Runs a npm test script (defaulting to
test-ci) across an OS + Node.js version matrix.
- reusable-npm-run.yml – Runs arbitrary npm scripts as a reusable workflow.
- sync-reusable.yml – Reusable flow that runs an npm script and generates a PR whenever the outcome is new.
- codeql-analysis.yml – Deprecated: Use the built-in default one in GitHub instead.
- gh-publish.yml – Deprecated: Use the release-please workflows above instead.
- release-please.yml – Deprecated: Use the newer release-please workflows above.
These environments are typically expected to be locked down to only be allowed to be used from the main branch.
npm– used by all therelease-pleaseactions when publishing to NPM.release-please-4.ymlandrelease-please-bot.ymlhas aNODE_TOKENsecret saved in it whilerelease-please-oidc.ymlinstead has the environment configured in the NPM Trusted Publisher config for the package.pr-bot– used byrelease-please-bot.yml,release-please-oidc.ymlandsync-reusable.ymlto find theAPP_PEMto use withactions/create-github-app-tokento create the token needed to create a PR.
These are the default/required NPM scripts in the above workflows:
check– used bylint.ymlfor linting and code quality checks.test– used bysimple-test.ymlfor running all tests (often includes eg. linting).test-ci– used bytest.ymlandtest-pg.ymlto run all non-linting / non-check tests.- (arbitrary script) – used by
reusable-npm-run.ymlandsync-reusable.ymlfor custom automation.
- Add the new files:
- Either by using a patch:
- Download it to
~/Downloads/release-please.patch - In your project, apply the patch:
git apply --reject ~/Downloads/release-please.patch - Find any
.rejfiles and apply their changes manually
- Download it to
- Or by adding all the files manually
- Either by using a patch:
- Run
npm install -D validate-conventional-committo add the dependency of.husky/commit-msg - Change
{".":"0.0.0"}in.github/release-please/manifest.jsonto the latest tagged version of the module - Configure the repo as Trusted Publisher in NPM:
- Go to
npmjs.com/package/installed-check/access - Set
release-please.ymlas theWorkflow filename - Set
npmas theEnvironment name - (Out of scope but still good to check on that page: Check that the module requires 2FA to publish)
- Go to
- Go to
/settings/environmentsin your repository:- Create a
npmenvironment and importantly set itsDeployment branches and tagsto eitherProtected branches onlyor toSelected branch and tags, adding onlymain - Create a
pr-botenvironment, add theAPP_PEMsecret for the GitHub App that will create the PR:s. Also, importantly, set itsDeployment branches and tagsto eitherProtected branches onlyor toSelected branch and tags, adding onlymain
- Create a
- If a pre-existing repository: Ensure that no tag protection is on in
/settings/rules(previously/settings/tag_protection) - Go to
/settings/actionsin your repository:- Since we use a GitHub app to create PR:s, we can unclick
Allow GitHub Actions to create and approve pull requests - Then we should set
Allow voxpelli, and select non-voxpelli, actions and reusable workflows+Allow actions created by GitHuband then add these to theAllow or block specified actions and reusable workflowslist:googleapis/release-please-action@v4, mtfoley/pr-compliance-action@*,
- Since we use a GitHub app to create PR:s, we can unclick
- Commit your changes as semantic versioning (eg.
ci: added automatic release flow) and push it - You should now be done 🎉 And Release Please will be creating PR:s and triggering releases for you.
Optional additional config to be added to .github/release-please/config.json:
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,Instead of downloading and applying the patch, you can add these files manually:
.github/release-please/config.json
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/v16.12.0/schemas/config.json",
"release-type": "node",
"include-component-in-tag": false,
"changelog-sections": [
{ "type": "feat", "section": "🌟 Features", "hidden": false },
{ "type": "fix", "section": "🩹 Fixes", "hidden": false },
{ "type": "docs", "section": "📚 Documentation", "hidden": false },
{ "type": "chore", "section": "🧹 Chores", "hidden": false },
{ "type": "perf", "section": "🧹 Chores", "hidden": false },
{ "type": "refactor", "section": "🧹 Chores", "hidden": false },
{ "type": "test", "section": "🧹 Chores", "hidden": false },
{ "type": "build", "section": "🤖 Automation", "hidden": false },
{ "type": "ci", "section": "🤖 Automation", "hidden": true }
],
"packages": {
".": {}
}
}.github/release-please/manifest.json
+{".":"0.0.0"}.github/workflows/compliance.yml
name: Compliance
on:
pull_request_target:
types: [opened, edited, reopened]
permissions:
pull-requests: write
jobs:
compliance:
runs-on: ubuntu-latest
steps:
- uses: mtfoley/pr-compliance-action@11b664f0fcf2c4ce954f05ccfcaab6e52b529f86
with:
body-auto-close: false
body-regex: '.*'
ignore-authors: |
renovate
renovate[bot]
ignore-team-members: false.github/workflows/release-please.yml
name: Release Please
on:
push:
branches:
- main
workflow_dispatch:
inputs:
force-release:
description: 'Force release to npm'
required: false
type: boolean
permissions:
contents: read
id-token: write
jobs:
release-please:
uses: voxpelli/ghatemplates/.github/workflows/release-please-oidc.yml@main
secrets: inherit
with:
app-id: '1082006'
force-release: ${{ inputs.force-release || false }}
.husky/commit-msg
#!/usr/bin/env sh
npx --no validate-conventional-commit < .git/COMMIT_EDITMSGLicensed under MIT.
fastify/workflows– reusable workflows for use in the Fastify organizationmdn/workflows– reusable GitHub Actions workflowsSocketDev/workflows– reusable workflows for use in the SocketDev organization