Skip to content

Commit 10b3c95

Browse files
committed
Stop lychee from causing so many PR failures
1 parent 01680d8 commit 10b3c95

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

.github/scripts/link-check.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,42 @@ set -e
55
export MSYS_NO_PATHCONV=1 # for Git Bash on Windows
66

77
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8-
LYCHEE_CONFIG="$SCRIPT_DIR/../../.lychee.toml"
8+
ROOT_DIR="$SCRIPT_DIR/../.."
99
DEPENDENCIES_DOCKERFILE="$SCRIPT_DIR/dependencies.dockerfile"
1010

11+
# Parse command line arguments
12+
RELATIVE_ONLY=false
13+
MODIFIED_FILES=""
14+
15+
while [[ $# -gt 0 ]]; do
16+
case $1 in
17+
--relative-only)
18+
RELATIVE_ONLY=true
19+
shift
20+
;;
21+
*)
22+
# Treat any other arguments as file paths
23+
MODIFIED_FILES="$MODIFIED_FILES $1"
24+
shift
25+
;;
26+
esac
27+
done
28+
1129
# Extract lychee version from dependencies.dockerfile
1230
LYCHEE_VERSION=$(grep "FROM lycheeverse/lychee:" "$DEPENDENCIES_DOCKERFILE" | sed 's/.*FROM lycheeverse\/lychee:\([^ ]*\).*/\1/')
1331

32+
# Determine target files/directories and config file
33+
TARGET="."
34+
LYCHEE_CONFIG="$SCRIPT_DIR/.lychee.toml"
35+
36+
if [[ "$RELATIVE_ONLY" == "true" ]]; then
37+
LYCHEE_CONFIG="$SCRIPT_DIR/.lychee-relative.toml"
38+
fi
39+
40+
if [[ -n "$MODIFIED_FILES" ]]; then
41+
TARGET="$MODIFIED_FILES"
42+
fi
43+
1444
# Build the lychee command with optional GitHub token
1545
CMD="lycheeverse/lychee:$LYCHEE_VERSION --verbose --config $(basename "$LYCHEE_CONFIG")"
1646

@@ -19,8 +49,7 @@ if [[ -n "$GITHUB_TOKEN" ]]; then
1949
CMD="$CMD --github-token $GITHUB_TOKEN"
2050
fi
2151

22-
# Add the target directory
23-
CMD="$CMD ."
52+
CMD="$CMD $TARGET"
2453

2554
# Determine if we should allocate a TTY
2655
DOCKER_FLAGS="--rm --init"
@@ -32,4 +61,4 @@ fi
3261

3362
# Run lychee with proper signal handling
3463
# shellcheck disable=SC2086
35-
exec docker run $DOCKER_FLAGS -v "$(dirname "$LYCHEE_CONFIG")":/data -w /data $CMD
64+
exec docker run $DOCKER_FLAGS -v "$(dirname "$ROOT_DIR")":/data -w /data $CMD

.github/workflows/reusable-link-check.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,26 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
14+
with:
15+
fetch-depth: 0 # needed for merge-base below
1416

15-
- name: Link check
17+
# check relative links across all files since they could link to files that are modified in the PR
18+
- name: Link check - relative links (all files)
1619
env:
1720
GITHUB_TOKEN: ${{ github.token }}
18-
run: ./.github/scripts/link-check.sh
21+
run: ./.github/scripts/link-check.sh --relative-only
22+
23+
- name: Get modified files
24+
if: github.event_name == 'pull_request'
25+
id: modified-files
26+
run: |
27+
merge_base=$(git merge-base ${{ github.base_ref }} ${{ github.event.pull_request.head.sha }})
28+
modified_files=$(git diff --name-only $merge_base...${{ github.event.pull_request.head.sha }} | tr '\n' ' ')
29+
echo "files=$modified_files" >> $GITHUB_OUTPUT
30+
echo "Modified files: $modified_files"
31+
32+
- name: Link check - all links (modified files only)
33+
if: github.event_name == 'pull_request' && steps.modified-files.outputs.files != ''
34+
env:
35+
GITHUB_TOKEN: ${{ github.token }}
36+
run: ./.github/scripts/link-check.sh ${{ steps.modified-files.outputs.files }}

0 commit comments

Comments
 (0)