diff --git a/.github/actions/markdown-link-checker/action.yaml b/.github/actions/markdown-link-checker/action.yaml new file mode 100644 index 0000000..7e17a42 --- /dev/null +++ b/.github/actions/markdown-link-checker/action.yaml @@ -0,0 +1,49 @@ +name: Markdown Link Checker +description: Checks all Markdown files for broken links +inputs: + github-token: + description: GitHub token (not used, but kept for interface compatibility) + required: false + args: + description: Arguments to pass to markdown-link-check + required: false + default: "--quiet --retry" + +runs: + using: "composite" + steps: + - name: Install markdown-link-check + shell: bash + run: npm install -g markdown-link-check + + - name: Run link check on all Markdown files + shell: bash + run: | + set -euo pipefail + echo "🔍 Scanning all Markdown files for broken links..." + failed=0 + total_dead_links=0 + + while IFS= read -r -d '' file; do + echo "------------------------------------------------------------" + echo "📄 Checking: $file" + output=$(markdown-link-check ${{ inputs.args }} "$file" 2>&1) + echo "$output" + + if echo "$output" | grep -q '✖'; then + num_file_dead_links=$(echo "$output" | grep '✖' | wc -l) + echo "❌ $num_file_dead_links broken links in $file" + total_dead_links=$((total_dead_links + num_file_dead_links)) + failed=1 + else + echo "✅ No broken links in $file" + fi + done < <(find . -type f -name "*.md" -print0) + + echo "------------------------------------------------------------" + if [ "$failed" -ne 0 ]; then + echo "❌ Total broken links found: $total_dead_links" + exit 1 + else + echo "✅ All Markdown files passed link checks." + fi diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 731d5b8..7c8537f 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -34,6 +34,12 @@ jobs: with: go-version: ^1 + - name: Run markdown link checker + uses: ./.github/actions/markdown-link-checker + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + args: "--quiet --retry" + - name: Restore pre-commit cache id: cache-restore uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4