-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
77 lines (74 loc) · 2.54 KB
/
md-link-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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Markdown Link Check
on:
pull_request:
paths:
- '**.md'
- '!.github/**'
workflow_dispatch:
permissions:
contents: read
jobs:
link-check:
runs-on: ubuntu-latest
steps:
- name: Setup Action
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Save PR number
env:
PR_NUMBER: ${{ github.event.number }}
run: echo $PR_NUMBER > pr_number
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install -g [email protected]
- name: Changed Files Exporter
if: github.event_name == 'pull_request'
id: files
uses: umani/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: PR link check
if: github.event_name == 'pull_request'
env:
FILES: '${{ steps.files.outputs.files_updated }} ${{ steps.files.outputs.files_created }}'
run: |
echo "The Following files were changed or created:"
echo $FILES
touch log err
for FILE in $FILES; do echo $FILE | grep -q .*\.md\$ && markdown-link-check -q -v -c .github/configs/markdown-link-check-config.json $FILE 1>> log 2>> err; done
if grep -q "ERROR:" err ; then exit 1 ; else echo -e "No broken links found."; fi
echo $(cat log)
echo $(cat err)
- name: Repository link check
if: github.event_name == 'workflow_dispatch'
run: |
touch log err
find . -name \*.md -exec markdown-link-check -q -v --config .github/configs/markdown-link-check-config.json {} 1>> log 2>> err \;
if grep -q "ERROR:" err ; then exit 1 ; else echo -e "No broken links found."; fi
echo $(cat log)
echo $(cat err)
- name: Show broken links
if: failure()
run: |
cat log | awk -v RS="FILE:" 'match($0, /(\S*\.md).*\[✖\].*([0-9]*\slinks\schecked\.)(.*)/, arr ) { print "FILE:"arr[1] arr[3] > "brokenlinks.txt"}'
cat brokenlinks.txt
- name: Create artifact for comment
if: failure()
run: |
echo "**The following links are broken:**" > artifact.txt
# Copy to generic name for commenting
cat brokenlinks.txt | tee -a artifact.txt
rm -f err log
- name: Upload list of broken links
if: failure()
uses: actions/upload-artifact@v4
with:
name: artifact
path: |
artifact.txt
pr_number