|
| 1 | +# Generates a list of changes and a commit message when the pinned gutenberg repository hash changes. |
| 2 | +name: Generate changelog and commit message |
| 3 | + |
| 4 | +on: |
| 5 | + # This workflow was introduced in WordPress 7.0. |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - trunk |
| 9 | + - '[7-9].[0-9]' |
| 10 | + paths: |
| 11 | + - 'package.json' |
| 12 | + |
| 13 | +# Cancels all previous workflow runs for pull requests that have not completed. |
| 14 | +concurrency: |
| 15 | + # The concurrency group contains the workflow name and the branch name for pull requests |
| 16 | + # or the commit hash for any other events. |
| 17 | + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +# Disable permissions for all available scopes by default. |
| 21 | +# Any needed permissions should be configured at the job level. |
| 22 | +permissions: {} |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Detects whether the gutenberg.sha value in the package.json file has changed. |
| 26 | + # |
| 27 | + # Performs the following steps: |
| 28 | + # - Checks out the repository. |
| 29 | + # - Check if the pinned hash has changed. |
| 30 | + detect-hash-change: |
| 31 | + name: Detect Gutenberg SHA change |
| 32 | + runs-on: ubuntu-24.04 |
| 33 | + if: ${{ github.repository == 'wordpress/wordpress-develop' }} |
| 34 | + permissions: |
| 35 | + contents: read |
| 36 | + outputs: |
| 37 | + sha_changed: ${{ steps.check-sha.outputs.sha_changed }} |
| 38 | + base_sha: ${{ steps.check-sha.outputs.base_sha }} |
| 39 | + head_sha: ${{ steps.check-sha.outputs.head_sha }} |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout repository |
| 43 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
| 46 | + persist-credentials: false |
| 47 | + |
| 48 | + - name: Check if the pinned Gutenberg hash has changed |
| 49 | + id: check-sha |
| 50 | + run: | |
| 51 | + BASE_GUTENBERG_SHA=$(git show ${{ github.event.pull_request.base.sha }}:package.json | jq -r '.gutenberg.sha // empty') |
| 52 | + HEAD_GUTENBERG_SHA=$(git show ${{ github.event.pull_request.head.sha }}:package.json | jq -r '.gutenberg.sha // empty') |
| 53 | +
|
| 54 | + echo "base_sha=$BASE_GUTENBERG_SHA" >> "$GITHUB_OUTPUT" |
| 55 | + echo "head_sha=$HEAD_GUTENBERG_SHA" >> "$GITHUB_OUTPUT" |
| 56 | +
|
| 57 | + if [ "$BASE_GUTENBERG_SHA" != "$HEAD_GUTENBERG_SHA" ]; then |
| 58 | + echo "sha_changed=true" >> "$GITHUB_OUTPUT" |
| 59 | + echo "The pinned Gutenberg Repository hash has changed." |
| 60 | + echo " Previous SHA (base branch): $BASE_GUTENBERG_SHA" |
| 61 | + echo " New SHA (head branch): $HEAD_GUTENBERG_SHA" |
| 62 | + else |
| 63 | + echo "sha_changed=false" >> "$GITHUB_OUTPUT" |
| 64 | + echo "The pinned Gutenberg repository hash has not changed: $HEAD_GUTENBERG_SHA" |
| 65 | + fi |
| 66 | +
|
| 67 | + # Generates a list of changes between two specified hashes. |
| 68 | + # |
| 69 | + # Performs the following steps: |
| 70 | + # - Checks out the repository. |
| 71 | + # - Generates a list of changes. |
| 72 | + # - Uploads the changelog as an artifact. |
| 73 | + generate-changelog: |
| 74 | + name: Generate a list of changes between the hashes |
| 75 | + runs-on: ubuntu-24.04 |
| 76 | + needs: [ 'detect-hash-change' ] |
| 77 | + if: ${{ needs.detect-hash-change.outputs.sha_changed == 'true' }} |
| 78 | + permissions: |
| 79 | + contents: read |
| 80 | + outputs: |
| 81 | + has_changes: ${{ steps.change-list.outputs.has_changes }} |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Checkout Gutenberg repository |
| 85 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 86 | + with: |
| 87 | + repository: WordPress/gutenberg |
| 88 | + filter: blob:none |
| 89 | + fetch-depth: 0 |
| 90 | + |
| 91 | + - name: Generate a list of changes |
| 92 | + id: change-list |
| 93 | + env: |
| 94 | + BASE_SHA: ${{ needs.detect-hash-change.outputs.base_sha }} |
| 95 | + HEAD_SHA: ${{ needs.detect-hash-change.outputs.head_sha }} |
| 96 | + run: | |
| 97 | + git log --reverse --format="- %s" "$BASE_SHA".."$HEAD_SHA" | \ |
| 98 | + sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' \ |
| 99 | + > changelog.txt |
| 100 | +
|
| 101 | + if [ -s changelog.txt ]; then |
| 102 | + echo "has_changes=true" >> "$GITHUB_OUTPUT" |
| 103 | + else |
| 104 | + echo "has_changes=false" >> "$GITHUB_OUTPUT" |
| 105 | + fi |
| 106 | +
|
| 107 | + - name: Upload changelog as an artifact |
| 108 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 109 | + with: |
| 110 | + path: changelog.txt |
| 111 | + archive: false |
| 112 | + |
| 113 | + # Drafts a commit message containing a detailed list of changes being merged. |
| 114 | + # |
| 115 | + # Performs the following steps: |
| 116 | + # - Downloads the changelog artifact. |
| 117 | + # - Builds a commit message. |
| 118 | + # - Uploads the commit message as an artifact. |
| 119 | + generate-commit-message: |
| 120 | + name: Generate commit message |
| 121 | + runs-on: ubuntu-24.04 |
| 122 | + needs: [ 'detect-hash-change', 'generate-changelog' ] |
| 123 | + if: ${{ needs.detect-hash-change.outputs.sha_changed == 'true' }} |
| 124 | + permissions: |
| 125 | + contents: read |
| 126 | + |
| 127 | + steps: |
| 128 | + - name: Download changelog artifact |
| 129 | + if: ${{ needs.generate-changelog.outputs.has_changes == 'true' }} |
| 130 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 131 | + with: |
| 132 | + name: changelog.txt |
| 133 | + skip-decompress: true |
| 134 | + |
| 135 | + - name: Build commit message |
| 136 | + env: |
| 137 | + BASE_SHA: ${{ needs.detect-hash-change.outputs.base_sha }} |
| 138 | + HEAD_SHA: ${{ needs.detect-hash-change.outputs.head_sha }} |
| 139 | + HAS_CHANGES: ${{ needs.generate-changelog.outputs.has_changes }} |
| 140 | + run: | |
| 141 | + { |
| 142 | + printf 'Editor: Bump pinned hash for the Gutenberg repository.\n\n' |
| 143 | + printf "This updates the pinned hash from the gutenberg from \`%s\` to \`%s\`.\n\n" "$BASE_SHA" "$HEAD_SHA" |
| 144 | +
|
| 145 | + if [ "$HAS_CHANGES" = "false" ]; then |
| 146 | + printf '> [!WARNING]\n' |
| 147 | + printf '> No pull request references were found in the commits between the two hashes. Please verify the hash range is correct.\n\n' |
| 148 | + else |
| 149 | + printf 'The following changes are included:\n\n' |
| 150 | + cat changes.txt |
| 151 | + printf '\n\n' |
| 152 | + fi |
| 153 | +
|
| 154 | + printf 'A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/%s...%s.\n\n' "$BASE_SHA" "$HEAD_SHA" |
| 155 | + printf 'See #64595, #64393.\n' |
| 156 | + } > commit-message.md |
| 157 | +
|
| 158 | + - name: Upload commit message as an artifact |
| 159 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 160 | + with: |
| 161 | + path: commit-message.md |
| 162 | + archive: false |
| 163 | + |
| 164 | + - name: Post PR comment |
| 165 | + env: |
| 166 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 167 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 168 | + REPO: ${{ github.repository }} |
| 169 | + run: | |
| 170 | + gh pr comment "$PR_NUMBER" --body-file commit-message.md --repo "$REPO" |
0 commit comments