From dc5fad843c481267dcf6f5ab952cccf386408397 Mon Sep 17 00:00:00 2001 From: ankitkhushwaha <124484362+ankitkhushwaha@users.noreply.github.com> Date: Thu, 13 Feb 2025 14:36:03 +0530 Subject: [PATCH] Update Workflow from Package-template --- .github/workflows/workflow-update.yml | 105 ++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 .github/workflows/workflow-update.yml diff --git a/.github/workflows/workflow-update.yml b/.github/workflows/workflow-update.yml new file mode 100644 index 0000000..8622b3a --- /dev/null +++ b/.github/workflows/workflow-update.yml @@ -0,0 +1,105 @@ + +# This template is taken from the cruft example code, for further information please see: +# https://cruft.github.io/cruft/#automating-updates-with-github-actions +name: Automatic Workflow Update from package template +permissions: + contents: write + pull-requests: write + +on: + # Allow manual runs through the web UI + workflow_dispatch: + schedule: + # ┌───────── minute (0 - 59) + # │ ┌───────── hour (0 - 23) + # │ │ ┌───────── day of the month (1 - 31) + # │ │ │ ┌───────── month (1 - 12 or JAN-DEC) + # │ │ │ │ ┌───────── day of the week (0 - 6 or SUN-SAT) + - cron: '0 7 * * 1' # Every Monday at 7am UTC + +jobs: + update: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + repo: ["sunpy", "ndcube"] + # , "sunkit-magex", "streamtracer", "sunkit-dem", + # "mpl-animators", "sunkit-image", "sunkit-pyvista", "sunpy-soar", + # "sunkit-instruments", "drms", "sunraster", "sunkit-spex", "radiospectra"] + steps: + - name: Checkout Target Repository + uses: actions/checkout@v4 + with: + repository: "ankitkhushwaha/${{ matrix.repo }}" + token: ${{ secrets.GH_PAT }} + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install Cruft + run: python -m pip install git+https://github.com/Cadair/cruft@patch-p1 + + - name: Check if update is available + continue-on-error: false + id: check + run: | + CHANGES=0 + if [ -f .cruft.json ]; then + if ! cruft check; then + CHANGES=1 + fi + else + echo "No .cruft.json file" + fi + + echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT" + + - name: Run update if available + id: cruft_update + if: steps.check.outputs.has_changes == '1' + run: | + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + git config --global user.name "${{ github.actor }}" + + cruft_output=$(cruft update --skip '**' --skip '!.github/workflows/**' --skip-apply-ask --refresh-private-variables) + echo $cruft_output + git restore --staged . + + if [[ "$cruft_output" == *"Failed to cleanly apply the update, there may be merge conflicts."* ]]; then + echo merge_conflicts=1 >> $GITHUB_OUTPUT + else + echo merge_conflicts=0 >> $GITHUB_OUTPUT + fi + + - name: Check if only .cruft.json is modified + id: cruft_json + if: steps.check.outputs.has_changes == '1' + run: | + git status --porcelain=1 + if [[ "$(git status --porcelain=1)" == " M .cruft.json" ]]; then + echo "Only .cruft.json is modified. Exiting workflow early." + echo "has_changes=0" >> "$GITHUB_OUTPUT" + else + echo "has_changes=1" >> "$GITHUB_OUTPUT" + fi + + - name: Create pull request + if: steps.cruft_json.outputs.has_changes == '1' + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ secrets.GH_PAT }} + add-paths: "." + commit-message: "Automatic package template update" + branch: "cruft/update" + delete-branch: true + draft: ${{ steps.cruft_update.outputs.merge_conflicts == '1' }} + title: "Updates from the package template" + labels: | + No Changelog Entry Needed + body: | + This is an autogenerated PR, which will 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.**