From 0c9a959ee86f8635f210d06c0360e0482631af82 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Feb 2025 14:46:03 +0100 Subject: [PATCH 1/4] deploy: do open/close issues about broken links There is specific code in git-scm.com's deploy workflow to open a ticket whenever broken links were detected, and to close such a ticket when no broken links were detected. However, as per https://github.com/lycheeverse/lychee-action/pull/265 the way we checked for this was incorrect: `env.lychee_exit_code` had was correct, until https://github.com/lycheeverse/lychee-action/pull/245 broke it by way of fixing another bug. This was the reason why the broken link that was found and reported in https://github.com/git/git-scm.com/actions/runs/13544529063/job/37852881418#step:3:135319 never made it into a GitHub issue, even if that had been the intention. For the record, I worked on a fix for this broken link and opened https://github.com/jnavila/git-manpages-l10n/pull/131 to incorporate that fix. What prevented this broken link from being detected before above-mentioned deployment is the fact that before https://github.com/git/git-scm.com/pull/1953 was merged, the `git-scm.com` deployment used `http://` in the base URL, and hence the `--remap` option used in the deployment workflow mapped all http://git-scm.com links to local files, whereas now the `https://` base URL is used and https://git-scm.com links are mapped, including the offending one. In any case let's fix opening/closing the "broken link" issues. Signed-off-by: Johannes Schindelin --- .github/actions/deploy-to-github-pages/action.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/actions/deploy-to-github-pages/action.yml b/.github/actions/deploy-to-github-pages/action.yml index 0b999db9ca..3e6a6fbfdc 100644 --- a/.github/actions/deploy-to-github-pages/action.yml +++ b/.github/actions/deploy-to-github-pages/action.yml @@ -176,8 +176,7 @@ runs: fail: false failIfEmpty: false # needed because its default overrides `fail = false` - - name: ${{ env.lychee_exit_code != '0' && 'open or update' || 'maybe close' }} link checker issue - if: env.lychee_exit_code != '' + - name: ${{ steps.lychee.outputs.exit_code != '0' && 'open or update' || 'maybe close' }} link checker issue uses: actions/github-script@v7 with: github-token: ${{ inputs.github-token }} @@ -211,13 +210,13 @@ runs: })() if (issues.data.items.length === 0) { - if (process.env.lychee_exit_code !== '0') { + if ('${{ steps.lychee.outputs.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') { + if ('${{ steps.lychee.outputs.exit_code }}' === '0') { await github.rest.issues.update({ ...req, state: 'closed' }) } } From f239ec38a327d44275d4a2458bcebffa0be387d2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 27 Feb 2025 02:30:34 +0100 Subject: [PATCH 2/4] deploy(link-check): be careful to anchor the remap patterns Especially the first one, which typically starts with `(https://.github.io/)?/git-scm.com)`, needs to be anchored to the beginning of the link, otherwise `/git-scm.com` would be matched even in the middle of any link, which was not intended (because the replacement starts with `file:/` and hence must be anchored at the start. Signed-off-by: Johannes Schindelin --- .github/actions/deploy-to-github-pages/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/deploy-to-github-pages/action.yml b/.github/actions/deploy-to-github-pages/action.yml index 3e6a6fbfdc..db99ca1654 100644 --- a/.github/actions/deploy-to-github-pages/action.yml +++ b/.github/actions/deploy-to-github-pages/action.yml @@ -131,12 +131,12 @@ runs: shell: bash run: | echo "result=$(echo "$base_url" | - sed 's|^\(.*\)\(/git-scm\.com\)$|(\1)?\2(.*)|') file://$PWD/public\$2" \ + sed 's|^\(.*\)\(/git-scm\.com\)$|^(\1)?\2(.*)|') file://$PWD/public\$2" \ >>$GITHUB_OUTPUT # When running in forks, do detect when links try to break out of the # `/git-scm.com/` subdirectory echo "remap-dotdot=$(echo "$base_url" | - sed -n 's|^\(https\?:\/\/.*\)\(/git-scm\.com\)$|--remap '\''(\1.*) file://../$1'\''|p')" \ + sed -n 's|^\(https\?:\/\/.*\)\(/git-scm\.com\)$|--remap '\''^(\1.*) file://../$1'\''|p')" \ >>$GITHUB_OUTPUT - name: check for downgrades to unencrypted HTTP From 969d67e297c127b9be89ffd7368f625d3cdc3389 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 26 Feb 2025 16:33:55 +0100 Subject: [PATCH 3/4] deploy(link-check): verify absolute git-scm.com links also in forks When deploying in forks, the base URL is distinctly different from https://git-scm.com. But there are plenty of such links in the HTML pages, e.g. all of those links in the ProGit book that point to Git's homepage. Let's include those in the checks so that broken links are noticed earlier rather than later. Signed-off-by: Johannes Schindelin --- .github/actions/deploy-to-github-pages/action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/actions/deploy-to-github-pages/action.yml b/.github/actions/deploy-to-github-pages/action.yml index db99ca1654..146e6af0f7 100644 --- a/.github/actions/deploy-to-github-pages/action.yml +++ b/.github/actions/deploy-to-github-pages/action.yml @@ -138,6 +138,9 @@ runs: echo "remap-dotdot=$(echo "$base_url" | sed -n 's|^\(https\?:\/\/.*\)\(/git-scm\.com\)$|--remap '\''^(\1.*) file://../$1'\''|p')" \ >>$GITHUB_OUTPUT + # When running in forks, do treat https://git-scm.com links as if they were relative + test https://git-scm.com = "$base_url" || + echo "remap-git-scm=--remap '^https?://git-scm.com(.*) file://$PWD/public\$1'" >>$GITHUB_OUTPUT - name: check for downgrades to unencrypted HTTP if: startsWith(env.base_url, 'https://') @@ -163,6 +166,7 @@ runs: --base '${{ env.base_url }}' --remap '${{ steps.remap.outputs.result }}' ${{ steps.remap.outputs.remap-dotdot }} + ${{ steps.remap.outputs.remap-git-scm }} --exclude file:///path/to/repo.git/ --exclude file:///caminho/para/o/reposit%C3%B3rio.git/ --exclude file:///ruta/a/repositorio.git/ From c902ac87c77033b381ad308de9993f106fa23b91 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 27 Feb 2025 08:31:44 +0100 Subject: [PATCH 4/4] ci: check for broken git-scm.com links Not all links are relative in the PR build; Some of the links originate from Git's manual pages or from the ProGit book or its translations, and those links are of the form "https://git-scm.com/...". Let's map those into "file:///..." URLs so that lychee checks them even in offline mode. This uncovers a broken link which is address by https://github.com/jnavila/git-manpages-l10n/pull/131. For the time being, this patch adds a work-around specifically for that issue lest contributors' PRs fail through no fault of their own. Signed-off-by: Johannes Schindelin --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7513da65b5..ff035e2b6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,13 @@ jobs: curl -Lo /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v$HUGO_VERSION/hugo_extended_${HUGO_VERSION}_linux-amd64.deb && sudo dpkg -i /tmp/hugo.deb + - name: work around a broken link + # See https://github.com/jnavila/git-manpages-l10n/pull/131; + # A space is missing in "https://git-scm.com/docs上查看" + run: | + sed -i 's,\(href="\(https://git-scm.com/docs\)\)\(上查看\)"\([^>]*>\)\2\3\(\),\1"\4\1\5 \3,p' \ + external/docs/content/docs/git/zh_HANS-CN.html + - name: run Hugo to build the pages run: hugo @@ -64,6 +71,7 @@ jobs: with: args: >- --offline + --remap '^https?://git-scm.com(.*) file://'"$PWD"'/public$1' --fallback-extensions html --exclude file:///path/to/repo.git/ --exclude file:///caminho/para/o/reposit%C3%B3rio.git/