generated from json-schema-org/repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 11
93 lines (79 loc) · 3.16 KB
/
link-checker.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
88
89
90
91
92
93
name: Link Checker
on:
repository_dispatch:
workflow_dispatch:
schedule:
- cron: '0 0 1 * *' # Run at midnight on the first of every month
jobs:
linkChecker:
name: Check and report broken links
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Corepack enable
run: corepack enable
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Get Token
uses: actions/create-github-app-token@v1
id: get_workflow_token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Serve App Locally
run: pnpm run dev &
- name: Wait for App to Start
run: sleep 20
# This will restore the lychee cache
- name: Restore lychee cache
uses: actions/cache@v4
with:
path: .lycheecache
key: cache-lychee-${{ github.sha }}
restore-keys: cache-lychee-
# This will run the link checker on all markdown files in the pages directory
- name: Link Checker
id: lychee
uses: lycheeverse/lychee-action@v1
with:
args: --base https://tour.json-schema.org --verbose --no-progress --accept 200,204,429,403 './content/**/*.mdx' --cache --max-cache-age 1d https://tour.json-schema.org
token: ${{secrets.GITHUB_TOKEN}}
- name: Install Octokit
run: pnpm add @octokit/[email protected]
# This will create an issue with the link checker report if it does not exist, otherwise it will update the existing issue.
- name: Create Issue
if: env.lychee_exit_code != 0
uses: actions/github-script@v7
env:
AUTH_TOKEN: ${{ steps.get_workflow_token.outputs.token }}
with:
script: |
const { Octokit } = require("@octokit/core");
const octokit = new Octokit({ auth: process.env.AUTH_TOKEN });
const allIssues = await octokit.request('GET /repos/{owner}/{repo}/issues', {
owner: context.repo.owner,
repo: context.repo.repo
});
const existingIssue = allIssues.data.find(issue => issue.title === 'Link Checker Report');
if (existingIssue) {
await octokit.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existingIssue.number,
body: '## Link Checker Report\n\n' + require('fs').readFileSync('./lychee/out.md', 'utf8')
});
} else {
await octokit.request('POST /repos/{owner}/{repo}/issues', {
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Link Checker Report',
body: '## Link Checker Report\n\n' + require('fs').readFileSync('./lychee/out.md', 'utf8')
});
}