-
Notifications
You must be signed in to change notification settings - Fork 215
86 lines (80 loc) · 3.37 KB
/
Copy pathdocs-link-check.yml
File metadata and controls
86 lines (80 loc) · 3.37 KB
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
name: 'Docs Link Check'
on:
pull_request:
schedule:
- cron: '0 4 * * *'
workflow_dispatch:
inputs:
mode:
description: 'Checks to run'
type: choice
options: [offline, online, both]
default: both
permissions:
contents: read
jobs:
offline:
if: github.event_name == 'pull_request' || github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && (inputs.mode == 'offline' || inputs.mode == 'both'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- name: Offline check (relative links, self-repo links, anchors)
uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8
with:
args: --offline --include-fragments --config ./lychee.toml .
- name: Check canonical MongoDB docs domains
run: |
exit_code=0
git grep -nE 'https?://(docs\.(atlas\.)?mongodb\.com|dochub\.mongodb\.org)' -- '*.md' ':!CHANGELOG.md' ':!.changelog/**' ':!compliance/**' || exit_code=$?
if [ "$exit_code" -eq 0 ]; then
echo "::error::Legacy MongoDB docs domains found. Use https://www.mongodb.com/docs/... links instead."
exit 1
elif [ "$exit_code" -ne 1 ]; then
echo "::error::git grep failed unexpectedly (exit $exit_code)"
exit "$exit_code"
fi
online-changed:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
fetch-depth: 2 # need HEAD^1 (the base parent) for the changed-files diff
- name: Collect changed markdown files
id: changed
run: |
files=$(git diff --name-only --diff-filter=d HEAD^1 HEAD -- '*.md' | tr '\n' ' ')
echo "files=$files" >> "$GITHUB_OUTPUT"
- name: Online check (changed files)
if: steps.changed.outputs.files != ''
uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8
with:
args: --config ./lychee.toml ${{ steps.changed.outputs.files }}
failIfEmpty: false # changed files may legitimately contain no links
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
online-full:
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && (inputs.mode == 'online' || inputs.mode == 'both'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- name: Online check (all docs)
uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8
with:
args: --config ./lychee.toml .
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
notify:
needs: [offline, online-full]
if: failure() && github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- name: Notify Slack
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "❌ ${{ github.event.repository.name }}: nightly docs link check failed. ${{ secrets.SLACK_ONCALL_TAG }} <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Failed Action>"
}