Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ai-disclosure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ name: AI disclosure
#
# modulane/ai-disclosure reads the description from the event and needs no
# token and no checkout. Dependabot pull requests are exempt.
#
# Other repositories call this workflow (see the README); this repository also
# runs it on its own pull requests.
on:
pull_request:
types: [opened, edited, reopened, synchronize]
workflow_call:

permissions: {}

Expand All @@ -21,10 +25,12 @@ concurrency:

jobs:
check:
name: AI disclosure
name: AI use section
runs-on: ubuntu-latest
timeout-minutes: 5

permissions: {}

steps:
- name: Check the AI use section
uses: modulane/ai-disclosure@5d2b11a0b28a8103f1b8d9ac31c7c7d79688b218 # v1.0.0
35 changes: 21 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ concurrency:
cancel-in-progress: true

jobs:
# Replace this job with the repository's own checks: install, lint, type
# check, test and build, with a Node.js matrix (and an OS matrix for a CLI).
# In this reference repository it checks that every JSON file parses, so the
# labels and rulesets stay valid. List each new job in ci-passed below.
# Prettier checks the formatting of every file, which also fails on a
# workflow or JSON file that does not parse. The workflows themselves run
# on this repository's own pull requests. List each new job in ci-passed
# below.
checks:
name: Checks
runs-on: ubuntu-latest
Expand All @@ -33,16 +33,23 @@ jobs:
with:
persist-credentials: false

- name: Check that every JSON file parses
run: |
status=0
while IFS= read -r file; do
if ! node -e 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"))' "$file"; then
echo "::error file=$file::Invalid JSON."
status=1
fi
done < <(git ls-files '*.json')
exit $status
# Corepack provides the Yarn version pinned in package.json
# "packageManager". It must be enabled before setup-node, which runs
# Yarn to find its cache.
- name: Enable Corepack
run: corepack enable

- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
cache: yarn

- name: Install dependencies
run: yarn install --immutable

- name: Check formatting
run: yarn check

# The one CI check the main ruleset requires, so adding or dropping a job or
# a Node.js version in the matrix never means editing the ruleset. It runs
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ name: Labels
# changes on main, create the labels that are missing and update the colour
# and description of the others. Labels that are not in the file are left
# alone, so removing one is a deliberate step in the repository settings.
#
# Other repositories call this workflow (see the README); this repository also
# runs it for its own labels.
on:
push:
branches: [main]
paths:
- .github/labels.json
workflow_dispatch:
workflow_call:

permissions: {}

Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/pr-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ name: Pull request labels
# never interpolate ${{ github.event.* }} straight into a run: block — pass
# untrusted fields through env, as below. Either change would let any GitHub
# user run code or shell commands with this job's write token.
#
# Other repositories call this workflow from their own pull_request_target
# workflow (see the README); this repository also runs it on its own pull
# requests.
on:
pull_request_target: # zizmor: ignore[dangerous-triggers] no pull request code is checked out or run
types: [opened, edited, reopened]
workflow_call:

permissions: {}

Expand Down Expand Up @@ -85,7 +90,8 @@ jobs:
done

# Only people with write access can be assigned; GitHub ignores
# the request for anyone else.
if [[ $ACTION == opened ]]; then
# the request for anyone else, but refuses it for a bot such as
# Dependabot (HTTP 403), so bots are not assigned.
if [[ $ACTION == opened && $AUTHOR != *'[bot]' ]]; then
gh api "repos/$GH_REPO/issues/$NUMBER/assignees" -f "assignees[]=$AUTHOR" > /dev/null
fi
70 changes: 66 additions & 4 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ name: Pull request title

# Pull requests are squash-merged, so the title becomes the commit message on
# main and decides the release (feat: minor, fix: patch, others none). Check
# that it follows Conventional Commits before it can be merged.
# that it follows Conventional Commits before it can be merged. In a monorepo,
# the package-scope input also checks that a release title names the package
# it releases: "fix(prettier-config): ..." for packages/prettier-config.
#
# Other repositories call this workflow (see the README); this repository also
# runs it on its own pull requests.
on:
pull_request:
types: [opened, edited, reopened, synchronize]
workflow_call:
inputs:
package-scope:
description: >-
Require a release title (feat, fix or breaking) to name a package
under packages/ that the pull request changes

