|
1 | 1 | # This template is taken from the cruft example code, for further information please see: |
2 | 2 | # https://cruft.github.io/cruft/#automating-updates-with-github-actions |
3 | 3 | name: Automatic Update from package template |
4 | | -permissions: |
5 | | - contents: write |
6 | | - pull-requests: write |
7 | 4 |
|
8 | 5 | on: |
9 | 6 | # Allow manual runs through the web UI |
|
19 | 16 | jobs: |
20 | 17 | update: |
21 | 18 | runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + pull-requests: write |
22 | 22 | strategy: |
23 | 23 | fail-fast: true |
24 | 24 | steps: |
25 | | - - uses: actions/checkout@v4 |
| 25 | + - uses: actions/checkout@v6 |
26 | 26 |
|
27 | | - - uses: actions/setup-python@v5 |
| 27 | + - uses: actions/setup-python@v6 |
28 | 28 | with: |
29 | | - python-version: "3.11" |
| 29 | + python-version: "3.14" |
30 | 30 |
|
31 | 31 | - name: Install Cruft |
32 | 32 | run: python -m pip install git+https://github.com/Cadair/cruft@patch-p1 |
|
93 | 93 | If this pull request has been opened as a draft there are conflicts which need fixing. |
94 | 94 |
|
95 | 95 | **To run the CI on this pull request you will need to close it and reopen it.** |
| 96 | +
|
| 97 | + report-fail: |
| 98 | + if: failure() |
| 99 | + needs: [update] |
| 100 | + runs-on: ubuntu-latest |
| 101 | + permissions: |
| 102 | + issues: write |
| 103 | + steps: |
| 104 | + - name: Open an issue if workflow fails |
| 105 | + uses: actions/github-script@v7 |
| 106 | + with: |
| 107 | + github-token: ${{ github.token }} |
| 108 | + # This script is adapted from https://github.com/scientific-python/issue-from-pytest-log-action |
| 109 | + # Under MIT license (c) Scientific Python Developers |
| 110 | + script: | |
| 111 | + const fs = require('fs'); |
| 112 | +
|
| 113 | + // Edit these if needed for your repo |
| 114 | + const variables = { |
| 115 | + owner: context.repo.owner, |
| 116 | + name: context.repo.repo, |
| 117 | + label: "Infrastructure", |
| 118 | + creator: "app/github-actions", |
| 119 | + title: "SunPy Package Template auto-update failed." |
| 120 | + }; |
| 121 | +
|
| 122 | + const logs = 'The package update workflow failed.' |
| 123 | + const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; |
| 124 | + const issue_body = `[Workflow Run URL](${workflow_url})\n${logs}`; |
| 125 | +
|
| 126 | + const query_string = `repo:${variables.owner}/${variables.name} author:${variables.creator} label:${variables.label} is:open in:title ${variables.title}`; |
| 127 | +
|
| 128 | + // Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures |
| 129 | + const query = `query { |
| 130 | + search(query: "${query_string}", type:ISSUE, first: 1) { |
| 131 | + edges { |
| 132 | + node { |
| 133 | + ... on Issue { |
| 134 | + body |
| 135 | + id |
| 136 | + number |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + }`; |
| 142 | +
|
| 143 | + const result = await github.graphql(query); |
| 144 | +
|
| 145 | + // If no issue is open, create a new issue, |
| 146 | + // else update the body of the existing issue. |
| 147 | + if (result.search.edges.length === 0) { |
| 148 | + github.rest.issues.create({ |
| 149 | + owner: variables.owner, |
| 150 | + repo: variables.name, |
| 151 | + body: issue_body, |
| 152 | + title: variables.title, |
| 153 | + labels: [variables.label], |
| 154 | + }); |
| 155 | + } else { |
| 156 | + github.rest.issues.update({ |
| 157 | + owner: variables.owner, |
| 158 | + repo: variables.name, |
| 159 | + issue_number: result.search.edges[0].node.number, |
| 160 | + body: issue_body |
| 161 | + }); |
| 162 | + } |
0 commit comments