From d989c7a38eefbe54704b63c229f28b8e132a972e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 29 Jun 2025 12:11:26 -0700 Subject: [PATCH] Make it easier to run lychee locally --- .github/scripts/dependencies.dockerfile | 3 ++ .github/scripts/link-check.sh | 35 +++++++++++++++++++ .../workflows/build-daily-no-build-cache.yml | 2 +- .github/workflows/build-daily.yml | 8 ++--- .github/workflows/build-pull-request.yml | 4 +-- .github/workflows/build.yml | 6 ++-- .github/workflows/reusable-link-check.yml | 18 ++++++++++ .../reusable-markdown-link-check.yml | 20 ----------- lychee.toml => .lychee.toml | 7 +--- 9 files changed, 67 insertions(+), 36 deletions(-) create mode 100644 .github/scripts/dependencies.dockerfile create mode 100755 .github/scripts/link-check.sh create mode 100644 .github/workflows/reusable-link-check.yml delete mode 100644 .github/workflows/reusable-markdown-link-check.yml rename lychee.toml => .lychee.toml (80%) diff --git a/.github/scripts/dependencies.dockerfile b/.github/scripts/dependencies.dockerfile new file mode 100644 index 000000000000..d8e3bbfe176b --- /dev/null +++ b/.github/scripts/dependencies.dockerfile @@ -0,0 +1,3 @@ +# this file exists so that Renovate can auto-update docker image versions that are then used elsewhere + +FROM lycheeverse/lychee:sha-2aa22f8@sha256:2e3786630482c41f9f2dd081e06d7da1c36d66996e8cf6573409b8bc418d48c4 AS lychee diff --git a/.github/scripts/link-check.sh b/.github/scripts/link-check.sh new file mode 100755 index 000000000000..788e22830ba4 --- /dev/null +++ b/.github/scripts/link-check.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +export MSYS_NO_PATHCONV=1 # for Git Bash on Windows + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +LYCHEE_CONFIG="$SCRIPT_DIR/../../.lychee.toml" +DEPENDENCIES_DOCKERFILE="$SCRIPT_DIR/dependencies.dockerfile" + +# Extract lychee version from dependencies.dockerfile +LYCHEE_VERSION=$(grep "FROM lycheeverse/lychee:" "$DEPENDENCIES_DOCKERFILE" | sed 's/.*FROM lycheeverse\/lychee:\([^ ]*\).*/\1/') + +# Build the lychee command with optional GitHub token +CMD="lycheeverse/lychee:$LYCHEE_VERSION --verbose --config $(basename "$LYCHEE_CONFIG")" + +# Add GitHub token if available +if [[ -n "$GITHUB_TOKEN" ]]; then + CMD="$CMD --github-token $GITHUB_TOKEN" +fi + +# Add the target directory +CMD="$CMD ." + +# Determine if we should allocate a TTY +DOCKER_FLAGS="--rm --init" +if [[ -t 0 ]]; then + DOCKER_FLAGS="$DOCKER_FLAGS -it" +else + DOCKER_FLAGS="$DOCKER_FLAGS -i" +fi + +# Run lychee with proper signal handling +# shellcheck disable=SC2086 +exec docker run $DOCKER_FLAGS -v "$(dirname "$LYCHEE_CONFIG")":/data -w /data $CMD diff --git a/.github/workflows/build-daily-no-build-cache.yml b/.github/workflows/build-daily-no-build-cache.yml index 1039fb64c520..652df1d810b6 100644 --- a/.github/workflows/build-daily-no-build-cache.yml +++ b/.github/workflows/build-daily-no-build-cache.yml @@ -27,7 +27,7 @@ jobs: # muzzle is not included here because it doesn't use gradle cache anyway and so is already covered # by the normal daily build - # markdown-link-check and misspell-check are not included here because they don't use gradle cache + # link-check and misspell-check are not included here because they don't use gradle cache # anyway and so are already covered by the normal daily build workflow-notification: diff --git a/.github/workflows/build-daily.yml b/.github/workflows/build-daily.yml index 0d441610a24c..7d76d7c02f8e 100644 --- a/.github/workflows/build-daily.yml +++ b/.github/workflows/build-daily.yml @@ -26,8 +26,8 @@ jobs: shell-script-check: uses: ./.github/workflows/reusable-shell-script-check.yml - markdown-link-check: - uses: ./.github/workflows/reusable-markdown-link-check.yml + link-check: + uses: ./.github/workflows/reusable-link-check.yml markdown-lint-check: uses: ./.github/workflows/reusable-markdown-lint-check.yml @@ -43,7 +43,7 @@ jobs: - common - test-latest-deps - muzzle - - markdown-link-check + - link-check - misspell-check if: always() uses: ./.github/workflows/reusable-workflow-notification.yml @@ -53,6 +53,6 @@ jobs: needs.common.result == 'success' && needs.test-latest-deps.result == 'success' && needs.muzzle.result == 'success' && - needs.markdown-link-check.result == 'success' && + needs.link-check.result == 'success' && needs.misspell-check.result == 'success' }} diff --git a/.github/workflows/build-pull-request.yml b/.github/workflows/build-pull-request.yml index 7f5b943c1b97..121405d721a0 100644 --- a/.github/workflows/build-pull-request.yml +++ b/.github/workflows/build-pull-request.yml @@ -43,11 +43,11 @@ jobs: uses: ./.github/workflows/reusable-shell-script-check.yml # this is not a required check to avoid blocking pull requests if external links break - markdown-link-check: + markdown-check: # release branches are excluded because the README.md javaagent download link has to be updated # on release branches before the release download has been published if: "!startsWith(github.ref_name, 'release/') && !startsWith(github.base_ref, 'release/')" - uses: ./.github/workflows/reusable-markdown-link-check.yml + uses: ./.github/workflows/reusable-link-check.yml markdown-lint-check: uses: ./.github/workflows/reusable-markdown-lint-check.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e24d0114ccd5..c99f34412c79 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,12 +37,12 @@ jobs: if: "!startsWith(github.ref_name, 'release/')" uses: ./.github/workflows/reusable-shell-script-check.yml - markdown-link-check: + link-check: # release branches are excluded to avoid unnecessary maintenance if external links break # (and also because the README.md javaagent download link has to be updated on release branches # before the release download has been published) if: "!startsWith(github.ref_name, 'release/')" - uses: ./.github/workflows/reusable-markdown-link-check.yml + uses: ./.github/workflows/reusable-link-check.yml markdown-lint-check: # release branches are excluded @@ -58,7 +58,7 @@ jobs: publish-snapshots: needs: # intentionally not blocking snapshot publishing on test-latest-deps, muzzle, - # markdown-link-check, or misspell-check + # link-check, or misspell-check - common runs-on: ubuntu-latest # skipping release branches because the versions in those branches are not snapshots diff --git a/.github/workflows/reusable-link-check.yml b/.github/workflows/reusable-link-check.yml new file mode 100644 index 000000000000..044e85e1f9a5 --- /dev/null +++ b/.github/workflows/reusable-link-check.yml @@ -0,0 +1,18 @@ +name: Reusable - Link check + +on: + workflow_call: + +permissions: + contents: read + +jobs: + link-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Link check + env: + GITHUB_TOKEN: ${{ github.token }} + run: ./.github/scripts/link-check.sh diff --git a/.github/workflows/reusable-markdown-link-check.yml b/.github/workflows/reusable-markdown-link-check.yml deleted file mode 100644 index 7c2f372df4e8..000000000000 --- a/.github/workflows/reusable-markdown-link-check.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Reusable - Markdown link check - -on: - workflow_call: - -permissions: - contents: read - -jobs: - markdown-link-check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - - uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2.4.1 - with: - args: > - --config ./lychee.toml - --github-token ${{ github.token }} - . diff --git a/lychee.toml b/.lychee.toml similarity index 80% rename from lychee.toml rename to .lychee.toml index 9bead5bd3802..b5a5e45d618c 100644 --- a/lychee.toml +++ b/.lychee.toml @@ -3,10 +3,7 @@ retry_wait_time = 5 max_retries = 6 max_concurrency = 4 -# Stealth -user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:128.0) Gecko/20100101 Firefox/128.0" - -# Check fragments in links +# Check link anchors include_fragments = true # excluding links to pull requests and issues is done for performance @@ -17,5 +14,3 @@ exclude = [ '^https://softwareengineering.stackexchange.com/questions/29727.*', '^https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/io/opentelemetry/$', ] - -