Skip to content

Commit

Permalink
feat: add broken link checker GHA workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mhucka committed Nov 27, 2023
1 parent 737a16a commit ae42568
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Broken links found in README.md
labels: ['bug']
assignees: ''
---

List of broken links:
- {{env.BROKEN_LINKS}}
64 changes: 64 additions & 0 deletions .github/workflows/link-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# @file markdown-linter.yml
# @brief GitHub Actions workflow to check the README file for broken links
# @license Please see the file named LICENSE in the repository
# @repo https://github.com/AI4LAM/awesome-ai4lam
#
# This file was originally copied on 2023-11-26 from the instructions at
# https://github.com/saver999/Broken-Links-Checker

name: Check README for broken links
on: [push, pull_request, workflow_dispatch]
env:
ISSUE_TEMPLATE: ".github/workflows/ISSUE_TEMPLATE.md"
contents: read
issues: write

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Gather links from the README.md file
id: get-links
run: |
LINKS=$(sed -nE 's/\[.*\]\((http[s]?:\/\/[^)]*)\)/\1/p' README.md | paste -sd ,)
echo "WEBSITE_URL=$LINKS" >> $GITHUB_ENV
- name: Run the Broken Links Checker
run: |
# Split the list of links into an array separated by commas
read -ra LINKS <<< "$WEBSITE_URL"
BROKEN_LINKS=()
# Scan the links and verify if they are reachable
for link in "${LINKS[@]}"; do
if [[ $link =~ ^(http|https):// ]]; then
# Scan the links and verify if they are reachable
if ! curl -IsSk "$link" > /dev/null; then
BROKEN_LINKS+=("$link")
fi
fi
done
if [ ${#BROKEN_LINKS[@]} -gt 0 ]; then
echo "Broken links found: ${BROKEN_LINKS[@]}" >&2
BROKEN_LINKS_STRING=$(echo "${BROKEN_LINKS[@]}" | tr '\n' ';')
echo "BROKEN_LINKS=$BROKEN_LINKS_STRING" >> $GITHUB_ENV
echo "Broken links found: ${BROKEN_LINKS[@]}"
echo "Broken links found, failing the workflow"
exit 1
else
echo "No broken links found"
fi
- uses: actions/checkout@v3
if: failure()

- uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: ${{ env.ISSUE_TEMPLATE }}
if: failure()

0 comments on commit ae42568

Please sign in to comment.