Skip to content

Commit 1c280ad

Browse files
authored
Merge pull request #5300 from richardcase/verify_update
🌱 chore: title verifier update
2 parents 2293c88 + 616ed69 commit 1c280ad

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ Fixes #
2828
**Special notes for your reviewer**:
2929

3030
**Checklist**:
31-
<!-- Put an "X" character inside the brackets of each completed task. Some may be optional depending on the PR in which case these can be deleted -->
31+
<!-- Put an "X" character inside the brackets of each completed task. Some may be optional depending on the PR in which case these can be deleted
32+
33+
Please add an icon to the title of this PR, the icon will be either ⚠️ (:warning:, major or breaking changes), ✨ (:sparkles:, feature additions), 🐛 (:bug:, patch and bugfixes), 📖 (:book:, documentation or proposals), or 🌱 (:seedling:, minor or other)
34+
-->
3235

3336
- [ ] squashed commits
3437
- [ ] includes documentation
35-
- [ ] includes [emojis](https://github.com/kubernetes-sigs/kubebuilder-release-tools?tab=readme-ov-file#kubebuilder-project-versioning)
38+
- [ ] includes emoji in title
3639
- [ ] adds unit tests
3740
- [ ] adds or updates e2e tests
3841

.github/workflows/pr-verify.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ on:
44
pull_request_target:
55
types: [opened, edited, synchronize, reopened]
66

7-
permissions:
8-
checks: write
9-
107
jobs:
118
verify:
129
runs-on: ubuntu-latest
1310
name: verify PR contents
1411
steps:
15-
- name: Verifier action
16-
id: verifier
17-
uses: kubernetes-sigs/kubebuilder-release-tools@012269a88fa4c034a0acf1ba84c26b195c0dbab4 # tag=v0.4.3
18-
with:
19-
github_token: ${{ secrets.GITHUB_TOKEN }}
12+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2
13+
14+
- name: Check if PR title is valid
15+
env:
16+
PR_TITLE: ${{ github.event.pull_request.title }}
17+
run: |
18+
./hack/verify-pr-title.sh "${PR_TITLE}"

hack/verify-pr-title.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Copyright 2024 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Define regex patterns
18+
WIP_REGEX="^\W?WIP\W"
19+
TAG_REGEX="^\[[[:alnum:]\._-]*\]"
20+
PR_TITLE="$1"
21+
22+
# Trim WIP and tags from title
23+
trimmed_title=$(echo "$PR_TITLE" | sed -E "s/$WIP_REGEX//" | sed -E "s/$TAG_REGEX//" | xargs)
24+
25+
# Normalize common emojis in text form to actual emojis
26+
trimmed_title=$(echo "$trimmed_title" | sed -E "s/:warning:/⚠/g")
27+
trimmed_title=$(echo "$trimmed_title" | sed -E "s/:sparkles:/✨/g")
28+
trimmed_title=$(echo "$trimmed_title" | sed -E "s/:bug:/🐛/g")
29+
trimmed_title=$(echo "$trimmed_title" | sed -E "s/:book:/📖/g")
30+
trimmed_title=$(echo "$trimmed_title" | sed -E "s/:rocket:/🚀/g")
31+
trimmed_title=$(echo "$trimmed_title" | sed -E "s/:seedling:/🌱/g")
32+
33+
# Check PR type prefix
34+
if [[ "$trimmed_title" =~ ^(⚠||🐛|📖|🚀|🌱) ]]; then
35+
echo "PR title is valid: $trimmed_title"
36+
else
37+
echo "Error: No matching PR type indicator found in title."
38+
echo "You need to have one of these as the prefix of your PR title:"
39+
echo "- Breaking change: ⚠ (:warning:)"
40+
echo "- Non-breaking feature: ✨ (:sparkles:)"
41+
echo "- Patch fix: 🐛 (:bug:)"
42+
echo "- Docs: 📖 (:book:)"
43+
echo "- Release: 🚀 (:rocket:)"
44+
echo "- Infra/Tests/Other: 🌱 (:seedling:)"
45+
exit 1
46+
fi
47+
48+
# Check that PR title does not contain Issue or PR number
49+
if [[ "$trimmed_title" =~ \#[0-9]+ ]]; then
50+
echo "Error: PR title should not contain issue or PR number."
51+
echo "Issue numbers belong in the PR body as either \"Fixes #XYZ\" (if it closes the issue or PR), or something like \"Related to #XYZ\" (if it's just related)."
52+
exit 1
53+
fi

0 commit comments

Comments
 (0)