From c742795c3366906f181460a6e404152a8918605d Mon Sep 17 00:00:00 2001 From: Rafael Riki Ogawa Osiro Date: Fri, 11 Jul 2025 19:52:55 -0300 Subject: [PATCH 1/6] feat: add htmlproofer plugin to check the links in project --- .github/workflows/htmlproofer.yml | 199 ++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 12 +- mkdocs.yml | 14 +++ requirements.txt | 3 +- 4 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/htmlproofer.yml diff --git a/.github/workflows/htmlproofer.yml b/.github/workflows/htmlproofer.yml new file mode 100644 index 0000000000..1e28a90bd8 --- /dev/null +++ b/.github/workflows/htmlproofer.yml @@ -0,0 +1,199 @@ +# .github/workflows/check-links-pr.yml + +name: Check Links in PR + +on: + pull_request: + branches: + - main + paths: + - 'docs/**' + - 'mkdocs.yml' + - 'requirements.txt' + +jobs: + check-links: + runs-on: ubuntu-latest + name: Verify documentation links + + steps: + - name: Checkout PR + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + cache: 'pip' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools wheel + pip install -r requirements.txt + pip install mkdocs-htmlproofer-plugin + + - name: Check links + id: linkcheck + run: | + echo "### 🔍 Checking documentation links" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + # Run build and capture output + if mkdocs build 2>&1 | tee /tmp/build_output.txt; then + echo "✅ **All links are working correctly!**" >> $GITHUB_STEP_SUMMARY + echo "status=success" >> $GITHUB_OUTPUT + else + echo "❌ **Broken links found!**" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "```" >> $GITHUB_STEP_SUMMARY + grep -E "(HTMLProofer:|External link|internally linking|anchor)" /tmp/build_output.txt >> $GITHUB_STEP_SUMMARY || true + echo "```" >> $GITHUB_STEP_SUMMARY + echo "status=failure" >> $GITHUB_OUTPUT + exit 1 + fi + + - name: Comment PR - Success + if: steps.linkcheck.outputs.status == 'success' + uses: actions/github-script@v7 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + // Find previous bot comments + const comments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + + const botComment = comments.data.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('### 🔍 Link Verification') + ); + + const body = `### 🔍 Link Verification + + ✅ **All links are working correctly!** + + _Last checked: ${new Date().toLocaleString('en-US', { timeZone: 'America/New_York' })}_`; + + // Update or create comment + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: body + }); + } else { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + } + + - name: Comment PR - Failure + if: failure() && steps.linkcheck.outputs.status == 'failure' + uses: actions/github-script@v7 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + // Read build output + const fs = require('fs'); + let buildOutput = ''; + try { + buildOutput = fs.readFileSync('/tmp/build_output.txt', 'utf8'); + // Extract only relevant lines + const lines = buildOutput.split('\n'); + const relevantLines = lines.filter(line => + line.includes('HTMLProofer:') || + line.includes('External link') || + line.includes('internally linking') || + line.includes('anchor') + ); + buildOutput = relevantLines.slice(0, 20).join('\n'); // Limit to 20 lines + } catch (e) { + buildOutput = 'Error reading broken links details.'; + } + + // Find previous comments + const comments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + + const botComment = comments.data.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('### 🔍 Link Verification') + ); + + const body = `### 🔍 Link Verification + + ❌ **Broken links found!** + + Please fix the following links before merging: + +
+ Click to see details + + \`\`\` + ${buildOutput} + \`\`\` + +
+ + **How to fix:** + 1. Run \`mkdocs build\` locally to see all errors + 2. Fix the broken links + 3. Commit the fixes + + _Last checked: ${new Date().toLocaleString('en-US', { timeZone: 'America/New_York' })}_`; + + // Update or create comment + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: body + }); + } else { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + } + + # Additional job: quick check with markdown-link-check + quick-check: + runs-on: ubuntu-latest + name: Quick markdown link check + + steps: + - name: Checkout PR + uses: actions/checkout@v4 + + - name: Check links with markdown-link-check + uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + folder-path: 'docs' + file-extension: '.md' + check-modified-files-only: 'yes' # Only check modified files in PR + use-quiet-mode: 'yes' + use-verbose-mode: 'no' + config-file: | + { + "ignorePatterns": [ + { "pattern": "^http://localhost" }, + { "pattern": "^http://127.0.0.1" }, + { "pattern": "^#" } + ], + "timeout": "20s", + "retryOn429": true, + "retryCount": 3, + "aliveStatusCodes": [200, 206, 403] + } \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6342971778..0c7fab1308 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,14 @@ repos: - repo: https://github.com/crate-ci/typos - rev: v1.33.1 + rev: v1.34.0 hooks: - id: typos - args: ["--config", ".typos.toml"] \ No newline at end of file + args: ["--config", ".typos.toml"] + - repo: local + hooks: + - id: check-docs-links + name: Check documentation links + entry: mkdocs build + language: system + files: '^docs/.*\.(md|markdown)$' + pass_filenames: false \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 33845a989b..303d2143ee 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -285,6 +285,20 @@ plugins: - components/anomaly-support/* - components/comparators/* - components/general-props/* + - htmlproofer: + raise_error: False + verbose: True + validate_external_urls: True + validate_internal_urls: True + ignore_urls: + - "http://localhost.*" + - "http://127.0.0.1.*" + - "#" + - "https://your-company.atlan.com" + - "mailto://hello@qualytics.co" + - "../print_page/" + ignore_missing_images: False + output_file: "broken_links.txt" - git-revision-date-localized - include-markdown - macros diff --git a/requirements.txt b/requirements.txt index f2db8880b9..d027a3be03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,9 @@ -mkdocs-material==9.5.50 mkdocs-exclude==1.0.2 mkdocs-git-revision-date-localized-plugin==1.2.6 +mkdocs-htmlproofer-plugin==1.3.0 mkdocs-include-markdown-plugin==6.0.2 mkdocs-macros-plugin==1.3.7 +mkdocs-material==9.5.50 mkdocs-print-site-plugin==2.7.3 mkdocs-redirects==1.2.2 pre-commit==3.8.0 \ No newline at end of file From 2ac33f9da905da1d5cb74812f00e57907e9cec4f Mon Sep 17 00:00:00 2001 From: Rafael Riki Ogawa Osiro Date: Fri, 11 Jul 2025 19:57:57 -0300 Subject: [PATCH 2/6] fix: tests --- .github/workflows/htmlproofer.yml | 193 +++++------------------------- 1 file changed, 29 insertions(+), 164 deletions(-) diff --git a/.github/workflows/htmlproofer.yml b/.github/workflows/htmlproofer.yml index 1e28a90bd8..a9b180b7f7 100644 --- a/.github/workflows/htmlproofer.yml +++ b/.github/workflows/htmlproofer.yml @@ -1,199 +1,64 @@ -# .github/workflows/check-links-pr.yml +# .github/workflows/check-links.yml -name: Check Links in PR +name: Check Documentation Links on: pull_request: - branches: - - main + branches: [main] paths: - 'docs/**' - 'mkdocs.yml' - 'requirements.txt' + push: + branches: [main] + workflow_dispatch: # Permite executar manualmente jobs: check-links: runs-on: ubuntu-latest - name: Verify documentation links + name: Check links steps: - - name: Checkout PR + - name: Checkout repository uses: actions/checkout@v4 - - name: Set up Python + - name: Setup Python 3.11 uses: actions/setup-python@v5 with: python-version: '3.11' cache: 'pip' - - name: Install dependencies + - name: Install MkDocs and plugins run: | - python -m pip install --upgrade pip setuptools wheel + python -m pip install --upgrade pip pip install -r requirements.txt pip install mkdocs-htmlproofer-plugin - - name: Check links + - name: Run link checker id: linkcheck run: | - echo "### 🔍 Checking documentation links" >> $GITHUB_STEP_SUMMARY + echo "## 🔍 Link Check Results" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - # Run build and capture output - if mkdocs build 2>&1 | tee /tmp/build_output.txt; then - echo "✅ **All links are working correctly!**" >> $GITHUB_STEP_SUMMARY - echo "status=success" >> $GITHUB_OUTPUT + # Executar mkdocs build e capturar resultado + if mkdocs build 2>&1 | tee build_log.txt; then + echo "✅ **All links are valid!**" >> $GITHUB_STEP_SUMMARY + echo "link_check_passed=true" >> $GITHUB_OUTPUT else - echo "❌ **Broken links found!**" >> $GITHUB_STEP_SUMMARY + echo "❌ **Broken links detected!**" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - echo "```" >> $GITHUB_STEP_SUMMARY - grep -E "(HTMLProofer:|External link|internally linking|anchor)" /tmp/build_output.txt >> $GITHUB_STEP_SUMMARY || true - echo "```" >> $GITHUB_STEP_SUMMARY - echo "status=failure" >> $GITHUB_OUTPUT + echo "### Errors found:" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + grep -E "(HTMLProofer:|External link|internally linking)" build_log.txt >> $GITHUB_STEP_SUMMARY || true + echo '```' >> $GITHUB_STEP_SUMMARY + echo "link_check_passed=false" >> $GITHUB_OUTPUT exit 1 fi - - name: Comment PR - Success - if: steps.linkcheck.outputs.status == 'success' - uses: actions/github-script@v7 + - name: Upload build log + if: failure() + uses: actions/upload-artifact@v4 with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - // Find previous bot comments - const comments = await github.rest.issues.listComments({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo - }); - - const botComment = comments.data.find(comment => - comment.user.type === 'Bot' && - comment.body.includes('### 🔍 Link Verification') - ); - - const body = `### 🔍 Link Verification - - ✅ **All links are working correctly!** - - _Last checked: ${new Date().toLocaleString('en-US', { timeZone: 'America/New_York' })}_`; - - // Update or create comment - if (botComment) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: body - }); - } else { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: body - }); - } - - - name: Comment PR - Failure - if: failure() && steps.linkcheck.outputs.status == 'failure' - uses: actions/github-script@v7 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - // Read build output - const fs = require('fs'); - let buildOutput = ''; - try { - buildOutput = fs.readFileSync('/tmp/build_output.txt', 'utf8'); - // Extract only relevant lines - const lines = buildOutput.split('\n'); - const relevantLines = lines.filter(line => - line.includes('HTMLProofer:') || - line.includes('External link') || - line.includes('internally linking') || - line.includes('anchor') - ); - buildOutput = relevantLines.slice(0, 20).join('\n'); // Limit to 20 lines - } catch (e) { - buildOutput = 'Error reading broken links details.'; - } - - // Find previous comments - const comments = await github.rest.issues.listComments({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo - }); - - const botComment = comments.data.find(comment => - comment.user.type === 'Bot' && - comment.body.includes('### 🔍 Link Verification') - ); - - const body = `### 🔍 Link Verification - - ❌ **Broken links found!** - - Please fix the following links before merging: - -
- Click to see details - - \`\`\` - ${buildOutput} - \`\`\` - -
- - **How to fix:** - 1. Run \`mkdocs build\` locally to see all errors - 2. Fix the broken links - 3. Commit the fixes - - _Last checked: ${new Date().toLocaleString('en-US', { timeZone: 'America/New_York' })}_`; - - // Update or create comment - if (botComment) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: body - }); - } else { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: body - }); - } - - # Additional job: quick check with markdown-link-check - quick-check: - runs-on: ubuntu-latest - name: Quick markdown link check - - steps: - - name: Checkout PR - uses: actions/checkout@v4 - - - name: Check links with markdown-link-check - uses: gaurav-nelson/github-action-markdown-link-check@v1 - with: - folder-path: 'docs' - file-extension: '.md' - check-modified-files-only: 'yes' # Only check modified files in PR - use-quiet-mode: 'yes' - use-verbose-mode: 'no' - config-file: | - { - "ignorePatterns": [ - { "pattern": "^http://localhost" }, - { "pattern": "^http://127.0.0.1" }, - { "pattern": "^#" } - ], - "timeout": "20s", - "retryOn429": true, - "retryCount": 3, - "aliveStatusCodes": [200, 206, 403] - } \ No newline at end of file + name: link-check-log + path: build_log.txt + retention-days: 7 \ No newline at end of file From 78438b089f5e3db2e6637e88013bb95058058c2f Mon Sep 17 00:00:00 2001 From: Rafael Riki Ogawa Osiro Date: Fri, 11 Jul 2025 20:07:59 -0300 Subject: [PATCH 3/6] chore: update the script --- .github/workflows/htmlproofer.yml | 127 +++++++++++++++++++++++++++--- 1 file changed, 115 insertions(+), 12 deletions(-) diff --git a/.github/workflows/htmlproofer.yml b/.github/workflows/htmlproofer.yml index a9b180b7f7..84ebc4d60b 100644 --- a/.github/workflows/htmlproofer.yml +++ b/.github/workflows/htmlproofer.yml @@ -11,7 +11,7 @@ on: - 'requirements.txt' push: branches: [main] - workflow_dispatch: # Permite executar manualmente + workflow_dispatch: jobs: check-links: @@ -21,6 +21,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Setup Python 3.11 uses: actions/setup-python@v5 @@ -34,31 +36,132 @@ jobs: pip install -r requirements.txt pip install mkdocs-htmlproofer-plugin - - name: Run link checker + - name: Update mkdocs.yml to fix warnings + run: | + cp mkdocs.yml mkdocs.yml.bak + + sed -i '/ignore_missing_images:/d' mkdocs.yml + sed -i '/output_file:/d' mkdocs.yml + sed -i '/validate_internal_urls:/d' mkdocs.yml + sed -i '/verbose:/d' mkdocs.yml + + - name: Run link checker with strict mode id: linkcheck run: | echo "## 🔍 Link Check Results" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - # Executar mkdocs build e capturar resultado - if mkdocs build 2>&1 | tee build_log.txt; then + mkdocs build 2>&1 | tee build_log.txt + BUILD_EXIT_CODE=${PIPESTATUS[0]} + + BROKEN_LINKS=$(grep -c "invalid url" build_log.txt || echo "0") + MISSING_ANCHORS=$(grep -c "does not contain an anchor" build_log.txt || echo "0") + MISSING_FILES=$(grep -c "is not found among documentation files" build_log.txt || echo "0") + CONFIG_WARNINGS=$(grep -c "Unrecognised configuration name" build_log.txt || echo "0") + + TOTAL_ISSUES=$((BROKEN_LINKS + MISSING_ANCHORS + MISSING_FILES)) + + if [ $TOTAL_ISSUES -eq 0 ] && [ $BUILD_EXIT_CODE -eq 0 ]; then echo "✅ **All links are valid!**" >> $GITHUB_STEP_SUMMARY echo "link_check_passed=true" >> $GITHUB_OUTPUT + FINAL_EXIT_CODE=0 else - echo "❌ **Broken links detected!**" >> $GITHUB_STEP_SUMMARY + echo "❌ **Issues found!**" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + if [ $BROKEN_LINKS -gt 0 ]; then + echo "### 🔗 Broken Links: $BROKEN_LINKS" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + grep "invalid url" build_log.txt >> $GITHUB_STEP_SUMMARY || true + echo '```' >> $GITHUB_STEP_SUMMARY + fi + + if [ $MISSING_ANCHORS -gt 0 ]; then + echo "### ⚓ Missing Anchors: $MISSING_ANCHORS" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + grep "does not contain an anchor" build_log.txt >> $GITHUB_STEP_SUMMARY || true + echo '```' >> $GITHUB_STEP_SUMMARY + fi + + if [ $MISSING_FILES -gt 0 ]; then + echo "### 📄 Missing Files: $MISSING_FILES" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + grep "is not found among documentation files" build_log.txt >> $GITHUB_STEP_SUMMARY || true + echo '```' >> $GITHUB_STEP_SUMMARY + fi + echo "" >> $GITHUB_STEP_SUMMARY - echo "### Errors found:" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - grep -E "(HTMLProofer:|External link|internally linking)" build_log.txt >> $GITHUB_STEP_SUMMARY || true - echo '```' >> $GITHUB_STEP_SUMMARY + echo "**Total issues: $TOTAL_ISSUES**" >> $GITHUB_STEP_SUMMARY + echo "link_check_passed=false" >> $GITHUB_OUTPUT - exit 1 + FINAL_EXIT_CODE=1 fi + + # Restaurar mkdocs.yml original + mv mkdocs.yml.bak mkdocs.yml + + exit $FINAL_EXIT_CODE - name: Upload build log - if: failure() + if: always() uses: actions/upload-artifact@v4 with: name: link-check-log path: build_log.txt - retention-days: 7 \ No newline at end of file + retention-days: 7 + + - name: Comment PR with results + if: github.event_name == 'pull_request' && always() + uses: actions/github-script@v7 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const fs = require('fs'); + const buildLog = fs.readFileSync('build_log.txt', 'utf8'); + + const brokenLinks = (buildLog.match(/invalid url/g) || []).length; + const missingAnchors = (buildLog.match(/does not contain an anchor/g) || []).length; + const missingFiles = (buildLog.match(/is not found among documentation files/g) || []).length; + const totalIssues = brokenLinks + missingAnchors + missingFiles; + + let body = '### 🔍 Link Check Results\n\n'; + + if (totalIssues === 0) { + body += '✅ **All links are valid!**\n'; + } else { + body += `❌ **Found ${totalIssues} issues:**\n\n`; + + if (brokenLinks > 0) body += `- 🔗 Broken links: ${brokenLinks}\n`; + if (missingAnchors > 0) body += `- ⚓ Missing anchors: ${missingAnchors}\n`; + if (missingFiles > 0) body += `- 📄 Missing files: ${missingFiles}\n`; + + body += '\n**Please fix these issues before merging.**\n'; + body += '\nRun `mkdocs build` locally to see detailed errors.\n'; + } + + const comments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + + const botComment = comments.data.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('### 🔍 Link Check Results') + ); + + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: body + }); + } else { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + } \ No newline at end of file From 764ec28f59c399742eac60ced28595e0a3b8ca89 Mon Sep 17 00:00:00 2001 From: Rafael Riki Ogawa Osiro Date: Fri, 11 Jul 2025 20:12:22 -0300 Subject: [PATCH 4/6] fix: script --- .github/workflows/htmlproofer.yml | 124 +++--------------------------- mkdocs.yml | 2 +- 2 files changed, 11 insertions(+), 115 deletions(-) diff --git a/.github/workflows/htmlproofer.yml b/.github/workflows/htmlproofer.yml index 84ebc4d60b..fa3e3b3394 100644 --- a/.github/workflows/htmlproofer.yml +++ b/.github/workflows/htmlproofer.yml @@ -21,8 +21,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Setup Python 3.11 uses: actions/setup-python@v5 @@ -36,132 +34,30 @@ jobs: pip install -r requirements.txt pip install mkdocs-htmlproofer-plugin - - name: Update mkdocs.yml to fix warnings - run: | - cp mkdocs.yml mkdocs.yml.bak - - sed -i '/ignore_missing_images:/d' mkdocs.yml - sed -i '/output_file:/d' mkdocs.yml - sed -i '/validate_internal_urls:/d' mkdocs.yml - sed -i '/verbose:/d' mkdocs.yml - - - name: Run link checker with strict mode + - name: Run link checker id: linkcheck run: | echo "## 🔍 Link Check Results" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - mkdocs build 2>&1 | tee build_log.txt - BUILD_EXIT_CODE=${PIPESTATUS[0]} - - BROKEN_LINKS=$(grep -c "invalid url" build_log.txt || echo "0") - MISSING_ANCHORS=$(grep -c "does not contain an anchor" build_log.txt || echo "0") - MISSING_FILES=$(grep -c "is not found among documentation files" build_log.txt || echo "0") - CONFIG_WARNINGS=$(grep -c "Unrecognised configuration name" build_log.txt || echo "0") - - TOTAL_ISSUES=$((BROKEN_LINKS + MISSING_ANCHORS + MISSING_FILES)) - - if [ $TOTAL_ISSUES -eq 0 ] && [ $BUILD_EXIT_CODE -eq 0 ]; then + if mkdocs build 2>&1 | tee build_log.txt; then echo "✅ **All links are valid!**" >> $GITHUB_STEP_SUMMARY echo "link_check_passed=true" >> $GITHUB_OUTPUT - FINAL_EXIT_CODE=0 else - echo "❌ **Issues found!**" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - - if [ $BROKEN_LINKS -gt 0 ]; then - echo "### 🔗 Broken Links: $BROKEN_LINKS" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - grep "invalid url" build_log.txt >> $GITHUB_STEP_SUMMARY || true - echo '```' >> $GITHUB_STEP_SUMMARY - fi - - if [ $MISSING_ANCHORS -gt 0 ]; then - echo "### ⚓ Missing Anchors: $MISSING_ANCHORS" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - grep "does not contain an anchor" build_log.txt >> $GITHUB_STEP_SUMMARY || true - echo '```' >> $GITHUB_STEP_SUMMARY - fi - - if [ $MISSING_FILES -gt 0 ]; then - echo "### 📄 Missing Files: $MISSING_FILES" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - grep "is not found among documentation files" build_log.txt >> $GITHUB_STEP_SUMMARY || true - echo '```' >> $GITHUB_STEP_SUMMARY - fi - + echo "❌ **Broken links detected!**" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - echo "**Total issues: $TOTAL_ISSUES**" >> $GITHUB_STEP_SUMMARY - + echo "### Errors found:" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + grep -E "(HTMLProofer:|External link|internally linking)" build_log.txt >> $GITHUB_STEP_SUMMARY || true + echo '```' >> $GITHUB_STEP_SUMMARY echo "link_check_passed=false" >> $GITHUB_OUTPUT - FINAL_EXIT_CODE=1 + exit 1 fi - - # Restaurar mkdocs.yml original - mv mkdocs.yml.bak mkdocs.yml - - exit $FINAL_EXIT_CODE - name: Upload build log - if: always() + if: failure() uses: actions/upload-artifact@v4 with: name: link-check-log path: build_log.txt - retention-days: 7 - - - name: Comment PR with results - if: github.event_name == 'pull_request' && always() - uses: actions/github-script@v7 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const fs = require('fs'); - const buildLog = fs.readFileSync('build_log.txt', 'utf8'); - - const brokenLinks = (buildLog.match(/invalid url/g) || []).length; - const missingAnchors = (buildLog.match(/does not contain an anchor/g) || []).length; - const missingFiles = (buildLog.match(/is not found among documentation files/g) || []).length; - const totalIssues = brokenLinks + missingAnchors + missingFiles; - - let body = '### 🔍 Link Check Results\n\n'; - - if (totalIssues === 0) { - body += '✅ **All links are valid!**\n'; - } else { - body += `❌ **Found ${totalIssues} issues:**\n\n`; - - if (brokenLinks > 0) body += `- 🔗 Broken links: ${brokenLinks}\n`; - if (missingAnchors > 0) body += `- ⚓ Missing anchors: ${missingAnchors}\n`; - if (missingFiles > 0) body += `- 📄 Missing files: ${missingFiles}\n`; - - body += '\n**Please fix these issues before merging.**\n'; - body += '\nRun `mkdocs build` locally to see detailed errors.\n'; - } - - const comments = await github.rest.issues.listComments({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo - }); - - const botComment = comments.data.find(comment => - comment.user.type === 'Bot' && - comment.body.includes('### 🔍 Link Check Results') - ); - - if (botComment) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: body - }); - } else { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: body - }); - } \ No newline at end of file + retention-days: 7 \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 303d2143ee..9e564443d6 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -286,7 +286,7 @@ plugins: - components/comparators/* - components/general-props/* - htmlproofer: - raise_error: False + raise_error: True verbose: True validate_external_urls: True validate_internal_urls: True From 042524b844ec7a660cafba3dc5654ac42eabf898 Mon Sep 17 00:00:00 2001 From: Rafael Riki Ogawa Osiro Date: Fri, 11 Jul 2025 20:20:47 -0300 Subject: [PATCH 5/6] fix: removing invalid options --- mkdocs.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 9e564443d6..61298b9bb1 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -287,9 +287,7 @@ plugins: - components/general-props/* - htmlproofer: raise_error: True - verbose: True validate_external_urls: True - validate_internal_urls: True ignore_urls: - "http://localhost.*" - "http://127.0.0.1.*" @@ -297,8 +295,6 @@ plugins: - "https://your-company.atlan.com" - "mailto://hello@qualytics.co" - "../print_page/" - ignore_missing_images: False - output_file: "broken_links.txt" - git-revision-date-localized - include-markdown - macros From 97044aef91e50b096ebdd0423071d30f8fd336cf Mon Sep 17 00:00:00 2001 From: Rafael Riki Ogawa Osiro Date: Fri, 11 Jul 2025 20:22:37 -0300 Subject: [PATCH 6/6] chore: update script --- .github/workflows/htmlproofer.yml | 42 +++++++++++-------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/.github/workflows/htmlproofer.yml b/.github/workflows/htmlproofer.yml index fa3e3b3394..382cc2bfee 100644 --- a/.github/workflows/htmlproofer.yml +++ b/.github/workflows/htmlproofer.yml @@ -16,48 +16,34 @@ on: jobs: check-links: runs-on: ubuntu-latest - name: Check links steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Setup Python 3.11 + - name: Setup Python uses: actions/setup-python@v5 with: python-version: '3.11' cache: 'pip' - - name: Install MkDocs and plugins + - name: Install dependencies run: | - python -m pip install --upgrade pip pip install -r requirements.txt pip install mkdocs-htmlproofer-plugin - - name: Run link checker - id: linkcheck + - name: Check links run: | - echo "## 🔍 Link Check Results" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY + # Run build and check for broken links + mkdocs build 2>&1 | tee build.log - if mkdocs build 2>&1 | tee build_log.txt; then - echo "✅ **All links are valid!**" >> $GITHUB_STEP_SUMMARY - echo "link_check_passed=true" >> $GITHUB_OUTPUT - else - echo "❌ **Broken links detected!**" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Errors found:" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - grep -E "(HTMLProofer:|External link|internally linking)" build_log.txt >> $GITHUB_STEP_SUMMARY || true - echo '```' >> $GITHUB_STEP_SUMMARY - echo "link_check_passed=false" >> $GITHUB_OUTPUT + # Fail if any broken links found + if grep -q "invalid url" build.log; then + echo "❌ Broken links found!" + grep "invalid url" build.log exit 1 fi - - - name: Upload build log - if: failure() - uses: actions/upload-artifact@v4 - with: - name: link-check-log - path: build_log.txt - retention-days: 7 \ No newline at end of file + + echo "✅ All links are valid!" \ No newline at end of file