Periodic Checks #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@f43a0e5ff2bd294095638e18286ca9a3d1956744 | |
with: | |
submodules: recursive | |
- uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d | |
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@d7906e4ad0b1822421a7e6a35d5ca353c962f410 | |
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 | |
}); |