More link check improvements (#2010)

This commit is contained in:
Trask Stalnaker 2025-07-12 16:47:12 -07:00 committed by GitHub
parent 6f3a18a109
commit 6a3094f18a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 25 deletions

View File

@ -1,7 +0,0 @@
# Check link anchors
include_fragments = true
# For relative links only, we exclude all external URLs
exclude = [
"^https?://.*",
]

View File

@ -6,21 +6,21 @@ export MSYS_NO_PATHCONV=1 # for Git Bash on Windows
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$SCRIPT_DIR/../.."
DEPENDENCIES_DOCKERFILE="$SCRIPT_DIR/dependencies.dockerfile"
DEPENDENCIES_DOCKERFILE="$SCRIPT_DIR/dependencies.Dockerfile"
# Parse command line arguments
RELATIVE_ONLY=false
MODIFIED_FILES=""
LOCAL_LINKS_ONLY=false
TARGET=""
while [[ $# -gt 0 ]]; do
case $1 in
--relative-only)
RELATIVE_ONLY=true
--local-links-only)
LOCAL_LINKS_ONLY=true
shift
;;
*)
# Treat any other arguments as file paths
MODIFIED_FILES="$MODIFIED_FILES $1"
TARGET="$TARGET $1"
shift
;;
esac
@ -29,26 +29,24 @@ done
# Extract lychee version from dependencies.dockerfile
LYCHEE_VERSION=$(grep "FROM lycheeverse/lychee:" "$DEPENDENCIES_DOCKERFILE" | sed 's/.*FROM lycheeverse\/lychee:\([^ ]*\).*/\1/')
# Determine target files/directories and config file
TARGET="."
LYCHEE_CONFIG=".github/scripts/.lychee.toml"
if [[ "$RELATIVE_ONLY" == "true" ]]; then
LYCHEE_CONFIG=".github/scripts/.lychee-relative.toml"
fi
if [[ -n "$MODIFIED_FILES" ]]; then
TARGET="$MODIFIED_FILES"
if [[ -z "$TARGET" ]]; then
TARGET="."
fi
# Build the lychee command with optional GitHub token
CMD="lycheeverse/lychee:$LYCHEE_VERSION --verbose --config $LYCHEE_CONFIG"
CMD="lycheeverse/lychee:$LYCHEE_VERSION --verbose --root-dir /data"
# Add GitHub token if available
if [[ -n "$GITHUB_TOKEN" ]]; then
CMD="$CMD --github-token $GITHUB_TOKEN"
fi
if [[ "$LOCAL_LINKS_ONLY" == "true" ]]; then
CMD="$CMD --scheme file --include-fragments"
else
CMD="$CMD --config .github/scripts/lychee-config.toml"
fi
CMD="$CMD $TARGET"
# Determine if we should allocate a TTY

View File

@ -18,7 +18,7 @@ jobs:
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ github.token }}
run: ./.github/scripts/link-check.sh --relative-only
run: ./.github/scripts/link-check.sh --local-links-only
- name: Get modified files
if: github.event_name == 'pull_request'