Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Add PR title checker #1087

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Changes from 2 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
66 changes: 66 additions & 0 deletions .github/workflows/pr-format-verification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: PR format verification

on:
pull_request:
branches:
- main
types:
# By default, a workflow only runs when a pull_request event's activity type is opened, synchronize, or reopened.
- opened
- synchronize
- edited
- reopened

defaults:
run:
shell: bash -euo pipefail {0}

jobs:
pr-format-verification:
name: Check PR title
# Only run the job if the PR is not created by dependabot.
# We still want dependabot PRs to go through, they contain important security updates,
# and there's no good way of getting dependabot to conform to our PR format
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-22.04
steps:
- name: Verify PR Title
env:
ON_FAILURE: |
PR title must be prefixed with component names (e.g., "vm-builder: ..." or "agent/subsystem,neonvm: ...") OR body must contain the string "<!-- affects all -->"

Some common component names:
* "agent" (the autoscaler-agent)
* "plugin" (the scheduler)
* "neonvm-controller" / "neonvm-runner" / "vm-builder" (individual parts of "neonvm")
* "neonvm" (when the PR affects most neonvm-related components)
* "ci" / "CI" - depending on your capitalization

Some common subsystems:
* "agent/billing" (generation of billing events in the autoscaler-agent)
* "agent/core" (core scaling algorithm in the autoscaler-agent)
* "plugin/trans" (core resource logic in the scheduler plugin)
* "ci/lint" (lints workflow in CI)

Check recent PRs for examples: https://github.com/neondatabase/autoscaling/pulls?q=is%3Apr+is%3Aclosed
run: |
title="$(jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH")"
body="$(jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH")"

# If the PR body contains the magic string, ignore it.
if grep -q '<!-- affects all -->' <(echo "$body") >/dev/null ; then
exit 0
fi

# If the title looks like 'Revert "..."', then give it a pass.
if grep -q '^Revert "' <(echo "$title") >/dev/null ; then
exit 0
fi

# Check that title matches the regex:
TITLE_REGEX='^[a-z0-9-.]+(/[a-z0-9-.]+)*(,[a-z0-9-.]+(/[a-z0-9-.]+)*)*: .*$'
sharnoff marked this conversation as resolved.
Show resolved Hide resolved

if ! grep -qiP "$TITLE_REGEX" <(echo "$title") >/dev/null ; then
echo "$ON_FAILURE" >/dev/stderr
exit 1
fi
Loading