Skip to content

Commit 20bd56b

Browse files
ci: fix pr title verifier
1 parent 4979e43 commit 20bd56b

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

.github/workflows/verify.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
name: PR Verifier
1+
name: "PR Title Verifier"
22

33
on:
44
pull_request:
5-
types: [opened, edited, synchronize,reopened]
6-
7-
permissions:
8-
contents: read # Read-only access to repository contents
9-
pull-requests: read # Read-only access to pull request details
5+
types: [opened, edited, synchronize, reopened]
106

117
jobs:
12-
138
verify:
14-
name: Verify PR contents
159
runs-on: ubuntu-latest
1610
steps:
17-
- name: Verifier action
18-
id: verifier
19-
uses: kubernetes-sigs/[email protected]
20-
with:
21-
github_token: ${{ secrets.GITHUB_TOKEN }}
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Get PR title
15+
id: get_title
16+
run: echo "::set-output name=title::${{ github.event.pull_request.title }}"
17+
18+
- name: Run PR Title Checker
19+
run: |
20+
chmod +x check_pr_title.sh
21+
./check_pr_title.sh "${{ steps.get_title.outputs.title }}"

hack/ci/pr-title.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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="^\[[\w-\.]*\]"
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+
# Check PR type prefix
26+
if [[ "$trimmed_title" =~ ^⚠ ]] || [[ "$trimmed_title" =~ ^✨ ]] || [[ "$trimmed_title" =~ ^🐛 ]] || [[ "$trimmed_title" =~ ^📖 ]] || [[ "$trimmed_title" =~ ^🚀 ]] || [[ "$trimmed_title" =~ ^🌱 ]]; then
27+
echo "PR title is valid: $trimmed_title"
28+
exit 0
29+
else
30+
echo "Error: No matching PR type indicator found in title."
31+
echo "You need to have one of these as the prefix of your PR title:"
32+
echo "- Breaking change: ⚠ (:warning:)"
33+
echo "- Non-breaking feature: ✨ (:sparkles:)"
34+
echo "- Patch fix: 🐛 (:bug:)"
35+
echo "- Docs: 📖 (:book:)"
36+
echo "- Release: 🚀 (:rocket:)"
37+
echo "- Infra/Tests/Other: 🌱 (:seedling:)"
38+
exit 1
39+
fi

0 commit comments

Comments
 (0)