Link Checker #132
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Link Checker | |
on: | |
workflow_run: | |
workflows: [Build Documentation] | |
types: [completed] | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
LinkChecker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download docs artifact from the last successful workflow | |
if: steps.cache-docs.outputs.cache-hit != 'true' | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
workflow: antora_build.yml # Name of the workflow that uploads the artifact | |
name: docs | |
path: docs | |
workflow_conclusion: success | |
branch: main | |
- name: Restore Lychee cache | |
uses: actions/cache@v4 | |
with: | |
path: .lycheecache | |
key: cache-lychee-${{ github.sha }} | |
restore-keys: cache-lychee- | |
- name: Run Lychee on docs folder | |
uses: lycheeverse/[email protected] | |
with: | |
args: | | |
--no-progress | |
--cache --max-cache-age 1d | |
--max-redirects 5 | |
'./docs/**/*.html' | |
format: markdown | |
output: link_checker_report.md | |
fail: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Calculate correct links percentage | |
id: calculate_percentage | |
run: | | |
# Extract values from the link checker report | |
report_file="link_checker_report.md" | |
total=$(grep '🔍 Total' "$report_file" | awk -F'|' '{print $3}' | xargs) | |
successful=$(grep '✅ Successful' "$report_file" | awk -F'|' '{print $3}' | xargs) | |
excluded=$(grep '👻 Excluded' "$report_file" | awk -F'|' '{print $3}' | xargs) | |
# Calculate the total correct, incorrect links (errors + timeouts) | |
correct=$((successful + excluded)) | |
incorrect=$((total - correct)) | |
# Calculate the percentage of correct links | |
if [ "$total" -gt 0 ]; then | |
percentage=$(echo "scale=2; $correct * 100 / $total" | bc) | |
else | |
percentage=100 | |
fi | |
echo "Links: $percentage% correct (Correct: $correct, Incorrect: $incorrect)" | |
# Save the percentage and totals to the environment | |
echo "CORRECT_LINKS_PERCENTAGE=$percentage" >> $GITHUB_ENV | |
echo "CORRECT=$correct" >> $GITHUB_ENV | |
echo "INCORRECT=$incorrect" >> $GITHUB_ENV | |
- name: Update dynamic badge for correct links percentage | |
if: ${{ env.GIST_AUTH != '' && env.GIST_ID != '' }} | |
env: | |
GIST_AUTH: ${{ secrets.GIST_AUTH }} | |
GIST_ID: ${{ vars.GIST_ID }} | |
uses: schneegans/[email protected] | |
with: | |
auth: ${{ env.GIST_AUTH }} | |
gistID: ${{ env.GIST_ID }} | |
filename: link_check_percentage.json | |
label: "🔗 Links" | |
message: "${{ env.CORRECT_LINKS_PERCENTAGE }}% correct (Correct: ${{ env.CORRECT }}, Incorrect: ${{ env.INCORRECT }})" | |
valColorRange: ${{ env.CORRECT_LINKS_PERCENTAGE }} | |
minColorRange: 0 | |
maxColorRange: 100 |