generated from shuding/nextra-docs-template
-
Notifications
You must be signed in to change notification settings - Fork 38
61 lines (52 loc) · 1.88 KB
/
url_check.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
name: Broken URL Check
on:
schedule:
- cron: '0 0 * * 1'
workflow_dispatch:
jobs:
url-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Run link checker
id: run_checker
run: |
python3 scripts/urlcheck.py > output.json
- name: Process results
id: process_results
run: |
output=$(cat output.json)
echo "Raw output:"
echo "$output"
total_issues=$(echo "$output" | jq -r '.total_issues')
if [ "$total_issues" -gt 0 ]; then
issue_body=$(echo "$output" | jq -r '.issues | map("File: " + .file + "\nLine: " + (.line|tostring) + "\nURL: " + .url + "\nStatus Code: " + (.status_code|tostring) + "\nReason: " + .reason + "\nFinal URL: " + .final_url + "\n\n") | join("\n")')
echo "$issue_body"
echo "issue_body=$issue_body" >> $GITHUB_ENV
fi
rm output.json
echo "total_issues=$total_issues" >> $GITHUB_OUTPUT
- name: Create Issue with Results
if: ${{ fromJson(steps.process_results.outputs.total_issues) > 0 }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueTitle = `🚨 Broken URLs: ${process.env.total_issues} issues found`;
const issueBody = process.env.issue_body;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.name,
title: issueTitle,
body: issueBody,
labels: ['url-check']
});