Skip to content

Commit de56c57

Browse files
🌱 (ci): improve PR title validation for a better security (kubernetes-sigs#4583)
(ci): improve PR title validation for a better security - Remove dependency on external scripts () - Eliminate use of environment variables to prevent exposure risks - Perform inline PR title sanitization and validation This makes PR title verification fully self-contained, more efficient, and more secure.
1 parent 874f8fd commit de56c57

File tree

2 files changed

+31
-54
lines changed

2 files changed

+31
-54
lines changed

.github/workflows/verify.yml

+31-7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,35 @@ jobs:
1212
- name: Checkout code
1313
uses: actions/checkout@v4
1414

15-
- name: Get PR title
16-
id: get_title
17-
run: echo "title=${{ github.event.pull_request.title }}" >> $GITHUB_ENV
18-
19-
- name: Run PR Title Checker
20-
id: check_title
15+
- name: Validate PR Title Format
2116
run: |
22-
./test/pr-title-checker.sh "${{ env.title }}"
17+
# Extract raw PR title
18+
RAW_TITLE="${{ github.event.pull_request.title }}"
19+
20+
# Ensure title is not empty
21+
if [[ -z "$RAW_TITLE" ]]; then
22+
echo "❌ Error: PR title cannot be empty."
23+
exit 1
24+
fi
25+
26+
# Enforce strict format (must start with one of the required emojis)
27+
if ! [[ "$RAW_TITLE" =~ ^(⚠|✨|🐛|📖|🚀|🌱) ]]; then
28+
echo "❌ Error: Invalid PR title format."
29+
echo "Your PR title must start with one of the following indicators:"
30+
echo "- Breaking change: ⚠ (:warning:)"
31+
echo "- Non-breaking feature: ✨ (:sparkles:)"
32+
echo "- Patch fix: 🐛 (:bug:)"
33+
echo "- Docs: 📖 (:book:)"
34+
echo "- Release: 🚀 (:rocket:)"
35+
echo "- Infra/Tests/Other: 🌱 (:seedling:)"
36+
exit 1
37+
fi
38+
39+
# Ensure title does not exceed 100 characters
40+
if [[ ${#RAW_TITLE} -gt 100 ]]; then
41+
echo "❌ Error: PR title is too long (max 100 characters)."
42+
exit 1
43+
fi
44+
45+
# Confirm PR title is valid
46+
echo "✅ PR title is valid: '$RAW_TITLE'"

test/pr-title-checker.sh

-47
This file was deleted.

0 commit comments

Comments
 (0)