-
Couldn't load subscription status.
- Fork 2.7k
ci: add script to check PRs against CHANGELOG.md for completeness #12309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| name: Check Changelog | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - 'CHANGELOG.md' | ||
| pull_request: | ||
| paths: | ||
| - 'CHANGELOG.md' | ||
|
|
||
| jobs: | ||
| check-changelog: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Run check_changelog_prs script | ||
| run: | | ||
| bash ci/check_changelog_prs.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Function to compare versions | ||
| version_gt() { | ||
| local v1=$1 | ||
| local v2=$2 | ||
| # Remove 'v' prefix if present | ||
| v1=${v1#v} | ||
| v2=${v2#v} | ||
| # Compare versions using sort -V | ||
| [ "$(printf '%s\n' "$v1" "$v2" | sort -V | head -n1)" != "$v1" ] | ||
| } | ||
|
|
||
| # Function to get git reference (tag or HEAD) | ||
| get_git_ref() { | ||
| local version=$1 | ||
| if git rev-parse "$version" >/dev/null 2>&1; then | ||
| echo "$version" | ||
| else | ||
| echo "HEAD" | ||
| fi | ||
| } | ||
|
|
||
| # Configure PR types to ignore | ||
| IGNORE_TYPES=( | ||
| "docs" | ||
| "chore" | ||
| "test" | ||
| "ci" | ||
| ) | ||
|
|
||
| # Configure PR numbers to ignore | ||
| IGNORE_PRS=( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refer: #12308 (comment) |
||
| # 3.9.0 | ||
| 10655 10857 10858 10887 10959 11029 11041 11053 11055 11061 10976 10984 11025 | ||
| # 3.10.0 | ||
| 11105 11128 11169 11171 11280 11333 11081 11202 11469 | ||
| # 3.11.0 | ||
| 11463 11570 | ||
| # 3.12.0 | ||
| 11769 11816 11881 11905 11924 11926 11973 11991 11992 11829 | ||
| ) | ||
|
|
||
| # Build ignore pattern to match the following formats: | ||
| # - Direct keyword prefix (e.g., "docs:") | ||
| ignore_pattern=$(IFS="|"; echo "(${IGNORE_TYPES[*]}):|(${IGNORE_TYPES[*]})\([^)]*\):") | ||
|
|
||
| # Get all versions from CHANGELOG.md | ||
| mapfile -t versions < <(grep -E '^## [0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md | sed 's/^## //') | ||
|
|
||
| # Initialize error flag | ||
| has_errors=0 | ||
|
|
||
| # Process each pair of consecutive versions | ||
| for ((i=0; i<${#versions[@]}-1; i++)); do | ||
| new_tag=${versions[i]} | ||
| old_tag=${versions[i+1]} | ||
|
|
||
| # Skip if new_tag is less than or equal to 3.8.0 | ||
| if ! version_gt "$new_tag" "3.8.0"; then | ||
| continue | ||
| fi | ||
|
|
||
| # Get git references | ||
| new_ref=$(get_git_ref "$new_tag") | ||
| old_ref=$(get_git_ref "$old_tag") | ||
|
|
||
| echo -e "\n=== Checking changes between $new_tag ($new_ref) and $old_tag ($old_ref) ===" | ||
|
|
||
| # Extract PRs between two versions from CHANGELOG.md | ||
| echo "Extracting PRs from CHANGELOG.md..." | ||
| changelog_prs=$(awk -v start="$new_tag" -v end="$old_tag" ' | ||
| BEGIN { flag = 0 } | ||
| $0 ~ "^## " { | ||
| if ($0 ~ start) { flag = 1; next } | ||
| if (flag && $0 ~ end) { flag = 0 } | ||
| } | ||
| flag { print } | ||
| ' CHANGELOG.md | grep -oE '#[0-9]+' | sort -n) | ||
|
|
||
| # Extract actual PRs from git log, filtering out configured types and specified PR numbers | ||
| echo "Extracting actual PRs from git log (excluding: ${IGNORE_TYPES[*]} and PRs: ${IGNORE_PRS[*]})..." | ||
| git_prs=$(git log "$old_ref..$new_ref" --oneline | grep -vE "$ignore_pattern" | grep -oE '#[0-9]+' | sort -n) | ||
|
|
||
| # Filter out specified PR numbers | ||
| for pr in "${IGNORE_PRS[@]}"; do | ||
| git_prs=$(echo "$git_prs" | grep -v "#$pr") | ||
| done | ||
|
|
||
| # Compare the two lists | ||
| echo "Comparing PRs..." | ||
| missing_prs=$(comm -23 <(echo "$git_prs") <(echo "$changelog_prs")) | ||
|
|
||
| # Print comparison results | ||
| echo -e "\n=== PR Comparison Results for $new_tag ===" | ||
|
|
||
| if [ -z "$missing_prs" ]; then | ||
| echo -e "\n✅ All PRs are included in CHANGELOG.md for version $new_tag" | ||
| else | ||
| echo -e "\n❌ [ERROR] Missing PRs in CHANGELOG.md for version $new_tag (sorted):" | ||
| printf ' %s\n' "$missing_prs" | ||
|
|
||
| # Get detailed information for each missing PR | ||
| echo -e "\nDetailed information about missing PRs for version $new_tag:" | ||
| for pr in $missing_prs; do | ||
| pr_num=${pr#\#} # Remove # symbol | ||
| echo -e "\nPR $pr :" | ||
| # Get PR commit information | ||
| git log "$old_ref..$new_ref" --oneline | grep "$pr" | while read -r line; do | ||
| echo " - $line" | ||
| done | ||
| # Try to get PR title (if possible) | ||
| echo " - PR URL: https://github.com/apache/apisix/pull/$pr_num" | ||
| done | ||
| echo "Note: If you confirm that a PR should not appear in the changelog, please add its number to the IGNORE_PRS array in this script." | ||
| has_errors=1 | ||
| fi | ||
| done | ||
|
|
||
| # Exit with error if any version had missing PRs | ||
| if [ $has_errors -eq 1 ]; then | ||
| exit 1 | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a TypeScript script instead of bash. This is not at all easy to review and maintain.
This has nothing to do with the APISIX runtime and does not have any negative performance impact, so it should definitely be developed in the most efficient language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t quite agree. From a project maintenance perspective, I believe we should minimize the number of languages used. If you prefer TypeScript and find it more efficient, then by the same logic, others might argue for using Python if they find it more efficient—should we adopt Python too?
Although I’ve written TypeScript for a long time, I still chose Bash for this script because, regardless of the language used, the core task involves extracting PR numbers via git commands and regex parsing of the changelog. The difference in implementation efficiency isn’t significant. Using TypeScript would also require setting up a Node.js environment, which might be unfamiliar to some contributors, and won’t necessarily result in a noticeable efficiency gain.
Regarding review and maintenance: I’ve added detailed comments in the script. The shell code mainly consists of commonly used commands. With the help of AI tools, I don’t think it’s particularly hard to understand or maintain.
Waiting for others options. @nic-6443 @AlinsRan @membphis @moonming
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one must look at it from a maintenance point of view, there are more problems with this script.
Why are logic and data coupled in a single script file? This forces every developer who wishes to add a special case to understand the script. Why not use a separate JSON file to store these exceptions?
Reducing the number of languages is not the goal, but rather using the right languages in the right places, languages that really have a wide range of users and can be used easily.
Another fact is that TypeScript has already been adopted by the project and was first applied to the testing part.
From some of the feedback I've heard, it's more popular than test-nginx.
Python has not achieved this status.
First of all, I admit that the choice of TypeScript is my personal preference. But so what?
There is no doubt that the JavaScript/TypeScript runtime based on v8 or any other JIT-enabled compiler is faster than Python.
CPython has no production-ready built-in JIT implementation to date, and PyPy is not widely used.
I don't see how these two can gain superiority over each other in terms of development efficiency. But, in any case, they are both better than the shell.
This is the point of using a “modern” tool, where we can express clearer logic with less code. And we will have countless libraries to use to reduce our own workload.
Compactness is now less of an advantage and more of a disadvantage, which brings low readability.
This proves once again the significance of splitting logic and data. Unless we need to deal with a new situation, it's straightforward for a developer to add a CHANGELOG special case by simply updating a copy of the JSON/YAML configuration.
The CI should definitely give developers a clear indication that you need to add a CHANGELOG or how to add a special case on demand.
Now the developer will have to edit your script documentation, which can introduce bugs in an improper review.
I do not agree. I'm not a git expert, and if I didn't consult the documentation, I probably wouldn't be able to say what each of the git commands included in the script you generated with the help of AI does and what the arguments in it represent.
When we implement it semantically, it will be simpler.
https://github.com/apache/apisix-website/blob/master/scripts/sync-docs.js#L41-L53
https://www.npmjs.com/package/simple-git
On top of that, you're using awk to work with strings. Can you guarantee to understand and reproduce this without the help of AI? How long would it take you to figure out all these git and awk commands?
With all due respect, this is hardly readable.
If a piece of code is important enough to require manual review, then I don't trust any snippet generated directly by AI. They don't even solve the problem of removing the illusion.
Can the author fully understand what it's generating? Do those comment feet really clearly explain every command used?
For example, that awk command: https://github.com/apache/apisix/pull/12309/files#diff-67d26cf11e0379ef7aa36cf327b9154b737a0e4dd38905b74c8bec9cb6c31789R90-R97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Developers can leverage AI with various tools, but we must fully understand the code generated by the AI and not be "controlled" by it.
From a project maintenance perspective, code that is easier to understand significantly improves maintenance, even if the language has not been used before. Currently, it is hard to understand what this parts (https://github.com/apache/apisix/pull/12309/files#diff-67d26cf11e0379ef7aa36cf327b9154b737a0e4dd38905b74c8bec9cb6c31789R90-R97).
Regarding the need to configure the environment for CI work, this is not difficult to address and maintain. Using the right tool in right place is right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, since you all think TypeScript is more appropriate, I’ll try to submit a new PR using TypeScript when I have time. But I still stand by my opinion: using a Bash script is more concise, though it sacrifices some readability.
Also, if I didn’t understand the code, I wouldn’t submit a PR for review — that’s being responsible to the community reviewer and to myself.
Anyway, thanks for the review. I will submit a new PR to complete it using TypeScript.