Skip to content

Commit f904201

Browse files
committed
Validate CHANGELOG generation
1. Check that CHANGELOG.md was updated - Ensures the file is modified in the PR. 2. Validate the entry format - Ensures it matches the pattern: * [#PR_NUMBER](PR_URL): Description - [@username](https://github.com/username). 3. Enforce exactly one entry - Validates that only ONE changelog entry is added per PR. 4. Reject blank lines - Ensures no blank lines or additional content is added. The validation will run automatically on all pull requests (when opened, updated, or reopened). If the validation fails, it will provide clear error messages explaining what needs to be fixed. The message dynamically refers to "the topmost version section (e.g., under '### X.X.X (Next)')" instead of hardcoding a specific version number. Resolves: #48.
1 parent f845036 commit f904201

File tree

3 files changed

+93
-11
lines changed

3 files changed

+93
-11
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22

33
*Description of changes:*
44

5-
### Pull Request Checklist:
6-
7-
- [ ] I have added a contribution line at the top of [CHANGELOG.md](CHANGELOG.md).
8-
95
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Validate Changelog
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
check-changelog:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout the repository
12+
uses: actions/checkout@v6
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Check if CHANGELOG.md was updated
17+
run: |
18+
# Get the list of changed files in this PR
19+
git fetch origin ${{ github.base_ref }}
20+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
21+
22+
echo "Files changed in this PR:"
23+
echo "$CHANGED_FILES"
24+
echo ""
25+
26+
# Check if CHANGELOG.md is in the list of changed files
27+
if ! echo "$CHANGED_FILES" | grep -q "^CHANGELOG.md$"; then
28+
echo "✗ CHANGELOG.md has not been updated"
29+
echo ""
30+
echo "Please update CHANGELOG.md with your changes following the format:"
31+
echo "* [#PR_NUMBER](PR_URL): Description - [@username](https://github.com/username)."
32+
echo ""
33+
echo "Add your entry under the topmost version section (e.g., under '### X.X.X (Next)')."
34+
exit 1
35+
fi
36+
37+
echo "✓ CHANGELOG.md has been updated"
38+
echo ""
39+
40+
- name: Validate changelog entry format
41+
run: |
42+
# Get the diff for CHANGELOG.md
43+
git fetch origin ${{ github.base_ref }}
44+
CHANGELOG_DIFF=$(git diff origin/${{ github.base_ref }}...HEAD -- CHANGELOG.md)
45+
46+
# Extract added lines (lines starting with + [changes], but not +++ [metadata])
47+
ADDED_LINES=$(echo "$CHANGELOG_DIFF" | grep "^+" | grep -v "^+++" || true)
48+
49+
echo "Added lines in CHANGELOG.md:"
50+
echo "$ADDED_LINES"
51+
echo ""
52+
53+
# Count valid changelog entries
54+
VALID_ENTRIES=$(echo "$ADDED_LINES" | grep -E '^\+\* \[#[0-9]+\]\(https://github\.com/[^/]+/[^/]+/pull/[0-9]+\): .+ - \[@[^]]+\]\(https://github\.com/[^)]+\)\.' || true)
55+
VALID_COUNT=$([[ -n "$VALID_ENTRIES" ]] && echo "$VALID_ENTRIES" | grep -c "^\+" || echo 0)
56+
57+
# Check that exactly one valid entry was added
58+
if [ "$VALID_COUNT" -eq 0 ]; then
59+
echo "✗ No valid changelog entry found"
60+
echo ""
61+
echo "Expected format:"
62+
echo "* [#PR_NUMBER](https://github.com/OWNER/REPO/pull/PR_NUMBER): Description - [@username](https://github.com/username)."
63+
echo ""
64+
echo "Example:"
65+
echo "* [#123](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/123): Add changelog validation - [@username](https://github.com/username)."
66+
exit 1
67+
elif [ "$VALID_COUNT" -gt 1 ]; then
68+
echo "✗ Multiple changelog entries detected ($VALID_COUNT entries)"
69+
echo ""
70+
echo "Please add only ONE changelog entry per pull request."
71+
echo ""
72+
echo "Entries found:"
73+
echo "$VALID_ENTRIES" | sed 's/^+//'
74+
exit 1
75+
fi
76+
77+
# Count total added lines (including any blank lines or invalid entries)
78+
TOTAL_ADDED=$([[ -n "$ADDED_LINES" ]] && echo "$ADDED_LINES" | wc -l || echo 0)
79+
80+
# Check that only one line was added (no blank lines or other content)
81+
if [ "$TOTAL_ADDED" -ne 1 ]; then
82+
echo "✗ Detected $TOTAL_ADDED added lines, but only 1 line should be added"
83+
echo ""
84+
echo "Please add only ONE changelog entry with no blank lines or additional content."
85+
echo ""
86+
echo "All added lines:"
87+
echo "$ADDED_LINES"
88+
exit 1
89+
fi
90+
91+
echo "✓ Exactly one valid changelog entry found:"
92+
echo "$VALID_ENTRIES" | sed 's/^+//'

CHANGELOG.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### 4.0.1 (Next)
2+
* [#153](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/153): Validate CHANGELOG generation - [@acm19](https://github.com/acm19).
23
* [#151](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/151): Upgrade deprecated actions/create-release@v1 - [@dblock](https://github.com/dblock).
34
* [#150](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/150): Fix pom.xml indentation inconsistencies - [@dblock](https://github.com/dblock).
45
* [#149](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/149): Add Checkstyle indentation checks - [@dblock](https://github.com/dblock).
@@ -19,12 +20,10 @@
1920
* [#104](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/104): Make request interceptors simpler and other improvements - [@acm19](https://github.com/acm19).
2021

2122
### 2.3.0 (2023/01/26)
22-
2323
* [#94](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/94): Add support for OpenSearch Serverless - [@dblock](https://github.com/dblock).
2424
* [#92](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/92): Make samples compatible with OpenSearch 2.x - [@dblock](https://github.com/dblock).
2525

2626
### 2.2.0 (2022/10/02)
27-
2827
* [#80](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/80): Add support for Apache client v5 - [@acm19](https://github.com/acm19).
2928
* [#76](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/76): Automate release process - [@acm19](https://github.com/acm19).
3029
* [#75](https://github.com/acm19/aws-request-signing-apache-interceptor/issues/75): Add OpenSearch cluster infrastructure - [@acm19](https://github.com/acm19).
@@ -33,11 +32,9 @@
3332
* [#70](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/70): Add maven release info, usage and badge to README - [@dblock](https://github.com/dblock).
3433

3534
### 2.1.1 (2022/07/12)
36-
3735
* [#67](https://github.com/acm19/aws-request-signing-apache-interceptor/issues/67): Add fields required by Maven Central to de POM - [@acm19](https://github.com/acm19).
3836

3937
### 2.1.0 (2022/07/12)
40-
4138
* [#58](https://github.com/acm19/aws-request-signing-apache-interceptor/issues/58): Test and fix the release process - [@acm19](https://github.com/acm19).
4239
* [#59](https://github.com/acm19/aws-request-signing-apache-interceptor/pull/59): Document versioning standard - [@acm19](https://github.com/acm19).
4340
* [#44](https://github.com/acm19/aws-request-signing-apache-interceptor/issues/44): Release to Maven Central - [@dblock](https://github.com/dblock), [@acm19](https://github.com/acm19).
@@ -60,14 +57,11 @@
6057
* Re-add support for JDK8 - [@acm19](https://github.com/acm19).
6158

6259
### 2.0.2 (2020/12/27)
63-
6460
* Updated dependencies - [@renovate-bot](https://github.com/renovate-bot).
6561

6662
### 2.0.1 (2020/05/03)
67-
6863
* Make `httpClient` a `provided` dependency - [@acm19](https://github.com/acm19).
6964

7065
### 2.0.0 (2020/05/03)
71-
7266
* Added renovate - [@acm19](https://github.com/acm19).
7367
* Upgraded to AWS SDK 2.13.8 - [@acm19](https://github.com/acm19).

0 commit comments

Comments
 (0)