-
Notifications
You must be signed in to change notification settings - Fork 288
55 lines (49 loc) · 1.67 KB
/
broken-links-check.yaml
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
name: check-links
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 1'
permissions:
issues: write
jobs:
check-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Prepare Yarn
uses: ./.github/actions/prepare/
- name: Build CLI
run: yarn build:cli
- name: Check Links
id: check-links
# Run link checker and save outputs to files. https://stackoverflow.com/a/692407
run: |
yarn lint:links > >(tee -a stdout.txt) 2> >(tee -a stderr.txt >&2)
- name: Create issue
uses: actions/[email protected]
if: always() && steps.check-links.outcome == 'failure'
with:
script: |
const title: 'Fix broken links';
const previousIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
creator: context.actor,
});
const previousIssueExists = previousIssues.some((issue) => {
issue.title === title;
})
if !previousIssueExists {
const fs = require('fs');
const input = fs.readFileSync('stderr.txt');
const data = JSON.parse(input);
const urls = data.map(item => item.url);
const output = urls.map(url => `- [ ] ${url}`).join('\n');
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body: `The following links are possibly broken:\n${output}`,
});
}