From 0bd051cc1638baeacdf6cce375314f6ecf592f38 Mon Sep 17 00:00:00 2001 From: Em Sharnoff Date: Tue, 24 Sep 2024 19:07:55 -0700 Subject: [PATCH 1/3] CI: Add PR title checker Loosely adapted the workflow from what we have in neondatabase/cloud, but with the format changed to match what we've previously done in this repo. --- .github/workflows/pr-format-verification.yml | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/pr-format-verification.yml diff --git a/.github/workflows/pr-format-verification.yml b/.github/workflows/pr-format-verification.yml new file mode 100644 index 000000000..a222b1224 --- /dev/null +++ b/.github/workflows/pr-format-verification.yml @@ -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 "" + + 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 '' <(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-.]+)*)*: .*$' + + if ! grep -qP "$TITLE_REGEX" <(echo "$title") >/dev/null ; then + echo "$ON_FAILURE" >/dev/stderr + exit 1 + fi From 37089eb9fd1fc51a189310287cec25e019847527 Mon Sep 17 00:00:00 2001 From: Em Sharnoff Date: Tue, 24 Sep 2024 20:22:07 -0700 Subject: [PATCH 2/3] add -i flag to grep Meant to include this; forgot! --- .github/workflows/pr-format-verification.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-format-verification.yml b/.github/workflows/pr-format-verification.yml index a222b1224..26e94af38 100644 --- a/.github/workflows/pr-format-verification.yml +++ b/.github/workflows/pr-format-verification.yml @@ -60,7 +60,7 @@ jobs: # Check that title matches the regex: TITLE_REGEX='^[a-z0-9-.]+(/[a-z0-9-.]+)*(,[a-z0-9-.]+(/[a-z0-9-.]+)*)*: .*$' - if ! grep -qP "$TITLE_REGEX" <(echo "$title") >/dev/null ; then + if ! grep -qiP "$TITLE_REGEX" <(echo "$title") >/dev/null ; then echo "$ON_FAILURE" >/dev/stderr exit 1 fi From 123ed021d0634529216cb34f8ba4e2b5c1bc9cb9 Mon Sep 17 00:00:00 2001 From: Em Sharnoff Date: Mon, 30 Sep 2024 15:03:36 -0700 Subject: [PATCH 3/3] break up title regex --- .github/workflows/pr-format-verification.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-format-verification.yml b/.github/workflows/pr-format-verification.yml index 26e94af38..1a49a390f 100644 --- a/.github/workflows/pr-format-verification.yml +++ b/.github/workflows/pr-format-verification.yml @@ -58,7 +58,11 @@ jobs: fi # Check that title matches the regex: - TITLE_REGEX='^[a-z0-9-.]+(/[a-z0-9-.]+)*(,[a-z0-9-.]+(/[a-z0-9-.]+)*)*: .*$' + WORD='[a-z0-9-.]+' + COMPONENT="$WORD(/$WORD)*" # one or more '/'-separated words + TITLE_PREFIX="$COMPONENT(,$COMPONENT)*" # one or more ','-separated components + TITLE_MSG='.+' # Any non-empty message. + TITLE_REGEX="^$TITLE_PREFIX: $TITLE_MSG\$" if ! grep -qiP "$TITLE_REGEX" <(echo "$title") >/dev/null ; then echo "$ON_FAILURE" >/dev/stderr