From 32f4f6056565986b6d63d1a154623b55bd28321f Mon Sep 17 00:00:00 2001 From: kairvee <145572028+kairveeehh@users.noreply.github.com> Date: Thu, 29 Jan 2026 08:00:56 +0000 Subject: [PATCH] CI: add link validation Signed-off-by: kairvee <145572028+kairveeehh@users.noreply.github.com> --- .github/workflows/link-validation.yml | 36 +++++++++++++++++++++++++++ scripts/remove-broken-links.sh | 25 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/workflows/link-validation.yml create mode 100644 scripts/remove-broken-links.sh diff --git a/.github/workflows/link-validation.yml b/.github/workflows/link-validation.yml new file mode 100644 index 000000000..2a3076d8d --- /dev/null +++ b/.github/workflows/link-validation.yml @@ -0,0 +1,36 @@ +name: Link Validation (Weekly Check) + +on: + schedule: + - cron: '0 6 * * 1' # Mondays at 06:00 UTC + workflow_dispatch: # Manual trigger + +jobs: + validate-links: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Set up Go + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.2.0 + with: + go-version: stable + + - name: Set up mdox + run: | + go install github.com/bwplotka/mdox@latest + export PATH="$(go env GOPATH)/bin:$PATH" + echo "PATH=$PATH" >> $GITHUB_ENV + + - name: Check for broken links (no file modification) + run: | + export PATH="$(go env GOPATH)/bin:$PATH" + md_files=$(find . -type d -name node_modules -prune -o -name '*.md' -print) + mdox fmt --links.validate --check $md_files > link-report.txt 2>&1 || true + + - name: Upload link check report + uses: actions/upload-artifact@v4 + with: + name: link-report + path: link-report.txt diff --git a/scripts/remove-broken-links.sh b/scripts/remove-broken-links.sh new file mode 100644 index 000000000..2bc605b47 --- /dev/null +++ b/scripts/remove-broken-links.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +echo "Running link validation and removing broken links..." + +# Run mdox and capture output +output=$(mdox fmt --links.validate --links.validate.config-file=.mdoxlintrc.yaml --check $(find . -name "*.md" -not -path "./node_modules/*" -not -path "./.next/*" -not -path "./.git/*") 2>&1 || true) + +# Parse broken HTTP/HTTPS links and remove them +echo "$output" | grep -E '"https?://[^"]*" not accessible' | while read -r line; do + file=$(echo "$line" | cut -d: -f1) + url=$(echo "$line" | grep -oP '"https?://[^"]*"' | tr -d '"') + + if [ -f "$file" ] && [ -n "$url" ]; then + echo "Removing broken link: $url from $file" + # Escape special characters for sed + escaped_url=$(echo "$url" | sed 's/[&/\]/\\&/g') + # Remove the link but keep the text if it's a markdown link [text](url) + sed -i -E "s|\[([^\]]*)\]\($escaped_url\)|\1|g" "$file" + # Remove plain URLs + sed -i "s|$escaped_url||g" "$file" + fi +done + +echo "Broken link removal complete"