|
25 | 25 | if: ${{ github.repository_owner == 'pypa' || github.event_name != 'schedule' }} |
26 | 26 | runs-on: ubuntu-latest |
27 | 27 | timeout-minutes: 20 |
| 28 | + permissions: |
| 29 | + contents: read |
| 30 | + # actions:read is enough to restore the cache but saving the base |
| 31 | + # linkcheck results on pushes to main needs actions:write |
| 32 | + actions: write |
28 | 33 | continue-on-error: >- |
29 | 34 | ${{ fromJSON(matrix.continue-on-error) }} |
30 | 35 | strategy: |
@@ -54,13 +59,58 @@ jobs: |
54 | 59 | run: | |
55 | 60 | python -m pip install --upgrade nox virtualenv |
56 | 61 |
|
| 62 | + - name: Restore base linkcheck results |
| 63 | + # On PRs and merge queue runs, only check links added by the change |
| 64 | + # See https://github.com/pypa/packaging.python.org/issues/2037 |
| 65 | + if: >- |
| 66 | + matrix.noxenv == 'linkcheck' && |
| 67 | + contains(fromJSON('["pull_request", "merge_group"]'), github.event_name) |
| 68 | + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
| 69 | + with: |
| 70 | + path: .cache/linkcheck-base |
| 71 | + # We don't expect an exact match here. Restore the most recent base |
| 72 | + # result using the restore-keys prefix instead |
| 73 | + key: linkcheck-base-${{ github.sha }} |
| 74 | + restore-keys: | |
| 75 | + linkcheck-base- |
| 76 | +
|
57 | 77 | - name: Nox ${{ matrix.noxenv }} |
58 | 78 | env: |
59 | 79 | # Authenticate github.com requests during linkcheck to avoid rate limits. |
60 | 80 | GITHUB_TOKEN: ${{ matrix.noxenv == 'linkcheck' && github.token || '' }} |
61 | 81 | run: | |
62 | 82 | python -m nox -s ${{ matrix.noxenv }} |
63 | 83 |
|
| 84 | + - name: Prepare base linkcheck results |
| 85 | + # Only cache results from main so PRs and merge queue runs can compare |
| 86 | + # their links against the latest merged version. |
| 87 | + # |
| 88 | + # Keep this step running even if linkcheck finds broken links. It uses |
| 89 | + # --keep-going, so output.json still contains the full result set. |
| 90 | + # Broken links on main should be cached too, since they are already |
| 91 | + # known failures. Skip only if the run was cancelled or output.json |
| 92 | + # was never created. |
| 93 | + if: >- |
| 94 | + (success() || failure()) && matrix.noxenv == 'linkcheck' && |
| 95 | + github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 96 | + run: | |
| 97 | + mkdir -p .cache/linkcheck-base |
| 98 | + if [ -f build/output.json ]; then |
| 99 | + cp build/output.json .cache/linkcheck-base/output.json |
| 100 | + else |
| 101 | + echo "::warning::build/output.json not found; skipping base linkcheck cache update" |
| 102 | + fi |
| 103 | +
|
| 104 | + - name: Save base linkcheck results |
| 105 | + if: >- |
| 106 | + (success() || failure()) && matrix.noxenv == 'linkcheck' && |
| 107 | + github.event_name == 'push' && github.ref == 'refs/heads/main' && |
| 108 | + hashFiles('.cache/linkcheck-base/output.json') != '' |
| 109 | + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
| 110 | + with: |
| 111 | + path: .cache/linkcheck-base |
| 112 | + key: linkcheck-base-${{ github.sha }} |
| 113 | + |
64 | 114 |
|
65 | 115 | check: |
66 | 116 | # This job does nothing and is only used for the branch protection |
|
0 commit comments