diff --git a/.github/scripts/check.sh b/.github/scripts/check.sh new file mode 100755 index 00000000..ad04ca1f --- /dev/null +++ b/.github/scripts/check.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -o pipefail +REGISTRY_BASE_URL="${REGISTRY_BASE_URL:-https://registry.coder.com}" +set -u + +if [[ -n "${VERBOSE:-}" ]]; then + set -x +fi + +status=0 +declare -a modules=() +declare -a failures=() +for path in $(find . -not -path '*/.*' -type f -name main.tf -maxdepth 2 | cut -d '/' -f 2 | sort -u); do + modules+=("${path}") +done +echo "Checking modules: ${modules[*]}" +for module in "${modules[@]}"; do + # Trim leading/trailing whitespace from module name + module=$(echo "${module}" | xargs) + url="${REGISTRY_BASE_URL}/modules/${module}" + printf "=== Check module %s at %s\n" "${module}" "${url}" + status_code=$(curl --output /dev/null --head --silent --fail --location "${url}" --retry 3 --write-out "%{http_code}") + # shellcheck disable=SC2181 + if (( status_code != 200 )); then + printf "==> FAIL(%s)\n" "${status_code}" + status=1 + failures+=("${module}") + else + printf "==> OK(%s)\n" "${status_code}" + fi +done + +if (( status != 0 )); then + echo "The following modules appear to have issues: ${failures[*]}" +fi +exit "${status}" diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 00000000..c43feea2 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,18 @@ +name: Check modules on registry.coder.com + +on: + schedule: + - cron: "*/13 * * * *" # Runs every 13th minute + workflow_dispatch: # Allows manual triggering of the workflow if needed + +jobs: + run-script: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Run check.sh + run: | + ./.github/scripts/check.sh