permissions:
pull-requests: read # read the pull request title
type: boolean
default: false

permissions: {}

# Only the latest title and commit of a pull request matter.
concurrency:
Expand All @@ -21,11 +34,15 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5

permissions:
contents: read # list the files of a pull request in a private repository
pull-requests: read # read the pull request title and its files

steps:
- name: Check the title
uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
with:
types: |
feat
Expand All @@ -44,3 +61,48 @@ jobs:
subjectPatternError: >-
Start the summary "{subject}" with a lowercase letter, for example
"feat: add project search".

# multi-semantic-release releases every package whose folder the commit
# changes, whatever the title says. The scope makes that visible: a
# feat: or fix: title (or one with "!") must name a package that the
# pull request changes, by its folder under packages/.
- name: Check the package scope
if: inputs.package-scope
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.pull_request.number }}
TITLE: ${{ github.event.pull_request.title }}
run: |
# The step above reports a title that does not match the format.
pattern='^([a-z]+)(\(([^)]*)\))?(!)?: '
if [[ ! $TITLE =~ $pattern ]]; then
exit 0
fi
type=${BASH_REMATCH[1]}
scope=${BASH_REMATCH[3]}
breaking=${BASH_REMATCH[4]}

if [[ $type != feat && $type != fix && -z $breaking ]]; then
echo "A $type: title releases nothing; no package scope needed."
exit 0
fi

changed=$(gh api --paginate "repos/$GH_REPO/pulls/$NUMBER/files" --jq '.[].filename' |
sed -n 's|^packages/\([^/]*\)/.*|\1|p' | sort -u)
list=$(paste -sd ' ' <<< "$changed")

if [[ -z $changed ]]; then
echo "::error::A $type: title releases a package, but this pull request changes none. Use another type, such as docs:, ci: or chore:."
exit 1
fi
if [[ -z $scope ]] || ! grep -qxF "$scope" <<< "$changed"; then
echo "::error::Name the package this releases in the title, for example \"$type($(head -n 1 <<< "$changed")): ...\". Packages this pull request changes: $list."
exit 1
fi

others=$(grep -vxF "$scope" <<< "$changed" | paste -sd ' ' || true)
if [[ -n $others ]]; then
echo "::warning::This pull request also changes $others: merging it releases them too, with the same type."
fi
echo "Releases $scope."
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Release
# in the same run and from the same commit. semantic-release decides from the
# commit messages whether a release is needed: fix: and feat: commits release,
# docs:, style: and chore: do not. A release is a vX.Y.Z git tag and a GitHub
# release; publishing to npm as well is described in the README.
# release, which the other repositories pin their calls to.
# The manual trigger remains available as a fallback, and its dry run shows
# what the next release would be without creating anything.
on:
Expand Down Expand Up @@ -33,9 +33,7 @@ jobs:
name: Release
needs: ci
# Release only from main, and never from a fork that has Actions enabled.
# Replace REPO-NAME with the repository's name: until then this job never
# runs, which is also why it never runs in modulane/repo-template.
if: github.repository == 'modulane/REPO-NAME' && github.ref == 'refs/heads/main'
if: github.repository == 'modulane/workflows' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 15

Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/zizmor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ name: Workflow security

