-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add broken link checker GHA workflow
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |