Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions .github/workflows/centralised_cruft_updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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: |
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down