# Audit the workflows with zizmor whenever a pull request changes them, so a
# regression (an unpinned action, a persisted token, a risky trigger) is
# caught before it reaches main.
# caught before it reaches main. It audits the repository that runs it: the
# caller's, when another repository calls this workflow.
#
# Other repositories call this workflow (see the README); this repository also
# runs it on its own pull requests.
on:
pull_request:
paths:
- .github/**
workflow_call:

permissions: {}

Expand Down Expand Up @@ -34,7 +39,7 @@ jobs:
# The zizmor version is fixed so a new audit never fails an unrelated
# pull request; Dependabot does not update it, so raise it by hand.
- name: Run zizmor
uses: zizmorcore/zizmor-action@53290badfa369cb0bf7ad16342cb62c2fa47ac7b # v0.8.0
uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1
with:
version: 1.31.1
advanced-security: false
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ Desktop.ini
.eslintcache

# Generated npm package archives
*.tgz
*.tgz
# Yarn: keep only what the team shares
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.yarn/
yarn.lock
3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

enableTelemetry: false
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,48 @@

Reusable GitHub Actions workflows for modulane repositories. Each repository calls them instead of keeping its own copy, so a change made here reaches every repository at once.

> **Status:** planned.
## What it holds

## What it will hold
| Workflow | What it does |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pr-title.yml` | Checks that the pull request title is a lowercase Conventional Commit. With `package-scope: true`, a monorepo's `feat:` or `fix:` title must also name the package it releases. |
| `pr-labels.yml` | Labels each pull request from its title (kind and `release:` label) and assigns its author, unless the author is a bot. |
| `ai-disclosure.yml` | Fails until the pull request's **AI use** section says whether AI tools were used, and how, with [modulane/ai-disclosure](https://github.com/modulane/ai-disclosure). |
| `labels.yml` | Syncs the repository labels from its `.github/labels.json`. |
| `zizmor.yml` | Audits the security of the repository's workflows. |

- **CI passed:** the single job that the main ruleset requires, gathering the repository's own checks.
- **Pull request title:** a lowercase Conventional Commit, with the package scope check for monorepos.
- **Pull request labels:** the kind and `release:` labels from the title, and the author assigned.
- **AI disclosure**, **labels sync** and **zizmor**.
`ci.yml` and `release.yml` stay in each repository: CI runs the repository's own checks, and the release differs between a package, an action and a monorepo. This repository runs its workflows on its own pull requests too.

## Usage

Each repository keeps a short workflow per check, with its own trigger, that calls the workflow here. [repo-template](https://github.com/modulane/repo-template) holds the full set, and new repositories start from it. For example:

```yaml
name: Pull request title

on:
pull_request:
types: [opened, edited, reopened, synchronize]

permissions: {}

jobs:
pr-title:
name: Pull request title
uses: modulane/workflows/.github/workflows/pr-title.yml@<sha> # vX.Y.Z
permissions:
contents: read # list the files of a pull request in a private repository
pull-requests: read # read the pull request title and its files
```

Calls are pinned to a commit SHA, like every other action, and Dependabot keeps them up to date.
- **Pinned to a commit.** Calls are pinned to the commit SHA of a release, like every other action, and Dependabot proposes the new release in each repository.
- **Permissions.** A called workflow gets at most the permissions its caller grants, so each call grants what the workflow's jobs ask for.
- **Check names.** A check from a called workflow is named after the calling job and the called one, for example **Pull request title / Conventional Commit title**. The main ruleset requires the checks by these names.
- **No concurrency in the caller.** The workflows here set their own concurrency group; the same group in the caller would cancel the call.

## Releases

[repo-template](https://github.com/modulane/repo-template) stays the reference setup: it holds the calls to these workflows, and new repositories still start from it.
Every merge to `main` runs semantic-release: a `feat:` title releases a minor version, a `fix:` title a patch, and a `!` a major one, which callers then have to adapt to. Changing a workflow's inputs, permissions or job names is breaking for its callers.

## License

Expand Down
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "workflows",
"version": "0.0.0-development",
"description": "Reusable GitHub Actions workflows that every modulane repository calls.",
"license": "MIT",
"private": true,
"scripts": {
"check": "yarn format:check",
"format": "prettier --write .",
"format:check": "prettier --check ."
},
"prettier": "@modulane/prettier-config",
"engines": {
"node": "^22.22.3 || ^24.15.0 || >=26.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/modulane/workflows.git"
},
"homepage": "https://github.com/modulane/workflows#readme",
"bugs": {
"url": "https://github.com/modulane/workflows/issues"
},
"devDependencies": {
"@modulane/prettier-config": "^1.0.0",
"prettier": "3.9.10",
"semantic-release": "^25.0.9"
},
"packageManager": "yarn@4.18.1+sha512.b2e1e7524f654f2749d32b4ebcb4622473cb5bcbc485df2007e12a154e50162a4d795526768bc5f5b8f81717bfd79deb2472813d86fb5ae2eb551fa9c872b08f"
}
Loading
Loading