From 57d96ca27fe3794bf5705e2739cc92b3a6827547 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 15 Nov 2024 12:27:03 +0000 Subject: [PATCH] ci: add script to check modules on registry.coder.com (#340) Added a script + corresponding GitHub action to check active modules on registry.coder.com --- .github/scripts/check.sh | 36 ++++++++++++++++++++++++++++++++++++ .github/workflows/check.yaml | 18 ++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 .github/scripts/check.sh create mode 100644 .github/workflows/check.yaml diff --git a/.github/scripts/check.sh b/.github/scripts/check.sh new file mode 100755 index 0000000..ad04ca1 --- /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 0000000..c43feea --- /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