mirror of
https://github.com/LukeHagar/developer.sailpoint.com.git
synced 2025-12-06 12:27:46 +00:00
Update preview-link-check.yml
This commit is contained in:
110
.github/workflows/preview-link-check.yml
vendored
110
.github/workflows/preview-link-check.yml
vendored
@@ -1,108 +1,16 @@
|
||||
name: PR Preview Link Check
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created, edited]
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
issues: write
|
||||
pull-requests: read
|
||||
name: PR - Crawl Docs for broken links
|
||||
|
||||
jobs:
|
||||
link-check:
|
||||
if: >
|
||||
${{ github.event.issue.pull_request && contains(github.event.comment.body, 'Visit the preview URL for this PR [HERE](') }}
|
||||
linkinator:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Extract preview URL from comment
|
||||
id: extract
|
||||
uses: actions/github-script@v8
|
||||
- uses: actions/checkout@v2
|
||||
- uses: JustinBeckwith/linkinator-action@v1
|
||||
with:
|
||||
script: |
|
||||
const body = context.payload.comment?.body || '';
|
||||
const match = body.match(/\[HERE\]\((https?:\/\/[^\s\)]+)\)/i);
|
||||
if (!match) {
|
||||
core.setFailed('No preview URL found in the comment.');
|
||||
return;
|
||||
}
|
||||
core.setOutput('url', match[1]);
|
||||
|
||||
- name: Post scan started comment
|
||||
id: start_comment
|
||||
uses: actions/github-script@v8
|
||||
with:
|
||||
script: |
|
||||
const issue_number = context.issue.number;
|
||||
const url = `${{ steps.extract.outputs.url }}`;
|
||||
const body = [
|
||||
`🔎 Starting link crawl with linkinator...`,
|
||||
'',
|
||||
`Target: ${url}`,
|
||||
'',
|
||||
'_This comment will be updated with results once the crawl completes._'
|
||||
].join('\n');
|
||||
const { data: comment } = await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number,
|
||||
body
|
||||
});
|
||||
core.setOutput('comment_id', comment.id);
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Run Linkinator
|
||||
id: linkinator
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
URL="${{ steps.extract.outputs.url }}"
|
||||
# Run linkinator recursively; do not fail the job even if broken links are found
|
||||
npx --yes linkinator "$URL" --recurse --retry --timeout 15000 --verbosity ERROR --format JSON > linkinator.json || true
|
||||
echo "Saved results to linkinator.json"
|
||||
|
||||
- name: Build Markdown report
|
||||
id: build_report
|
||||
shell: bash
|
||||
run: |
|
||||
total=$(jq '.links | length' linkinator.json)
|
||||
broken=$(jq '[.links[] | select(.state=="BROKEN")] | length' linkinator.json)
|
||||
passed=$(jq -r '.passed' linkinator.json)
|
||||
{
|
||||
echo "✅ Link crawl completed for ${{ steps.extract.outputs.url }}"
|
||||
echo ""
|
||||
echo "- Total links scanned: ${total}"
|
||||
echo "- Broken links: ${broken}"
|
||||
echo "- Passed: ${passed}"
|
||||
echo ""
|
||||
if [ "${broken}" -gt 0 ]; then
|
||||
echo "### Broken links"
|
||||
echo ""
|
||||
echo "| Status | URL | Parent |"
|
||||
echo "| --- | --- | --- |"
|
||||
jq -r '.links[] | select(.state=="BROKEN") | "| \(.status) | \(.url) | \(.parent // "-") |"' linkinator.json
|
||||
echo ""
|
||||
else
|
||||
echo "No broken links detected."
|
||||
echo ""
|
||||
fi
|
||||
} > report.md
|
||||
|
||||
- name: Update comment with results
|
||||
uses: actions/github-script@v8
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const body = fs.readFileSync('report.md', 'utf8');
|
||||
await github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: ${{ steps.start_comment.outputs.comment_id }},
|
||||
body
|
||||
});
|
||||
|
||||
|
||||
paths: docs/**/*.md
|
||||
|
||||
Reference in New Issue
Block a user