-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (65 loc) · 2.62 KB
/
Copy pathcheck-links.yml
File metadata and controls
75 lines (65 loc) · 2.62 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
name: Check Links
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
schedule:
# Run weekly on Mondays at 9:00 UTC to catch link rot
- cron: '0 9 * * 1'
workflow_dispatch:
jobs:
link-checker:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: read
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Check for manual override label
id: check-label
if: github.event_name == 'pull_request'
run: |
LABEL_EXISTS=$(gh pr view "${{ github.event.pull_request.number }}" --json labels --jq 'if (.labels[].name | select(. == "links checked by hand")) then "true" else "false" end')
echo "skip=$LABEL_EXISTS" >> "$GITHUB_OUTPUT"
if [ "$LABEL_EXISTS" = "true" ]; then
echo "Manual override enabled: 'links checked by hand' label found"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Skip message
if: github.event_name == 'pull_request' && steps.check-label.outputs.skip == 'true'
run: |
echo "::notice::Links check skipped - 'links checked by hand' label present on PR"
- name: Check links in markdown and HTML files
id: lychee
if: github.event_name != 'pull_request' || steps.check-label.outputs.skip != 'true'
uses: lycheeverse/lychee-action@v2
with:
# Check all .qmd (Quarto markdown), .md (markdown), and .html files
args: --verbose --no-progress --config lychee.toml './**/*.qmd' './**/*.md' './**/*.html'
# Fail action on broken links
fail: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create issue on main branch if links are broken
if: failure() && github.ref == 'refs/heads/main'
run: |
# Create issue with broken link details
BODY=$(cat <<'EOF'
The link checker found broken links in the main branch.
**Workflow Run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Please review the workflow logs above for details on which links are broken.
This issue was automatically created by the link checker workflow.
@copilot please fix the broken links found in the main branch.
EOF
)
gh issue create \
--title "Broken links detected in main branch" \
--body "$BODY" \
--label "bug,automated,copilot"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}