Debian Codegraph @

.github/workflows/link-check.yml

raw
1 # Check for broken links in the documentation.
2 # Runs daily on the main branch and opens/reopens/closes a GitHub issue accordingly.
3
4 name: link-check
5
6 env:
7 FORCE_COLOR: "1"
8 DEFAULT_PYTHON_VERSION: "3.14" # keep in sync with tox.ini
9 PIP_DISABLE_PIP_VERSION_CHECK: "1"
10
11 permissions: {}
12
13 on:
14 schedule:
15 - cron: "0 6 * * *" # daily at 06:00 UTC
16 workflow_dispatch:
17
18 jobs:
19 link-check:
20 runs-on: ubuntu-latest
21 steps:
22 - name: "Checkout repository"
23 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
24 with:
25 persist-credentials: false
26
27 - name: "Setup CI environment"
28 uses: pydata/pydata-sphinx-theme/.github/actions/set-dev-env@e8db643b990df73812cf9397bc0f8cfa1164e4d3
29 with:
30 python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
31
32 - name: "Check for broken links"
33 run: python -Im tox run -e docs-linkcheck
34
35 - name: "Upload broken-links report"
36 uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
37 with:
38 name: broken-links
39 path: docs/_build/linkcheck/output.txt
40 if: ${{ always() }}
41
42 report-issue:
43 needs: link-check
44 if: always()
45 runs-on: ubuntu-latest
46 permissions:
47 issues: write
48 steps:
49 - name: "Create, update, or close link-check issue"
50 uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
51 env:
52 CONCLUSION: ${{ needs.link-check.result }}
53 RUN_ID: ${{ github.run_id }}
54 with:
55 script: |
56 const TITLE = "Link-check found broken links";
57 const LABEL = "link-check";
58 const { owner, repo } = context.repo;
59 const conclusion = process.env.CONCLUSION;
60 const run_url = `https://github.com/${owner}/${repo}/actions/runs/${process.env.RUN_ID}`;
61
62 const q = `repo:${owner}/${repo} author:app/github-actions label:"${LABEL}" is:issue`;
63 const search = await github.rest.search.issuesAndPullRequests({ q });
64 const existing = search.data.items.find(i => i.title === TITLE);
65
66 if (conclusion === "failure") {
67 const body = [
68 `link-check failed, see ${run_url}`,
69 ``,
70 `This issue will be closed automatically the next time link-check succeeds.`,
71 ].join("\n");
72
73 if (existing) {
74 await github.rest.issues.update({
75 owner, repo,
76 issue_number: existing.number,
77 state: "open",
78 body,
79 });
80 console.log(`Reopened/updated issue #${existing.number}`);
81 } else {
82 const { data: issue } = await github.rest.issues.create({
83 owner, repo,
84 title: TITLE,
85 body,
86 labels: [LABEL],
87 });
88 console.log(`Created issue #${issue.number}`);
89 }
90 }
91
92 if (conclusion === "success" && existing) {
93 await github.rest.issues.update({
94 owner, repo,
95 issue_number: existing.number,
96 state: "closed",
97 body: `Closed automatically because link-check succeeded (${run_url})`,
98 });
99 console.log(`Closed issue #${existing.number}`);
100 }