From 654a3799068de355e220e9721e08bb668d04f271 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Wed, 7 Jan 2026 14:13:52 +0000 Subject: [PATCH 1/2] Add a step which opens an issue when the update workflow fails fixes #231 --- .../.github/workflows/sub_package_update.yml | 73 ++++++++++++++++++- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml b/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml index 60649ec..78c5827 100644 --- a/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml +++ b/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml @@ -1,9 +1,6 @@ # 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 Update from package template -permissions: - contents: write - pull-requests: write on: # Allow manual runs through the web UI @@ -19,6 +16,9 @@ on: jobs: update: runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write strategy: fail-fast: true steps: @@ -26,7 +26,7 @@ jobs: - uses: actions/setup-python@v6 with: - python-version: "3.11" + python-version: "3.14" - name: Install Cruft run: python -m pip install git+https://github.com/Cadair/cruft@patch-p1 @@ -93,3 +93,68 @@ jobs: 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.** + + report-fail: + if: failure() + needs: [update] + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - name: Open an issue if workflow fails + uses: actions/github-script@v7 + with: + github-token: ${{ github.token }} + script: | + const fs = require('fs'); + + // Edit these if needed for your repo + const variables = { + owner: context.repo.owner, + name: context.repo.repo, + label: "Infrastructure", + creator: "app/github-actions", + title: "SunPy Package Template auto-update failed." + }; + + const logs = 'The package update workflow failed.' + const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; + const issue_body = `[Workflow Run URL](${workflow_url})\n${logs}`; + + const query_string = `repo:${variables.owner}/${variables.name} author:${variables.creator} label:${variables.label} is:open in:title ${variables.title}`; + + // Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures + const query = `query { + search(query: "${query_string}", type:ISSUE, first: 1) { + edges { + node { + ... on Issue { + body + id + number + } + } + } + } + }`; + + const result = await github.graphql(query); + + // If no issue is open, create a new issue, + // else update the body of the existing issue. + if (result.search.edges.length === 0) { + github.rest.issues.create({ + owner: variables.owner, + repo: variables.n ame, + body: issue_body, + title: variables.title, + labels: [variables.label], + }); + } else { + github.rest.issues.update({ + owner: variables.owner, + repo: variables.name, + issue_number: result.search.edges[0].node.number, + body: issue_body + }); + } From 9f3d189bd0421485408c6583bd24ead511d0d190 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Wed, 7 Jan 2026 14:17:13 +0000 Subject: [PATCH 2/2] attribution --- .../.github/workflows/sub_package_update.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml b/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml index 78c5827..171ce90 100644 --- a/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml +++ b/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml @@ -105,6 +105,8 @@ jobs: uses: actions/github-script@v7 with: github-token: ${{ github.token }} + # This script is adapted from https://github.com/scientific-python/issue-from-pytest-log-action + # Under MIT license (c) Scientific Python Developers script: | const fs = require('fs');