Skip to content

Periodic Checks

Periodic Checks #104

Workflow file for this run

name: Periodic Checks
on:
schedule:
- cron: "0 0 * * MON"
- cron: "0 0 * * THU"
workflow_dispatch:
jobs:
linkcheck:
name: Validate Markdown Links
runs-on: ubuntu-22.04
permissions:
# Needed to post comments and issues
issues: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
submodules: recursive
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version-file: "build/.nvmrc"
cache: "npm"
cache-dependency-path: "build/package-lock.json"
- name: Perform link checking
run: |
make linkcheck
working-directory: build
- name: Create an issue or comment if bad links are detected
if: failure()
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
// Read the markdown linkcheck report
const fs = require('fs');
const body = fs.readFileSync('build/generated/mlc_report.log', 'utf8');
const title = "Scheduled Check of Markdown Documents Found Bad Hyperlinks";
const labels = ["bug", "Scope: Documentation"];
// Find open linkchecker issues
const query = `query($owner:String!, $name:String!, $labels:[String!], $user:String!) {
repository(owner:$owner, name:$name) {
issues(first: 100, orderBy: {
direction: DESC,
field: CREATED_AT
}, filterBy: {
createdBy: $user,
labels: $labels,
states: OPEN
}) {
nodes {
title
number
}
}
}
}`;
const result = await github.graphql(query, {
owner: context.repo.owner,
name: context.repo.repo,
labels: labels,
user: "github-actions[bot]"
});
// find the first issue with a matching title, and create a comment
for (const issue of result.repository.issues.nodes) {
if (issue.title !== title) {
continue;
}
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body
});
return;
}
// or, if none were found, create an issue
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels
});