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
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ updates:
interval: weekly
# Propose a release only once it is a week old, so a compromised one is
# more likely to have been found and pulled by then.
# modulane's own releases, such as modulane/workflows, come straight away.
cooldown:
default-days: 7
exclude: ['modulane/*']
# A ci: title never triggers a release.
commit-message:
prefix: ci
Expand Down
24 changes: 5 additions & 19 deletions .github/workflows/ai-disclosure.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
name: AI disclosure

# Every pull request says whether AI tools were used, the maintainer's
# included. The "AI use" section of the pull request template has two boxes:
# "No AI tool was used", or "AI tools were used" with each tool and what it
# did written under it. This check fails until exactly one box is ticked, and
# the main ruleset requires it. Editing the description runs it again.
#
# modulane/ai-disclosure reads the description from the event and needs no
# token and no checkout. Dependabot pull requests are exempt.
# included: modulane/workflows fails until the "AI use" section of the
# description ticks exactly one box. The main ruleset requires this check.
# Dependabot pull requests are exempt.
on:
pull_request:
types: [opened, edited, reopened, synchronize]

permissions: {}

# Only the latest description matters.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

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

steps:
- name: Check the AI use section
uses: modulane/ai-disclosure@5d2b11a0b28a8103f1b8d9ac31c7c7d79688b218 # v1.0.0
uses: modulane/workflows/.github/workflows/ai-disclosure.yml@8a5ecaa4dc296a9e04849212ec06ddeec2a2480b # v1.0.0
36 changes: 5 additions & 31 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Labels

# .github/labels.json is the list of labels this repository uses. When it
# 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.
# changes on main, modulane/workflows creates the labels that are missing and
# updates the others. Labels that are not in the file are left alone.
on:
push:
branches: [main]
Expand All @@ -13,35 +12,10 @@ on:

permissions: {}

# Two syncs never run at once; a later one waits and applies the newest file.
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
sync:
name: Sync labels
runs-on: ubuntu-latest
timeout-minutes: 5

labels:
name: Labels
uses: modulane/workflows/.github/workflows/labels.yml@8a5ecaa4dc296a9e04849212ec06ddeec2a2480b # v1.0.0
permissions:
contents: read # read .github/labels.json
issues: write # create and edit labels

steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Create or update each label
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
jq -c '.[]' .github/labels.json | while read -r label; do
gh label create "$(jq -r .name <<< "$label")" \
--color "$(jq -r .color <<< "$label")" \
--description "$(jq -r .description <<< "$label")" \
--force
done
88 changes: 9 additions & 79 deletions .github/workflows/pr-labels.yml
Original file line number Diff line number Diff line change
@@ -1,91 +1,21 @@
name: Pull request labels

# Label every pull request from its Conventional Commit title: its kind
# (feat: enhancement, fix: bug, docs: documentation, ...) and the release
# that merging it publishes (feat: minor, fix: patch, a "!" major, other
# types none). The labels follow the title when it is edited. A new pull
# request is also assigned to its author.
# modulane/workflows labels every pull request from its Conventional Commit
# title (its kind and the release that merging it publishes) and assigns a
# new pull request to its author.
#
# pull_request_target gives this job a token that can label pull requests
# from forks. It is safe here because the job never checks out or runs code
# from the pull request: it only reads the title, through an environment
# variable, never interpolated into the script.
#
# Keep it safe: never add a checkout of the pull request to this workflow, and
# 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.
# pull_request_target gives the job a token that can label pull requests from
# forks. It is safe because the called workflow never checks out or runs code
# from the pull request. Never add a checkout to this workflow.
on:
pull_request_target: # zizmor: ignore[dangerous-triggers] no pull request code is checked out or run
types: [opened, edited, reopened]

permissions: {}

# Only the latest title matters.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
label:
name: Label from the title
runs-on: ubuntu-latest
timeout-minutes: 5

pr-labels:
name: Pull request labels
uses: modulane/workflows/.github/workflows/pr-labels.yml@8a5ecaa4dc296a9e04849212ec06ddeec2a2480b # v1.0.0
permissions:
pull-requests: write # add and remove labels, assign the author

steps:
- name: Apply the kind and release labels
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.pull_request.number }}
TITLE: ${{ github.event.pull_request.title }}
AUTHOR: ${{ github.event.pull_request.user.login }}
ACTION: ${{ github.event.action }}
run: |
# "type(scope)!: summary"; the "Pull request title" check enforces
# the format, so a title that does not match gets no labels.
pattern='^([a-z]+)(\([^)]*\))?(!)?: '
kind=''
release=''

if [[ $TITLE =~ $pattern ]]; then
case ${BASH_REMATCH[1]} in
feat) kind=enhancement release='release: minor' ;;
fix) kind=bug release='release: patch' ;;
docs) kind=documentation release='release: none' ;;
ci | build) kind=ci release='release: none' ;;
*) kind=maintenance release='release: none' ;;
esac

if [[ -n ${BASH_REMATCH[3]} ]]; then
release='release: major'
fi
fi

# Labels this workflow manages. Any other label is left alone.
managed=(enhancement bug documentation ci maintenance
'release: major' 'release: minor' 'release: patch' 'release: none')

current=$(gh api "repos/$GH_REPO/issues/$NUMBER/labels" --jq '.[].name')

for label in "${managed[@]}"; do
if [[ $label != "$kind" && $label != "$release" ]] &&
grep -qxF "$label" <<< "$current"; then
gh api -X DELETE "repos/$GH_REPO/issues/$NUMBER/labels/${label// /%20}" > /dev/null
fi
done

for label in "$kind" "$release"; do
if [[ -n $label ]]; then
gh api "repos/$GH_REPO/issues/$NUMBER/labels" -f "labels[]=$label" > /dev/null
fi
done

# Only people with write access can be assigned; GitHub ignores
# the request for anyone else.
if [[ $ACTION == opened ]]; then
gh api "repos/$GH_REPO/issues/$NUMBER/assignees" -f "assignees[]=$AUTHOR" > /dev/null
fi
46 changes: 9 additions & 37 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,18 @@
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.
# main and decides the release. modulane/workflows checks that it is a
# lowercase Conventional Commit.
on:
pull_request:
types: [opened, edited, reopened, synchronize]

permissions:
pull-requests: read # read the pull request title

# Only the latest title and commit of a pull request matter.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: {}

jobs:
check:
name: Conventional Commit title
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Check the title
uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
# "feat: Add X" reads oddly in release notes; keep the summary lowercase.
subjectPattern: ^[^A-Z].*$
subjectPatternError: >-
Start the summary "{subject}" with a lowercase letter, for example
"feat: add project search".
pr-title:
name: Pull request title
uses: modulane/workflows/.github/workflows/pr-title.yml@8a5ecaa4dc296a9e04849212ec06ddeec2a2480b # v1.0.0
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
33 changes: 5 additions & 28 deletions .github/workflows/zizmor.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
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.
# modulane/workflows audits 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.
on:
pull_request:
paths:
- .github/**

permissions: {}

# A new push to a pull request cancels the run it replaces.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
zizmor:
name: zizmor
runs-on: ubuntu-latest
timeout-minutes: 5

name: Workflow security
uses: modulane/workflows/.github/workflows/zizmor.yml@8a5ecaa4dc296a9e04849212ec06ddeec2a2480b # v1.0.0
permissions:
contents: read # read the workflows

steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

# Findings appear as annotations on the pull request and fail the job.
# 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
with:
version: 1.31.1
advanced-security: false
annotations: true
Loading