Skip to content

Commit a586f4d

Browse files
committed
ci: add link checker
1 parent e241812 commit a586f4d

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

.github/workflows/links.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Links
2+
3+
on:
4+
repository_dispatch:
5+
workflow_dispatch:
6+
pull_request:
7+
schedule:
8+
- cron: "00 18 * * *"
9+
10+
jobs:
11+
linkChecker:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
issues: write # required for peter-evans/create-issue-from-file
15+
pull-requests: write # required for github-script to comment on PRs
16+
steps:
17+
- uses: actions/checkout@v5
18+
19+
- name: Link Checker
20+
id: lychee
21+
uses: lycheeverse/lychee-action@v2
22+
with:
23+
fail: false
24+
25+
- name: Create or Update PR Comment
26+
if: steps.lychee.outputs.exit_code != 0 && github.event_name == 'pull_request'
27+
uses: actions/github-script@v8
28+
with:
29+
script: |
30+
const fs = require('fs');
31+
const commentMarker = '<!-- link-checker-report -->';
32+
33+
// Read the report file if it exists, otherwise use a fallback message
34+
let body;
35+
if (fs.existsSync('./lychee/out.md')) {
36+
body = fs.readFileSync('./lychee/out.md', 'utf8');
37+
} else {
38+
body = '## 🔗 Link Checker Report\n\nThe link checker found broken links in this pull request. Please check the workflow logs for details.';
39+
}
40+
41+
// Add the marker to identify this comment
42+
body = commentMarker + '\n\n' + body;
43+
44+
// Get existing comments on the PR
45+
const { data: comments } = await github.rest.issues.listComments({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
issue_number: context.issue.number,
49+
});
50+
51+
// Find existing comment with our marker
52+
const existingComment = comments.find(comment =>
53+
comment.user.type === 'Bot' &&
54+
comment.body.includes(commentMarker)
55+
);
56+
57+
if (existingComment) {
58+
// Update existing comment
59+
await github.rest.issues.updateComment({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
comment_id: existingComment.id,
63+
body: body,
64+
});
65+
} else {
66+
// Create new comment
67+
await github.rest.issues.createComment({
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
issue_number: context.issue.number,
71+
body: body,
72+
});
73+
}
74+
75+
- name: Create Issue From File
76+
if: steps.lychee.outputs.exit_code != 0 && github.event_name == 'schedule'
77+
uses: peter-evans/create-issue-from-file@v5
78+
with:
79+
title: Link Checker Report
80+
content-filepath: ./lychee/out.md
81+
labels: 'type: documentation'

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/commitizen-tools/commitizen/pythonpackage.yml?label=python%20package&logo=github&logoColor=white&style=flat-square)](https://github.com/commitizen-tools/commitizen/actions)
2+
[![Check Links](https://github.com/commitizen-tools/commitizen/actions/workflows/links.yml/badge.svg)](https://github.com/commitizen-tools/commitizen/actions/workflows/links.yml)
23
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org)
34
[![PyPI Package latest release](https://img.shields.io/pypi/v/commitizen.svg?style=flat-square)](https://pypi.org/project/commitizen/)
45
[![PyPI Package download count (per month)](https://img.shields.io/pypi/dm/commitizen?style=flat-square)](https://pypi.org/project/commitizen/)

lychee.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exclude_path = [
2+
"(^|/)test/", # skip directories named "test"
3+
]

0 commit comments

Comments
 (0)