Skip to content

Commit 8c6089a

Browse files
authored
Stop lychee from causing so many PR failures (#2002)
1 parent 8add72d commit 8c6089a

File tree

5 files changed

+100
-6
lines changed

5 files changed

+100
-6
lines changed

.github/scripts/.lychee-relative.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Check link anchors
2+
include_fragments = true
3+
4+
# For relative links only, we exclude all external URLs
5+
exclude = [
6+
"^https?://.*",
7+
]
File renamed without changes.

.github/scripts/link-check.sh

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,51 @@ 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=".github/scripts/.lychee.toml"
35+
36+
if [[ "$RELATIVE_ONLY" == "true" ]]; then
37+
LYCHEE_CONFIG=".github/scripts/.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
15-
CMD="lycheeverse/lychee:$LYCHEE_VERSION --verbose --config $(basename "$LYCHEE_CONFIG")"
45+
CMD="lycheeverse/lychee:$LYCHEE_VERSION --verbose --config $LYCHEE_CONFIG"
1646

1747
# Add GitHub token if available
1848
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 "$ROOT_DIR":/data -w /data $CMD

.github/workflows/build.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
pull_request:
99
merge_group:
1010
workflow_dispatch:
11+
schedule:
12+
# Run daily at 7:30 AM UTC
13+
- cron: '30 7 * * *'
1114

1215
permissions:
1316
contents: read
@@ -199,3 +202,31 @@ jobs:
199202
)
200203
)
201204
run: exit 1 # fail
205+
206+
workflow-notification:
207+
permissions:
208+
contents: read
209+
issues: write
210+
if: github.event_name == 'schedule' && always()
211+
needs:
212+
- build
213+
- test
214+
- integration-test
215+
- link-check
216+
- markdown-lint-check
217+
- misspell-check
218+
- shell-script-check
219+
- publish-snapshots
220+
uses: ./.github/workflows/reusable-workflow-notification.yml
221+
with:
222+
success: >-
223+
${{
224+
needs.build.result == 'success' &&
225+
needs.test.result == 'success' &&
226+
needs.integration-test.result == 'success' &&
227+
needs.link-check.result == 'success' &&
228+
needs.markdown-lint-check.result == 'success' &&
229+
needs.misspell-check.result == 'success' &&
230+
needs.shell-script-check.result == 'success' &&
231+
needs.publish-snapshots.result == 'success'
232+
}}

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,35 @@ 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+
- name: Link check - relative links (all files)
18+
if: github.event_name == 'pull_request'
19+
env:
20+
GITHUB_TOKEN: ${{ github.token }}
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 origin/${{ github.base_ref }} HEAD)
28+
# Using lychee's default extension filter here to match when it runs against all files
29+
modified_files=$(git diff --name-only $merge_base...${{ github.event.pull_request.head.sha }} \
30+
| grep -E '\.(md|mkd|mdx|mdown|mdwn|mkdn|mkdown|markdown|html|htm|txt)$' \
31+
| tr '\n' ' ' || true)
32+
echo "files=$modified_files" >> $GITHUB_OUTPUT
33+
echo "Modified files: $modified_files"
34+
35+
- name: Link check - all links (modified files only)
36+
if: github.event_name == 'pull_request' && steps.modified-files.outputs.files != ''
37+
env:
38+
GITHUB_TOKEN: ${{ github.token }}
39+
run: ./.github/scripts/link-check.sh ${{ steps.modified-files.outputs.files }}
40+
41+
- name: Link check - all links (all files)
42+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
1643
env:
1744
GITHUB_TOKEN: ${{ github.token }}
1845
run: ./.github/scripts/link-check.sh

0 commit comments

Comments
 (0)