Skip to content

Link Check (Production) #683

Link Check (Production)

Link Check (Production) #683

name: Link Check (Production)
# Runs lychee against the freshly built site to catch broken external links
# (and stale internal references) on a daily cron, with Slack on failure.
#
# Resolves links against the build's filesystem (`--root-dir`) rather than
# `--base https://docs.civic.com`, because `--base` collapses fragment-only
# links like `<a href="#foo">` to `https://docs.civic.com/#foo` instead of
# resolving them against the page they live on, producing thousands of false
# "fragment not found" errors.
on:
push:
branches: [main]
schedule:
# Daily at 09:00 UTC
- cron: '0 9 * * *'
workflow_dispatch:
jobs:
link-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Link Checker (Built HTML)
uses: lycheeverse/lychee-action@v2
with:
args: >
--config lychee.toml
--root-dir ${{ github.workspace }}/build
--no-progress
'build/**/*.html'
fail: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create Issue From File
if: failure()
uses: peter-evans/create-issue-from-file@v5
with:
title: 'Link Checker Report: Broken Links Found'
content-filepath: ./lychee/out.md
labels: |
documentation
automated
- name: Slack Notification
if: failure() && github.event_name == 'schedule'
uses: slackapi/slack-github-action@v2.1.0
with:
payload: |
{
"text": "🔴 Scheduled link check failed for docs.civic.com",
"blocks": [
{
"type": "header",
"text": { "type": "plain_text", "text": "🔴 Docs Link Check Failed" }
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Repository:* ${{ github.repository }}\n*Workflow:* ${{ github.workflow }}\n*Run:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Details>"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "The scheduled link check found broken links in the documentation. Please check the GitHub issue for details."
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}