stefanvodita commented on code in PR #14279: URL: https://github.com/apache/lucene/pull/14279#discussion_r1966913749
########## .github/workflows/verify-changelog-and-set-milestone.yml: ########## @@ -0,0 +1,100 @@ +name: "Change Log Entry Verifier and Milestone Setter" +run-name: Change log entry verifier and milestone setter +on: + - pull_request_target + +env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE: ${{ github.event.issue.html_url }} + ESCAPE_HATCH: ${{ '__NA__' }} + CHANGE_LOG_FILE: ${{ 'lucene/CHANGES.txt' }} + +jobs: + changelog-verifier-and-milestone-setter: + name: Verify Change Log Entry and Set Milestone + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: ChangeLog Entry Verifier and Milestone Setter + run: | + echo "################## STEP 1 ##################" + echo "Checking for escape hatch in the top comment" + pr_comment=$(gh pr view ${{ github.event.number }} --json body -q '.body') + if echo "$pr_comment" | grep -q ${{ env.ESCAPE_HATCH }}; then + echo "Skipping checks as escape hatch: ${ESCAPE_HATCH} is found in the top comment." + exit 0 + else + echo "No escape hatch found in the top comment. Proceeding with next steps." + fi + + + echo -e "\n" + echo "################## STEP 2 ##################" + echo "Checking for change log entry in ${{ env.CHANGE_LOG_FILE }}" + git log --pretty=oneline | tail -n 2 | cat + echo "merge base sha: ${{ github.event.pull_request.base.sha }}, merge head sha: ${{ github.event.pull_request.head.sha }}" + if ! git diff ${{ github.event.pull_request.base.sha }} --name-only | grep -q "${{ env.CHANGE_LOG_FILE }}"; then + echo "Change log file:${{ env.CHANGE_LOG_FILE }} does not contains an entry corresponding to changes introduced in PR. Please add a changelog entry." Review Comment: It's for this to be in the log now, but could we make it a PR comment eventually? ########## .github/workflows/verify-changelog-and-set-milestone.yml: ########## @@ -0,0 +1,100 @@ +name: "Change Log Entry Verifier and Milestone Setter" +run-name: Change log entry verifier and milestone setter +on: + - pull_request_target + +env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE: ${{ github.event.issue.html_url }} + ESCAPE_HATCH: ${{ '__NA__' }} + CHANGE_LOG_FILE: ${{ 'lucene/CHANGES.txt' }} + +jobs: + changelog-verifier-and-milestone-setter: + name: Verify Change Log Entry and Set Milestone + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: ChangeLog Entry Verifier and Milestone Setter + run: | + echo "################## STEP 1 ##################" + echo "Checking for escape hatch in the top comment" + pr_comment=$(gh pr view ${{ github.event.number }} --json body -q '.body') + if echo "$pr_comment" | grep -q ${{ env.ESCAPE_HATCH }}; then + echo "Skipping checks as escape hatch: ${ESCAPE_HATCH} is found in the top comment." + exit 0 + else + echo "No escape hatch found in the top comment. Proceeding with next steps." + fi + + + echo -e "\n" + echo "################## STEP 2 ##################" + echo "Checking for change log entry in ${{ env.CHANGE_LOG_FILE }}" + git log --pretty=oneline | tail -n 2 | cat + echo "merge base sha: ${{ github.event.pull_request.base.sha }}, merge head sha: ${{ github.event.pull_request.head.sha }}" + if ! git diff ${{ github.event.pull_request.base.sha }} --name-only | grep -q "${{ env.CHANGE_LOG_FILE }}"; then + echo "Change log file:${{ env.CHANGE_LOG_FILE }} does not contains an entry corresponding to changes introduced in PR. Please add a changelog entry." + exit 0 + else + echo "${{ env.CHANGE_LOG_FILE }} contains change log entry. Proceeding with next steps." + fi + + + echo -e "\n" + echo "################## STEP 3 ##################" + echo "Extracting Lucene version from change log entry" + # git diff header pattern -> "@@ -15,0 +16,4 @@" + # try to extract the line number at which new entry is added, here it's line number 16 + diff=$(git diff ${{ github.event.pull_request.base.sha }} --unified=0 -- ${{ env.CHANGE_LOG_FILE }}) + lucene_version="" + diff_header_pattern="@@ -[0-9]+,?[0-9]* \+([0-9]*),?[0-9]* @@" + if [[ $diff =~ $diff_header_pattern ]]; then + echo "Match found: ${BASH_REMATCH[0]}" + new_entry_line_number=$((BASH_REMATCH[1])) + echo "Found introduced change log entry at line number:${new_entry_line_number}" + lucene_version_regex="=+ ?Lucene ?([0-9.]*) ?=+" + current_line_number=0 + while IFS="" read -r line; do + current_line_number=$((current_line_number+1)) + if [[ $line =~ $lucene_version_regex ]]; then + lucene_version="${BASH_REMATCH[1]}" + fi + if [[ $current_line_number -ge $new_entry_line_number ]]; then + echo "Reached the line number at which new entry is added in ${{ env.CHANGE_LOG_FILE }}" + break + fi + done < ${{ env.CHANGE_LOG_FILE }} + if [[ -z $lucene_version ]]; then + echo "Could not find Lucene version in the change log entry. Please add the Lucene version in the change log entry." + exit 0 + fi + echo "Found corresponding Lucene version: ${lucene_version} based on change log entry. Proceeding with next steps." + else + echo "Could not find the line number at which new entry is added in ${{ env.CHANGE_LOG_FILE }}" + exit 0 + fi + + + echo -e "\n" + echo "################## STEP 4 ##################" + echo "Adding/Updating milestone for the PR" + mapfile -t milestones < <(gh repo view --json milestones -q '.milestones[].title') + IFS=','; echo "${milestones[*]}" + milestone_exists=false + for milestone in "${milestones[@]}"; do + if [[ $milestone == "$lucene_version" ]]; then + milestone_exists=true + break + fi + done + if [[ $milestone_exists == false ]]; then + echo "Milestone:${lucene_version} does not exist. Please create the milestone and run the workflow again." + exit 0 + fi + gh pr edit ${{ github.event.number }} --milestone "${lucene_version}" Review Comment: If I understand correctly, this is the only place where we're changing the PR and not just writing logs. I think I'd like to merge with this line commented out first, see how it runs, and then come back here and uncomment the line. Does that make sense? ########## .github/workflows/verify-changelog-and-set-milestone.yml: ########## @@ -0,0 +1,100 @@ +name: "Change Log Entry Verifier and Milestone Setter" +run-name: Change log entry verifier and milestone setter +on: + - pull_request_target + +env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE: ${{ github.event.issue.html_url }} + ESCAPE_HATCH: ${{ '__NA__' }} + CHANGE_LOG_FILE: ${{ 'lucene/CHANGES.txt' }} + +jobs: + changelog-verifier-and-milestone-setter: + name: Verify Change Log Entry and Set Milestone + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: ChangeLog Entry Verifier and Milestone Setter + run: | + echo "################## STEP 1 ##################" + echo "Checking for escape hatch in the top comment" Review Comment: This runs when a PR is updated. Would it make more sense to check the description? Better yet, have a tag we add to skip this workflow? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org