diff --git a/.github/actions/deploy-to-github-pages/action.yml b/.github/actions/deploy-to-github-pages/action.yml index b60feb5735..feb0c7a3da 100644 --- a/.github/actions/deploy-to-github-pages/action.yml +++ b/.github/actions/deploy-to-github-pages/action.yml @@ -62,3 +62,62 @@ runs: - name: deploy id: deploy uses: actions/deploy-pages@v4 + + - name: construct `--remap` option for lychee + id: remap + shell: bash + run: | + base_url='${{ steps.pages.outputs.base_url }}' + echo "result=$(echo "$base_url" | + sed 's|^\(.*\)\(/git-scm\.com\)$|(\1)?\2(.*)|') file://$PWD/public\$2" \ + >>$GITHUB_OUTPUT + + - name: check for broken links + id: lychee + uses: lycheeverse/lychee-action@25a231001d1723960a301b7d4c82884dc7ef857d # until an official version is out that includes https://github.com/lycheeverse/lychee/pull/1422 + with: + lycheeVersion: nightly # until an official version includes https://github.com/lycheeverse/lychee/pull/1422 + args: >- + --offline + --fallback-extensions html + --base '${{ steps.pages.outputs.base_url }}' + --remap '${{ steps.remap.outputs.result }}' + --exclude file:///path/to/repo.git/ + --exclude file:///caminho/para/o/reposit%C3%B3rio.git/ + --exclude file:///ruta/a/repositorio.git/ + --exclude file:///sl%C3%B3%C3%B0/til/hirsla.git/ + --exclude file:///Pfad/zum/Repo.git/ + --exclude file:///chemin/du/d%C3%A9p%C3%B4t.git/ + --exclude file:///srv/git/project.git + public/ + output: lychee.md + jobSummary: true + fail: false + failIfEmpty: false # needed because its default overrides `fail = false` + + - name: ${{ env.lychee_exit_code != '0' && 'maybe close' || 'open or update' }} link checker issue + uses: actions/github-script@v7 + with: + script: | + const fs = await import('fs') + // GitHub issues can only have 64k characters in their body + const body = (s => { + if (s.length < 65535) return s + return s.replace(/^([^]{0,65000}\n)[^]*\n(.+)\n?$/, '$1\n[...]\n\n$2') + })(await fs.promises.readFile('lychee.md', 'utf8')) + + const req = { owner: context.repo.owner, repo: context.repo.repo } + const q = `"Link+Checker+Report"+in:title+is:issue+label:linkchecker+is:open+repo:${req.owner}/${req.repo}` + const issues = await github.rest.search.issuesAndPullRequests({ ...req, q, sort: 'created', per_page: 1 }) + + if (issues.data.items.length === 0) { + if (process.env.lychee_exit_code !== '0') { + await github.rest.issues.create({ ...req, title: 'Link Checker Report', body, labels: ['linkchecker'] }) + } + } else { + req.issue_number = issues.data.items[0].number + await github.rest.issues.createComment({ ...req, body }) + if (process.env.lychee_exit_code === '0') { + await github.rest.issues.update({ ...req, state: 'closed' }) + } + } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45122b79fb..83738fc03d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,3 +57,22 @@ jobs: } done exit $res + + - name: check for broken links + id: lychee + uses: lycheeverse/lychee-action@25a231001d1723960a301b7d4c82884dc7ef857d # until an official version is out that includes https://github.com/lycheeverse/lychee/pull/1422 + with: + lycheeVersion: nightly # until an official version includes https://github.com/lycheeverse/lychee/pull/1422 + args: >- + --offline + --fallback-extensions html + --exclude file:///path/to/repo.git/ + --exclude file:///caminho/para/o/reposit%C3%B3rio.git/ + --exclude file:///ruta/a/repositorio.git/ + --exclude file:///sl%C3%B3%C3%B0/til/hirsla.git/ + --exclude file:///Pfad/zum/Repo.git/ + --exclude file:///chemin/du/d%C3%A9p%C3%B4t.git/ + --exclude file:///srv/git/project.git + public/ + output: lychee.md + jobSummary: true diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 427253d591..6523cc0425 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,6 +12,7 @@ jobs: permissions: pages: write # to deploy to GitHub Pages id-token: write # to verify that the deployment source is legit + issues: write # to open tickets upon broken links environment: name: github-pages url: ${{ steps.deploy.outputs.url }} diff --git a/.github/workflows/update-book.yml b/.github/workflows/update-book.yml index e1bf8b3307..4ffa47a3c8 100644 --- a/.github/workflows/update-book.yml +++ b/.github/workflows/update-book.yml @@ -109,6 +109,7 @@ jobs: contents: write # to push changes (if any) pages: write # to deploy to GitHub Pages id-token: write # to verify that the deployment source is legit + issues: write # to open tickets upon broken links environment: name: github-pages url: ${{ steps.deploy.outputs.url }} diff --git a/.github/workflows/update-download-data.yml b/.github/workflows/update-download-data.yml index 9da529346f..000ca7bf32 100644 --- a/.github/workflows/update-download-data.yml +++ b/.github/workflows/update-download-data.yml @@ -13,6 +13,7 @@ jobs: contents: write # to push changes (if any) pages: write # to deploy to GitHub Pages id-token: write # to verify that the deployment source is legit + issues: write # to open tickets upon broken links environment: name: github-pages url: ${{ steps.deploy.outputs.url }} diff --git a/.github/workflows/update-git-version-and-manual-pages.yml b/.github/workflows/update-git-version-and-manual-pages.yml index c9b91d062d..714033d58d 100644 --- a/.github/workflows/update-git-version-and-manual-pages.yml +++ b/.github/workflows/update-git-version-and-manual-pages.yml @@ -18,6 +18,7 @@ jobs: contents: write # to push changes (if any) pages: write # to deploy to GitHub Pages id-token: write # to verify that the deployment source is legit + issues: write # to open tickets upon broken links environment: name: github-pages url: ${{ steps.deploy.outputs.url }} diff --git a/.github/workflows/update-translated-manual-pages.yml b/.github/workflows/update-translated-manual-pages.yml index 620fff0297..c77c09d964 100644 --- a/.github/workflows/update-translated-manual-pages.yml +++ b/.github/workflows/update-translated-manual-pages.yml @@ -37,6 +37,7 @@ jobs: contents: write # to push changes (if any) pages: write # to deploy to GitHub Pages id-token: write # to verify that the deployment source is legit + issues: write # to open tickets upon broken links environment: name: github-pages url: ${{ steps.deploy.outputs.url }}