From aaa410b35f952911fef9d145348a4ec254983772 Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Sat, 6 Dec 2025 21:06:08 +0800 Subject: [PATCH] ci: add link checker --- .github/workflows/links.yml | 82 +++++++++++++++++++++++++++++++++++++ docs/README.md | 1 + 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/links.yml diff --git a/.github/workflows/links.yml b/.github/workflows/links.yml new file mode 100644 index 000000000..7188d6cc5 --- /dev/null +++ b/.github/workflows/links.yml @@ -0,0 +1,82 @@ +name: Links + +on: + repository_dispatch: + workflow_dispatch: + pull_request: + schedule: + - cron: "00 18 * * *" + +jobs: + linkChecker: + runs-on: ubuntu-latest + permissions: + issues: write # required for peter-evans/create-issue-from-file + pull-requests: write # required for github-script to comment on PRs + steps: + - uses: actions/checkout@v5 + + - name: Link Checker + id: lychee + uses: lycheeverse/lychee-action@v2 + with: + args: . --exclude-path "tests" + fail: false + + # - name: Create or Update PR Comment + # if: steps.lychee.outputs.exit_code != 0 && github.event_name == 'pull_request' + # uses: actions/github-script@v8 + # with: + # script: | + # const fs = require('fs'); + # const commentMarker = ''; + + # // Read the report file if it exists, otherwise use a fallback message + # let body; + # if (fs.existsSync('./lychee/out.md')) { + # body = fs.readFileSync('./lychee/out.md', 'utf8'); + # } else { + # body = '## 🔗 Link Checker Report\n\nThe link checker found broken links in this pull request. Please check the workflow logs for details.'; + # } + + # // Add the marker to identify this comment + # body = commentMarker + '\n\n' + body; + + # // Get existing comments on the PR + # const { data: comments } = await github.rest.issues.listComments({ + # owner: context.repo.owner, + # repo: context.repo.repo, + # issue_number: context.issue.number, + # }); + + # // Find existing comment with our marker + # const existingComment = comments.find(comment => + # comment.user.type === 'Bot' && + # comment.body.includes(commentMarker) + # ); + + # if (existingComment) { + # // Update existing comment + # await github.rest.issues.updateComment({ + # owner: context.repo.owner, + # repo: context.repo.repo, + # comment_id: existingComment.id, + # body: body, + # }); + # } else { + # // Create new comment + # await github.rest.issues.createComment({ + # owner: context.repo.owner, + # repo: context.repo.repo, + # issue_number: context.issue.number, + # body: body, + # }); + # } + + # - name: Create Issue From File + # if: steps.lychee.outputs.exit_code != 0 && github.event_name == 'schedule' + # uses: peter-evans/create-issue-from-file@v5 + # with: + # title: Link Checker Report + # content-filepath: ./lychee/out.md + # labels: 'type: documentation' diff --git a/docs/README.md b/docs/README.md index fa3fab223..5c307dc6b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,5 @@ [![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) +[![Check Links](https://github.com/commitizen-tools/commitizen/actions/workflows/links.yml/badge.svg)](https://github.com/commitizen-tools/commitizen/actions/workflows/links.yml) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org) [![PyPI Package latest release](https://img.shields.io/pypi/v/commitizen.svg?style=flat-square)](https://pypi.org/project/commitizen/) [![PyPI Package download count (per month)](https://img.shields.io/pypi/dm/commitizen?style=flat-square)](https://pypi.org/project/commitizen/)