marcelscruz / public-apis

A collaborative list of public APIs for developers
https://publicapis.dev
MIT License
3.03k stars 317 forks source link

Broken Link Checker - Github Action #354

Open JuanPabloDiaz opened 1 month ago

JuanPabloDiaz commented 1 month ago

I believe that it will be a great idea to setup a GitHub action that runs periodically and checks for broken links. It will check all repository links once per day and create an issue in case of errors.

Github action to check for broken links in Markdown, HTML, and text files using Lychee, a fast link checker written in Rust.

Here is a full example of a GitHub workflow file:

It will check all repository links once per day and create an issue in case of errors.

name: Links

on:
  repository_dispatch:
  workflow_dispatch:
  schedule:
    - cron: "00 18 * * *"

jobs:
  linkChecker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Link Checker
        id: lychee
        uses: lycheeverse/lychee-action@v1

      - name: Create Issue From File
        if: env.lychee_exit_code != 0
        uses: peter-evans/create-issue-from-file@v4
        with:
          title: Link Checker Report
          content-filepath: ./lychee/out.md
          labels: report, automated issue

I'd like to share my experience with Lychee. I came across it yesterday and integrated it into my project. While it was helpful in identifying some broken links, it also generated some false positives (links that appear broken but function correctly). I'm still exploring the tool's functionality to potentially fine-tune its accuracy.

On a separate note, I encountered a permissions issue when trying to open new issues.

Project implementations:

here is an example from my own project: image

I hope this helps

JuanPabloDiaz commented 1 month ago

My bad, I believe you are already using a github action that does just that. Could you please confirm if validate_links.yml check for broken links?

marcelscruz commented 1 month ago

The file you linked came from the original fork, and as we changed a few things around here, I'm not sure if it's working. If you have a good understanding of Python (which I don't), it'd be great if you could have a look at it and see if it's still working! 🙏 Btw, you summary screenshot looks great, would love like that around here!