From 75c706aca9856daf3148521e7237eb8c92c39b2e Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Thu, 20 Aug 2026 09:42:09 +0100 Subject: [PATCH] Add the template commit log to the PR description --- .../workflows/centralised_cruft_updater.yml | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/.github/workflows/centralised_cruft_updater.yml b/.github/workflows/centralised_cruft_updater.yml index 0c0e703..7ccc882 100644 --- a/.github/workflows/centralised_cruft_updater.yml +++ b/.github/workflows/centralised_cruft_updater.yml @@ -73,6 +73,10 @@ jobs: REPO_FULL: ${{ matrix.repo }} BOT: "SunPyBot" BRANCH: "cruft/update" + PR_BODY: | + This is an autogenerated PR, which applies the latest changes from the [SunPy Package Template](https://github.com/sunpy/package-template). + + If this pull request has been opened as a draft there are conflicts which need fixing. steps: - name: Set safe repo name @@ -142,6 +146,8 @@ jobs: env: EXTRA_CONTEXT: ${{ inputs.extra_context }} run: | + OLD_COMMIT=$(jq -r '.commit // empty' .cruft.json 2>/dev/null || echo "") + EXTRA_ARGS=() if [ -n "$EXTRA_CONTEXT" ]; then EXTRA_ARGS=(--variables-to-update "$EXTRA_CONTEXT") @@ -155,6 +161,10 @@ jobs: echo "merge_conflicts=0" >> "$GITHUB_OUTPUT" fi + NEW_COMMIT=$(jq -r '.commit // empty' .cruft.json 2>/dev/null || echo "") + echo "old_commit=${OLD_COMMIT}" >> "$GITHUB_OUTPUT" + echo "new_commit=${NEW_COMMIT}" >> "$GITHUB_OUTPUT" + - name: Check if only .cruft.json is modified id: cruft_json run: | @@ -179,6 +189,32 @@ jobs: fi echo "merge_conflicts=$MERGE_CONFLICTS" >> "$GITHUB_OUTPUT" + - name: Generate commit log + id: commit_log + if: steps.cruft_json.outputs.has_changes == '1' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OLD_COMMIT: ${{ steps.cruft_update.outputs.old_commit }} + NEW_COMMIT: ${{ steps.cruft_update.outputs.new_commit }} + run: | + COMMIT_LOG="" + if [ -n "$OLD_COMMIT" ] && [ -n "$NEW_COMMIT" ] && [ "$OLD_COMMIT" != "$NEW_COMMIT" ]; then + COMMIT_LOG=$(gh api "repos/${{ github.repository }}/compare/${OLD_COMMIT}...${NEW_COMMIT}" \ + --jq '.commits[] | "- [" + .sha[0:7] + "](" + .html_url + ") " + (.commit.message | split("\n")[0])' 2>/dev/null || echo "") + fi + + { + echo "$PR_BODY" + if [ -n "$COMMIT_LOG" ]; then + echo "" + echo "## Changes from the template" + echo "" + echo "$COMMIT_LOG" + fi + } > pr_body.md + + echo "path=$(pwd)/pr_body.md" >> "$GITHUB_OUTPUT" + # There is already an open PR, so its branch just needs a new commit. # create-pull-request is not used here because it resets the # branch to the base, which would discard any manual conflict fixes. @@ -199,6 +235,15 @@ jobs: git commit -m "Run cruft update from package template" git push "https://${BOT}:${BOT_FORK_PAT}@github.com/${FORK_REPO}.git" "HEAD:${BRANCH}" + - name: Update existing PR description + if: steps.cruft_json.outputs.has_changes == '1' && steps.existing.outputs.existing_pr != '0' + env: + GH_TOKEN: ${{ secrets.BOT_PR_PAT }} + PR_NUMBER: ${{ steps.existing.outputs.existing_pr }} + BODY_PATH: ${{ steps.commit_log.outputs.path }} + run: | + gh pr edit "$PR_NUMBER" --repo "$REPO_FULL" --body-file "$BODY_PATH" + # No open PR, so build the branch on the fork from scratch and open one. # maintainer-can-modify must be false as BOT_PR_PAT has no write access to # the fork; the allow-edits job turns it on afterwards. @@ -218,12 +263,7 @@ jobs: branch: ${{ env.BRANCH }} delete-branch: true title: 'Updates from the package template' - body: | - This is an autogenerated PR, which applies the latest changes from the [SunPy Package Template](https://github.com/sunpy/package-template). - - If this pull request has been opened as a draft there are conflicts which need fixing. - - **To run the CI on this pull request you will need to close it and reopen it.** + body-path: ${{ steps.commit_log.outputs.path }} draft: ${{ steps.conflicts.outputs.merge_conflicts == '1' }} - name: Prepare status for collation