Check links daily #182
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
name: Check links daily | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "18 0 * * *" | |
permissions: | |
issues: write # to create an issue when link check fails | |
env: | |
OUTPUT_FILE: lychee.md | |
jobs: | |
build-and-check-links: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@main | |
- name: Install lychee | |
env: | |
LYCHEEVERSION: 0.13.0 | |
# due to the limitation of Apache, we can't use lycheeverse/lychee-action directly, | |
# so we re-use some core code from it | |
run: | | |
curl -sLO "https://github.com/lycheeverse/lychee/releases/download/v${{ env.LYCHEEVERSION }}/lychee-v${{ env.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz" | |
tar -xvzf "lychee-v${{ env.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz" | |
rm "lychee-v${{ env.LYCHEEVERSION }}-x86_64-unknown-linux-gnu.tar.gz" | |
install -t "$HOME/.local/bin" -D lychee | |
rm lychee | |
echo "$HOME/.local/bin" >> "$GITHUB_PATH" | |
- name: Link Checker | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
# For parameter description, see https://github.com/lycheeverse/lychee#commandline-parameters | |
# -E, --exclude-all-private Exclude all private IPs from checking. | |
# -i, --insecure Proceed for server connections considered insecure (invalid TLS) | |
# -n, --no-progress Do not show progress bar. | |
# -t, --timeout <timeout> Website timeout in seconds from connect to response finished [default:20] | |
# --max-concurrency <max-concurrency> Maximum number of concurrent network requests [default: 128] | |
# -a --accept <accept> Comma-separated list of accepted status codes for valid links | |
# -m, --max-redirects <MAX_REDIRECTS> | |
# 'build': the site directory to check | |
# './*.md': all markdown files in the root directory | |
run: | | |
# run lychee | |
GITHUB_WORKFLOW_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}?check_suite_focus=true" | |
if ! lychee --output ${OUTPUT_FILE} \ | |
-E -i -n -t 5 --max-concurrency 64 -a 429,401,403 -m 10 -f markdown \ | |
-s http --exclude-path versioned_docs/version-v0.15 --exclude-path versioned_docs/version-v0.16 --exclude-path versioned_docs/version-v0.17 \ | |
-s https --exclude-path versioned_docs/version-v0.15 --exclude-path versioned_docs/version-v0.16 --exclude-path versioned_docs/version-v0.17 \ | |
'**/*.md' | |
then | |
echo "" >> "${OUTPUT_FILE}" # add a new line | |
echo "[Full Github Actions output](${GITHUB_WORKFLOW_URL})" >> "${OUTPUT_FILE}" | |
gh issue list -S "is:open Broken links found in the website" | |
if ! gh issue list -S "is:open Broken links found in the website" | grep -F "Broken links found in the website"; then | |
gh issue create --title "Broken links found in the website" --body-file "${OUTPUT_FILE}" --repo "${GITHUB_REPOSITORY}" --assignee "${GITHUB_ACTOR}" --label "type/bug" | |
else | |
echo "Broken links found in the website, but an issue already exists." | |
fi | |
exit 1 | |
fi | |