Skip to content

Check Markdown links #4349

Check Markdown links

Check Markdown links #4349

Workflow file for this run

name: Check Markdown links
on:
schedule:
- cron: '17 3 * * *' # run nightly
workflow_dispatch:
# only allow one instance of this workflow to be running per PR or branch, cancels any that are already running
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
issues: write
jobs:
markdown-link-check:
runs-on: ubuntu-latest
# don't run this job if triggered by Dependabot
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit # Leave it audit mode
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Restore lychee cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: cache-restore
with:
path: .lycheecache
key: cache-lychee-${{ github.sha }}
restore-keys: cache-lychee-
- name: Run markdown link check
id: lychee
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0
with:
fail: false
args: >-
--cache
--cache-exclude-status '403,429,500..599'
--max-cache-age 1d
--max-retries 3
--retry-wait-time 5
--timeout 60
--threads 1
--max-concurrency 1
--no-progress
--exclude-path src/Agent/CHANGELOG.md
'./**/*.md'
- name: Save lychee cache
if: always()
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .lycheecache
key: ${{ steps.cache-restore.outputs.cache-primary-key }}
- name: Update or create link check issue
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const exitCode = '${{ steps.lychee.outputs.exit_code }}';
const fs = require('fs');
const label = 'linkcheck';
const title = 'Broken links detected in documentation';
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: label,
state: 'open'
});
if (exitCode !== '0') {
const body = fs.readFileSync('lychee/out.md', 'utf8');
if (issues.length > 0) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issues[0].number,
body
});
} else {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: [label]
});
}
} else if (issues.length > 0) {
for (const issue of issues) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
}
}