Skip to content

Commit 6606a16

Browse files
authored
custom markdown list check action (#48)
Create custom markdown list check action, since 1. https://github.com/gaurav-nelson/github-action-markdown-link-check has been deprecated. Changed to https://github.com/tcort/github-action-markdown-link-check 2. Output error items at the end of log for better readability. Test runs: 1. [found error links](https://github.com/YanxuanLiu/spark-rapids-common/actions/runs/17041482748/job/48306080190?pr=4#step:4:286) 2. [all links valid](https://github.com/YanxuanLiu/spark-rapids-common/actions/runs/17056868836/job/48356049241?pr=4#step:4:183) --------- Signed-off-by: Yanxuan Liu <[email protected]>
1 parent 7b45825 commit 6606a16

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# A workflow to check markdown links
16+
name: markdown link check
17+
18+
on:
19+
pull_request:
20+
types: [opened, synchronize, reopened]
21+
22+
jobs:
23+
markdown-link-check:
24+
permissions:
25+
actions: read
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout code
29+
uses: NVIDIA/spark-rapids-common/checkout@main
30+
31+
- name: Run Markdown Link Check
32+
uses: NVIDIA/spark-rapids-common/markdown-link-check@main

markdown-link-check/action.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: 'Markdown Link Check'
16+
description: 'Check markdown links'
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Run markdown link check
22+
id: markdown-link-check
23+
uses: tcort/github-action-markdown-link-check@v1
24+
with:
25+
max-depth: -1
26+
use-verbose-mode: 'yes'
27+
base-branch: 'gh-pages'
28+
29+
- name: Summarize results
30+
shell: bash
31+
if: always()
32+
run: |
33+
echo "Summarizing markdown link check results"
34+
set -e
35+
36+
has_errors=0
37+
current_file=""
38+
files=()
39+
summaries=()
40+
in_summary_section=0 # 0: not in summary section, 1: in summary section
41+
42+
# Process output line by line
43+
while IFS= read -r line; do
44+
# Detect file header lines
45+
if [[ "$line" =~ ^FILE:[[:space:]]*(.+) ]]; then
46+
current_file="${BASH_REMATCH[1]}"
47+
in_summary_section=0
48+
49+
# Detect start of summary section (after "n links checked.")
50+
elif [[ "$line" =~ ^[[:space:]]*[0-9]+[[:space:]]*links[[:space:]]*checked\. ]]; then
51+
if [ -n "$current_file" ]; then
52+
in_summary_section=1
53+
# Start new summary for this file
54+
files+=("$current_file")
55+
summaries+=("Details:")
56+
fi
57+
58+
# Collect summary content
59+
elif [ $in_summary_section -eq 1 ] && [ -n "$current_file" ]; then
60+
# Add to current summary
61+
last_index=$((${#summaries[@]} - 1))
62+
summaries[$last_index]+=$'\n'"$line"
63+
64+
# Check if this line indicates an error
65+
if [[ "$line" =~ ERROR: ]] || [[ "$line" =~ \[✖\] ]]; then
66+
has_errors=1
67+
fi
68+
fi
69+
done <<< "$MLC_OUTPUT" # The output of the markdown link check action
70+
71+
# Output final conclusion
72+
if [ $has_errors -eq 0 ]; then
73+
echo "=========== All links are valid ==========="
74+
exit 0
75+
fi
76+
77+
echo "=========== Found error links ==========="
78+
# Output error details
79+
for i in "${!files[@]}"; do
80+
filename="${files[$i]}"
81+
summary="${summaries[$i]}"
82+
83+
# Only output summaries that contain errors
84+
if [[ "$summary" =~ ERROR: ]] || [[ "$summary" =~ \[✖\] ]]; then
85+
echo "File: $filename"
86+
# Preserve newlines in summary
87+
while IFS= read -r s_line; do
88+
echo " $s_line"
89+
done <<< "$summary"
90+
echo # Add empty line between files
91+
fi
92+
done

0 commit comments

Comments
 (0)