|
| 1 | +name: Python Versions |
| 2 | + |
| 3 | +# #1660: keeps .github/python-versions.toml current. `detect` recomputes the |
| 4 | +# tiers from python.org's release cycle, PyPy's releases, setup-python's builds |
| 5 | +# and the hosted runner images (util/update_python_versions.py, whose docstring |
| 6 | +# gives the rules), rewrites the file and the prose the audit tests pin to it, |
| 7 | +# and runs that audit. When something changed, `pr` pushes the change to |
| 8 | +# `bot/python-versions` and opens that branch's pull request, or updates the |
| 9 | +# open one, for the owner to merge. Nothing here pushes `main` or edits ruleset |
| 10 | +# 23497679: the pull request body lists the required contexts to change by hand. |
| 11 | +# |
| 12 | +# Only these two triggers. A push to `bot/python-versions` starts the pull |
| 13 | +# request's own checks, which is why `pr` spends the release App's token rather |
| 14 | +# than GITHUB_TOKEN, whose pushes start nothing; nothing it starts runs this |
| 15 | +# workflow again. |
| 16 | +on: |
| 17 | + schedule: |
| 18 | + - cron: '41 5 * * 1' # Mondays at 05:41 UTC |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +# Nothing by default; each job asks for what it needs. |
| 22 | +permissions: {} |
| 23 | + |
| 24 | +# One run at a time, so two runs cannot race for the branch. A queued run is |
| 25 | +# kept, not cancelled: it recomputes from the sources and skips what the branch |
| 26 | +# already proposes. |
| 27 | +concurrency: |
| 28 | + group: python-versions |
| 29 | + cancel-in-progress: false |
| 30 | + |
| 31 | +jobs: |
| 32 | + # No secret and a read-only token. The computation reads the network and |
| 33 | + # writes only this checkout, and the audit is the repository's own tests. |
| 34 | + detect: |
| 35 | + name: Recompute the Python version tiers |
| 36 | + runs-on: ubuntu-latest |
| 37 | + timeout-minutes: 15 |
| 38 | + permissions: |
| 39 | + contents: read |
| 40 | + pull-requests: read |
| 41 | + outputs: |
| 42 | + changed: ${{ steps.update.outputs.changed }} |
| 43 | + publish: ${{ steps.update.outputs.publish }} |
| 44 | + |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v7 |
| 47 | + with: |
| 48 | + persist-credentials: false |
| 49 | + |
| 50 | + # `latest` for this job, like every single-interpreter job (#1661). |
| 51 | + - name: Read the Python versions |
| 52 | + id: python-versions |
| 53 | + run: python3 util/python_versions.py --github-output |
| 54 | + |
| 55 | + - uses: actions/setup-python@v7 |
| 56 | + with: |
| 57 | + python-version: ${{ steps.python-versions.outputs.latest }} |
| 58 | + |
| 59 | + # PyYAML, from the `test` extra, for the workflow readers and the audit; |
| 60 | + # neither imports pcapkit. |
| 61 | + - name: Install PyYAML |
| 62 | + run: python -m pip install PyYAML |
| 63 | + |
| 64 | + # Fetches the four sources, rewrites the files, and writes the proposal to |
| 65 | + # $RUNNER_TEMP/proposal. `publish` is false when nothing changed, or when |
| 66 | + # `bot/python-versions` has an open pull request and a commit it holds |
| 67 | + # ahead of main proposes these tiers, hand edits or merges of main on top |
| 68 | + # or not (an anonymous, commits-only fetch), so an unmerged proposal is not |
| 69 | + # pushed, nor its approval asked for, every week. When that branch holds |
| 70 | + # commits it did not make and proposes other tiers, this fails as |
| 71 | + # `publish` would refuse, before any approval. A branch with no open pull |
| 72 | + # request was merged or closed, and is proposed afresh. The token reads |
| 73 | + # that pull request's state. |
| 74 | + - name: Recompute the tiers |
| 75 | + id: update |
| 76 | + env: |
| 77 | + GH_TOKEN: ${{ github.token }} |
| 78 | + run: >- |
| 79 | + python util/update_python_versions.py update --write --out "$RUNNER_TEMP/proposal" |
| 80 | + --proposal-branch bot/python-versions --github-output |
| 81 | +
|
| 82 | + # The three modules that pin the workflows and the prose to the file, on |
| 83 | + # the rewritten tree. A failure here does not stop the proposal: a tier |
| 84 | + # move can need hand edits the script names, and the body lists what failed. |
| 85 | + - name: Run the audit tests |
| 86 | + id: audit |
| 87 | + continue-on-error: true |
| 88 | + shell: bash |
| 89 | + run: >- |
| 90 | + python -m unittest -v tests.project.test_python_versions_1660 |
| 91 | + tests.project.test_python_matrix_tiers_1633 tests.project.test_ktlo_legs_stay_green_1672 |
| 92 | + 2>&1 | tee "$RUNNER_TEMP/audit.log" |
| 93 | +
|
| 94 | + - name: Write the pull request body |
| 95 | + if: ${{ steps.update.outputs.changed == 'true' }} |
| 96 | + env: |
| 97 | + AUDIT_OUTCOME: ${{ steps.audit.outcome }} |
| 98 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 99 | + run: >- |
| 100 | + python util/update_python_versions.py body "$RUNNER_TEMP/proposal" |
| 101 | + --audit-outcome "$AUDIT_OUTCOME" --audit-log "$RUNNER_TEMP/audit.log" --run-url "$RUN_URL" |
| 102 | +
|
| 103 | + # Kept for as long as an environment approval can wait. The proposal holds |
| 104 | + # files/.github/..., which upload-artifact leaves out unless told otherwise. |
| 105 | + - name: Upload the proposal |
| 106 | + if: ${{ steps.update.outputs.publish == 'true' }} |
| 107 | + uses: actions/upload-artifact@v7 |
| 108 | + with: |
| 109 | + name: python-versions-proposal |
| 110 | + path: ${{ runner.temp }}/proposal |
| 111 | + include-hidden-files: true |
| 112 | + retention-days: 30 |
| 113 | + |
| 114 | + - name: Say why no pull request opens |
| 115 | + if: ${{ steps.update.outputs.publish == 'true' && vars.RELEASE_APP_CLIENT_ID == '' }} |
| 116 | + run: >- |
| 117 | + echo "::warning title=No pull request without the release App::vars.RELEASE_APP_CLIENT_ID is unset, |
| 118 | + so the pr job skips. Set up the App as docs/source/contributing/releasing.rst describes." |
| 119 | +
|
| 120 | + # With nothing changed the tree is main's, so a failing audit is main's own |
| 121 | + # failure: the run says so rather than passing green over it. |
| 122 | + - name: Fail on a failing audit of an unchanged tree |
| 123 | + if: ${{ steps.update.outputs.changed != 'true' && steps.audit.outcome == 'failure' }} |
| 124 | + run: | |
| 125 | + echo "::error title=The audit fails on main::the tiers need no change, but the audit fails; see above." |
| 126 | + exit 1 |
| 127 | +
|
| 128 | + # The release App's private key is a secret of the `github-release` |
| 129 | + # environment, which needs the owner's approval, so he is asked only on a run |
| 130 | + # that has something to propose. The token is contents and pull requests |
| 131 | + # write and nothing else: no `workflows`, so it cannot push a workflow file, |
| 132 | + # and `update` writes none. `publish` force-pushes `bot/python-versions` alone, |
| 133 | + # and while its pull request is open refuses it if it holds commits it did not |
| 134 | + # make; with none open it recreates the branch from main. |
| 135 | + pr: |
| 136 | + name: Open or update the pull request |
| 137 | + needs: detect |
| 138 | + if: >- |
| 139 | + ${{ needs.detect.outputs.publish == 'true' && vars.RELEASE_APP_CLIENT_ID != '' && |
| 140 | + github.ref == 'refs/heads/main' }} |
| 141 | + runs-on: ubuntu-latest |
| 142 | + timeout-minutes: 10 |
| 143 | + environment: github-release |
| 144 | + # GITHUB_TOKEN only downloads `detect`'s artifact; the App's token does the rest. |
| 145 | + permissions: |
| 146 | + actions: read |
| 147 | + |
| 148 | + steps: |
| 149 | + - name: Mint the release App's token |
| 150 | + id: app |
| 151 | + uses: actions/create-github-app-token@v3 |
| 152 | + with: |
| 153 | + client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} |
| 154 | + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} |
| 155 | + permission-contents: write |
| 156 | + permission-pull-requests: write |
| 157 | + |
| 158 | + # The commit `detect` read, with full history for the branch's merge base. |
| 159 | + - uses: actions/checkout@v7 |
| 160 | + with: |
| 161 | + ref: ${{ github.sha }} |
| 162 | + fetch-depth: 0 |
| 163 | + token: ${{ steps.app.outputs.token }} |
| 164 | + |
| 165 | + - name: Download the proposal |
| 166 | + env: |
| 167 | + GH_TOKEN: ${{ github.token }} |
| 168 | + run: >- |
| 169 | + gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name python-versions-proposal |
| 170 | + --dir "$RUNNER_TEMP/proposal" |
| 171 | +
|
| 172 | + - name: Push the proposal and open or update its pull request |
| 173 | + env: |
| 174 | + GH_TOKEN: ${{ steps.app.outputs.token }} |
| 175 | + APP_SLUG: ${{ steps.app.outputs.app-slug }} |
| 176 | + APP_BOT_ID: ${{ vars.RELEASE_APP_BOT_ID }} |
| 177 | + run: python3 util/update_python_versions.py publish "$RUNNER_TEMP/proposal" |
0 commit comments