diff --git a/.github/workflows/link_check.yml b/.github/workflows/link_check.yml new file mode 100644 index 00000000..f36a987c --- /dev/null +++ b/.github/workflows/link_check.yml @@ -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 diff --git a/ci/link_check.sh b/ci/link_check.sh new file mode 100755 index 00000000..e9ff574d --- /dev/null +++ b/ci/link_check.sh @@ -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