Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI : Added link_check #86

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
17 changes: 17 additions & 0 deletions .github/workflows/link_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
pull_request: # temporary for testing
schedule:
- cron: "0 9 * * *"

# this cancels workflows in progress if you start a new one
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-basic-cli-docs-broken-links:
runs-on: [ubuntu-20.04]
steps:
- uses: actions/checkout@v3

- run: ./ci/link_check.sh
30 changes: 30 additions & 0 deletions ci/link_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -euxo pipefail

base_url="https://www.roc-lang.org/packages/basic-cli"

timeout=15 #timeout in seconds

broken_links=()

extract_links() {
curl -s "$1" | grep -Eo 'href="([^"#]+)"' | cut -d'"' -f2
}

links=$(extract_links "$base_url")

for link in "${links[@]}"; do
full_link="${base_url}${link}"
status=$(curl -o /dev/null -s -w "%{http_code}" --connect-timeout $timeout "$full_link")
if [[ $status != 200 ]]; then
broken_links+=("$full_link")
fi
done

if [[ ${#broken_links[@]} -gt 0 ]]; then
echo "Broken links found:"
printf '%s\n' "${broken_links[@]}"
exit 1
fi