From efc967ee57d1e683b5fdd47c2c16bf1e7870aded Mon Sep 17 00:00:00 2001 From: swarnabhasinha Date: Wed, 18 Dec 2024 19:13:26 +0530 Subject: [PATCH] feat(ci): validate link workflow --- .github/config/lychee.toml | 18 ++++++++++++ .github/workflows/check-broken-links.yml | 36 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/config/lychee.toml create mode 100644 .github/workflows/check-broken-links.yml diff --git a/.github/config/lychee.toml b/.github/config/lychee.toml new file mode 100644 index 00000000..e8378efc --- /dev/null +++ b/.github/config/lychee.toml @@ -0,0 +1,18 @@ +# Ignore certain URLs or patterns +exclude = [ + "localhost", # Ignore localhost links + "example.com", # Ignore example domains + "http://127.0.0.1" # Ignore local IP links +] + +# Retry failed links before reporting +retry = 3 + +# Timeout for links (in seconds) +timeout = 10 + +# Acceptable status codes +accept = [200, 403] + +# Maximum concurrency for checking links +max_concurrency = 10 diff --git a/.github/workflows/check-broken-links.yml b/.github/workflows/check-broken-links.yml new file mode 100644 index 00000000..08feafd5 --- /dev/null +++ b/.github/workflows/check-broken-links.yml @@ -0,0 +1,36 @@ +name: Check Broken Links + +on: + pull_request: + paths: + - "**/*.md" + - "**/*.mdx" + - "**/*.html" + +jobs: + link-check: + name: Validate Links + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Install Lychee + run: | + wget -q https://github.com/lycheeverse/lychee/releases/latest/download/lychee-linux-x86_64.tar.gz + tar -xzf lychee-linux-x86_64.tar.gz + sudo mv lychee /usr/local/bin/ + + - name: Run Link Checker + run: | + lychee \ + --config .github/config/lychee.toml \ + --accept=200,403 \ + --no-progress \ + '**/*.md' '**/*.mdx' '**/*.html' + + - name: Report Failure on Broken Links + if: failure() + run: | + echo "::error:: Broken links detected. Please fix them before merging."