forked from microcks/microcks.io
-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (77 loc) · 3.48 KB
/
external-link-check.yml
File metadata and controls
93 lines (77 loc) · 3.48 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
87
88
89
90
91
92
93
# This link checks Microcks website links in Markdown HTML files once per day
# from: https://github.com/lycheeverse/lychee-action
# link checker used is 'lychee': https://github.com/lycheeverse/lychee
name: External Link Check
on:
schedule:
- cron: "42 0 * * 0" # This will run the workflow every Sunday at 00:42 UTC
workflow_dispatch: # This allows the workflow to be triggered manually
jobs:
linkChecker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Ensure Report Directory Exists
run: mkdir -p link-checker
# Run lychee and capture errors
- name: Link Checker
id: lychee
uses: lycheeverse/lychee-action@v1
continue-on-error: true
with:
# Check all markdown and html files in repo
# Exclude all files except those starting with http:// or https:// thanks to the --scheme option
args: --verbose --no-progress './**/*.md' './**/*.html' --scheme https --scheme http
# Use markdown as output format
format: markdown
# Use different output file path
output: ./link-checker/report.md
# Don't fail action on broken links
fail: false
env:
# Use a custom GitHub token to "avoid" rate limiting
GITHUB_TOKEN: ${{ secrets.CUSTOM_TOKEN }}
# Capture lychee output including regex errors
- name: Capture Errors
run: |
echo "### Lychee Link Check Report" > ./link-checker/report.md
echo "" >> ./link-checker/report.md
{ lychee --verbose --no-progress './**/*.md' './**/*.html' --scheme https --scheme http; } >> ./link-checker/report.md 2>&1 || true
echo "" >> ./link-checker/report.md
# Debug: Show report contents
- name: Debug Report
run: cat ./link-checker/report.md
# Check if report contains regex errors or broken links
- name: Check for Errors
id: check_errors
run: |
if grep -q "Error:" ./link-checker/report.md || grep -q "✗" ./link-checker/report.md; then
echo "has_errors=true" >> $GITHUB_ENV
else
echo "has_errors=false" >> $GITHUB_ENV
fi
# Format the date for the issue title and store it in an environment variable
- name: Format Date
run: echo "DATE=$(date +'%A, %e. %b %Y')" >> $GITHUB_ENV
# Create an issue if there are broken links
- name: Create Issue From File
if: env.has_errors == 'true'
id: create_issue # 🔹 Add an ID to reference outputs later
uses: peter-evans/create-issue-from-file@v5
with:
title: "External Link Check Report - ${{ env.DATE }}"
content-filepath: ./link-checker/report.md
labels: report, automated issue, contribution message, help wanted
# Store the issue number in an environment variable
- name: Store Issue Number
if: steps.create_issue.outputs.issue-number != ''
run: echo "ISSUE_NUMBER=${{ steps.create_issue.outputs.issue-number }}" >> $GITHUB_ENV
# Add a comment to the issue with the contribution message
- name: Add contribution message as new comment
if: env.ISSUE_NUMBER != ''
run: gh issue comment "$ISSUE_NUMBER" --body-file "$BODY"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
BODY: "./.github/contribution_message.md"