forked from usnistgov/OSCAL
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (81 loc) · 2.76 KB
/
periodic.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
});