diff --git a/.github/workflows/lychee.yml b/.github/workflows/lychee.yml new file mode 100644 index 0000000000..257b7dded9 --- /dev/null +++ b/.github/workflows/lychee.yml @@ -0,0 +1,76 @@ +name: 🍈 Lychee + +on: [pull_request] + +concurrency: + group: lychee-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + check-links: + name: Check links + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - name: 🍈 Lychee Link Checker + id: lychee + uses: lycheeverse/lychee-action@v2 + with: + fail: false + output: ../lychee/out.md + args: > + --cache + --max-cache-age 3h + --verbose + --no-progress + --accept 200,201,204,304,403,429 + --timeout 20 + --max-retries 5 + --retry-wait-time 5 + --max-concurrency 16 + --exclude 'http://localhost.*' + --exclude 'https://localhost.*' + --exclude 'https://dev.mysql.com/.*' + --exclude 'https://www.mysql.com/.*' + --exclude 'https://www.gnu.org/.*' + --exclude 'https://www.cockroachlabs.com/.*' + --exclude '^/.*' + './**/*.md' './**/*.mdx' + workingDirectory: "content" + env: + GITHUB_TOKEN: ${{ secrets.github_token }} + + - name: 📝 Clean up Lychee Report + if: ${{ always() && github.event.pull_request.head.repo.fork == false }} + run: | + if [ -f "lychee/out.md" ]; then + # Read the original output + ORIGINAL=$(cat lychee/out.md) + + # Create formatted output + cat > lychee/formatted.md << 'EOF' + ## 🍈 Lychee Link Check Report + + > **Note:** Links are cached for 3 hours to avoid unnecessary requests, and speed up consecutive runs. + + ### 📊 Results Overview + + EOF + + # Append the original content with title replacement + echo "$ORIGINAL" | sed 's/^# Summary$//' | sed 's/^## Summary$//' >> lychee/formatted.md + fi + + - name: 📝 Comment Broken Links + if: ${{ always() && github.event.pull_request.head.repo.fork == false }} + uses: peter-evans/create-or-update-comment@v4 + with: + issue-number: ${{ github.event.pull_request.number }} + body-path: lychee/formatted.md + + - name: 🚫 Fail if broken links found + if: ${{ steps.lychee.outputs.exit_code != 0 }} + run: exit ${{ steps.lychee.outputs.exit_code }}