Skip to content

Commit ac921a7

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

File tree

5 files changed

+96
-6
lines changed

5 files changed

+96
-6
lines changed
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 "$(dirname "$ROOT_DIR")":/data -w /data $CMD

.github/workflows/build.yml

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

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,32 @@ 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 ${{ 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 }}
37+
38+
- name: Link check - all links (all files)
39+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
1640
env:
1741
GITHUB_TOKEN: ${{ github.token }}
1842
run: ./.github/scripts/link-check.sh

0 commit comments

Comments
 (0)