-
Notifications
You must be signed in to change notification settings - Fork 783
130 lines (113 loc) · 4.29 KB
/
check-all-links.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Check all content (MDX) links
on:
pull_request:
permissions:
actions: read
checks: read
contents: read
issues: write
pull-requests: write
jobs:
check-for-absolute-urls:
name: "Check for dangerous urls"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: check docs urls
id: absolute-urls
run: |
FILES_WITH_ABS_URLS=$(grep -Erl "https://prisma\.io/docs|https://www\.prisma\.io/docs" content) || echo "no absolute URLs found."
FILES_WITH_LOCAL_URLS=$(grep -Prl "(?<!!)\[.+\]\(\..+\)" content) || echo "no local URLs found."
OUTPUT="## Dangerous URL check"$'\n'
SUCCESS=false
if [ -n "${FILES_WITH_ABS_URLS}" ]; then # if there were matching files
OUTPUT+="### Absolute URLs"$'\n'
OUTPUT+="The following files have absolute URLs to prisma.io/docs. Please replace them with relative URLs."$'\n'
OUTPUT+="Example: https://www.prisma.io/docs/getting-started/quickstart -> /getting-started/quickstart"$'\n'
for line in ${FILES_WITH_ABS_URLS}
do
OUTPUT+="${line}"$'\n'
done
OUTPUT+=""$'\n'
else
# no matching files
OUTPUT+="No absolute URLs to prisma.io/docs found."$'\n'
SUCCESS=true
fi
if [ -n "${FILES_WITH_LOCAL_URLS}" ]; then
OUTPUT+="### Local URLs"$'\n'
OUTPUT+="The following files have local URLs. Please remove any leading dots."$'\n'
OUTPUT+="Example: ./getting-started/quickstart -> /getting-started/quickstart"$'\n'
for line in ${FILES_WITH_LOCAL_URLS}
do
OUTPUT+="${line}"$'\n'
done
else
OUTPUT+="No local URLs found."$'\n'
SUCCESS=true
fi
# check success
if [ -n "${FILES_WITH_ABS_URLS}" ] || [ -n "${FILES_WITH_LOCAL_URLS}" ]; then
SUCCESS=false
else
SUCCESS=true
fi
# https://github.com/orgs/community/discussions/26288#discussioncomment-3876281
{
echo 'body<<EOF'
echo "$OUTPUT"
echo EOF
} >> "$GITHUB_OUTPUT"
echo "success=${SUCCESS}" >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/create-or-update-comment
with:
pull-request: ${{ github.event.pull_request.number }}
body: ${{ steps.absolute-urls.outputs.body }}
body-includes: absolute URLs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: report success
run: |
if ${{ steps.absolute-urls.outputs.success }}; then
exit 0;
else
exit 1;
fi
check-for-dead-links:
name: Check links
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Install deps
run: npm install
- name: Install remark presets
run: npm install remark-lint-no-dead-urls remark-custom-header-id
- name: Check external links (remark-cli)
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
npx remark-cli . -qf -e=md,mdx --use remark-mdx --use remark-custom-header-id --use remark-frontmatter --use remark-gfm \
--use "remark-lint-no-dead-urls=skipLocalhost:true,skipUrlPatterns:['https://www.notion.so/prismaio','https://www.prisma.io/docs','https://dash.cloudflare.com','https://www.cloudflare.com']"
- name: Check internal links (docusaurus build)
env:
DOCUSAURUS_POST_HOG_KEY: ${{ secrets.DOCUSAURUS_POST_HOG_KEY }}
run: npm run clean && npm run build
check-for-redirects:
name: Check for needed redirects
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create suggested redirects
id: redirects
run: |
bash .github/workflows/scripts/generate-redirects.sh
- uses: ./.github/actions/create-or-update-comment
with:
pull-request: ${{ github.event.pull_request.number }}
body: ${{ steps.redirects.outputs.body }}
body-includes: following redirects
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}