|
| 1 | +# Generated file. DO NOT EDIT. |
| 2 | +name: Check for NEXT_CHANGELOG.md Changes |
| 3 | + |
| 4 | +on: |
| 5 | + # Use pull_request_target to have access to GitHub API |
| 6 | + pull_request_target: |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-next-changelog: |
| 10 | + runs-on: |
| 11 | + group: databricks-deco-testing-runner-group |
| 12 | + labels: ubuntu-latest-deco |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v3 |
| 17 | + |
| 18 | + - name: Fetch list of changed files |
| 19 | + id: changed-files |
| 20 | + env: |
| 21 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + run: | |
| 23 | + # Use the GitHub API to fetch changed files |
| 24 | + files=$(gh pr view ${{ github.event.pull_request.number }} --json files -q '.files[].path') |
| 25 | + |
| 26 | + # Sanitize to avoid code injection |
| 27 | + sanitized_files=$(echo "$files" | sed 's/[^a-zA-Z0-9._/-]/_/g') |
| 28 | + |
| 29 | + # Store the sanitized list of files in a temporary file to avoid env variable issues |
| 30 | + echo "$sanitized_files" > modified_files.txt |
| 31 | +
|
| 32 | + - name: Fetch PR message |
| 33 | + id: pr-message |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + run: | |
| 37 | + # Use the GitHub API to fetch the PR message |
| 38 | + pr_message=$(gh pr view ${{ github.event.pull_request.number }} --json body -q '.body') |
| 39 | + |
| 40 | + # Sanitize the PR message to avoid code injection, keeping the equal sign |
| 41 | + sanitized_pr_message=$(echo "$pr_message" | sed 's/[^a-zA-Z0-9._/-=]/_/g') |
| 42 | + |
| 43 | + # Store the sanitized PR message |
| 44 | + echo "$sanitized_pr_message" > pr_message.txt |
| 45 | +
|
| 46 | + - name: Verify NEXT_CHANGELOG.md was modified or PR message contains NO_CHANGELOG=true |
| 47 | + run: | |
| 48 | + # Read the sanitized files and PR message from the temporary files |
| 49 | + modified_files=$(cat modified_files.txt) |
| 50 | + pr_message=$(cat pr_message.txt) |
| 51 | + |
| 52 | + # Check if NEXT_CHANGELOG.md exists in the list of changed files |
| 53 | + echo "Changed files: $modified_files" |
| 54 | + if ! echo "$modified_files" | grep -q "NEXT_CHANGELOG.md"; then |
| 55 | + echo "NEXT_CHANGELOG.md not modified." |
| 56 | + |
| 57 | + # Check if PR message contains NO_CHANGELOG=true |
| 58 | + if echo "$pr_message" | grep -q "NO_CHANGELOG=true"; then |
| 59 | + echo "NO_CHANGELOG=true found in PR message. Skipping changelog check." |
| 60 | + exit 0 |
| 61 | + else |
| 62 | + echo "WARNING: file NEXT_CHANGELOG.md not changed. If this is expected, add NO_CHANGELOG=true to the PR message." |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Comment on PR with instructions if needed |
| 68 | + if: failure() # This step will only run if the previous step fails (i.e., if NEXT_CHANGELOG.md was not modified and NO_CHANGELOG=true was not in the PR message) |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + run: | |
| 72 | + # Check if a comment exists with the instructions |
| 73 | + previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ |
| 74 | + --jq '.[] | select(.body | startswith("<!-- NEXT_CHANGELOG_INSTRUCTIONS -->")) | .id') |
| 75 | + echo "Previous comment IDs: $previous_comment_ids" |
| 76 | +
|
| 77 | + # If no previous comment exists, add one with instructions |
| 78 | + if [ -z "$previous_comment_ids" ]; then |
| 79 | + echo "Adding instructions comment." |
| 80 | + gh pr comment ${{ github.event.pull_request.number }} --body \ |
| 81 | + "<!-- NEXT_CHANGELOG_INSTRUCTIONS --> |
| 82 | + Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes. |
| 83 | + If this is not necessary for your PR, please include the following in your PR description: |
| 84 | + NO_CHANGELOG=true |
| 85 | + and rerun the job." |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Delete instructions comment on success |
| 89 | + if: success() # This step will only run if the previous check passed (i.e., if NEXT_CHANGELOG.md was modified or NO_CHANGELOG=true is in the PR message) |
| 90 | + env: |
| 91 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + run: | |
| 93 | + # Check if there is a previous instructions comment |
| 94 | + previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ |
| 95 | + --jq '.[] | select(.body | startswith("<!-- NEXT_CHANGELOG_INSTRUCTIONS -->")) | .id') |
| 96 | + |
| 97 | + # If a comment exists, delete it |
| 98 | + if [ -n "$previous_comment_ids" ]; then |
| 99 | + echo "Deleting previous instructions comment." |
| 100 | + for comment_id in $previous_comment_ids; do |
| 101 | + gh api "repos/${{ github.repository }}/issues/comments/$comment_id" --method DELETE |
| 102 | + done |
| 103 | + else |
| 104 | + echo "No instructions comment found to delete." |
| 105 | + fi |
0 commit comments