From 2ffe93ad4731121e6ff8b628c50a9df0dfa071ac Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Thu, 14 Nov 2024 20:26:13 +0000 Subject: [PATCH 1/3] ci: add script to check modules on registry.coder.com --- .github/workflows/check.yaml | 18 ++++++++++++++++++ check.sh | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .github/workflows/check.yaml create mode 100755 check.sh diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 00000000..7a659339 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,18 @@ +name: Check modules on registry.coder.com + +on: + schedule: + - cron: "23 * * * *" # Runs at 23 minutes past the hour. + 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: | + ./check.sh diff --git a/check.sh b/check.sh new file mode 100755 index 00000000..021ff94b --- /dev/null +++ b/check.sh @@ -0,0 +1,37 @@ +#!/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=() +modules+=("doesnotexist") +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}" From 511f7fed5c12ba77ebb8d80a43a2aea019f07040 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Thu, 14 Nov 2024 20:27:24 +0000 Subject: [PATCH 2/3] fixup! ci: add script to check modules on registry.coder.com --- check.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/check.sh b/check.sh index 021ff94b..ad04ca1f 100755 --- a/check.sh +++ b/check.sh @@ -10,7 +10,6 @@ fi status=0 declare -a modules=() declare -a failures=() -modules+=("doesnotexist") for path in $(find . -not -path '*/.*' -type f -name main.tf -maxdepth 2 | cut -d '/' -f 2 | sort -u); do modules+=("${path}") done From 92816ec5d4eb9ff1c3115dc30b8ac6bca65b2c24 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 15 Nov 2024 12:18:21 +0000 Subject: [PATCH 3/3] address PR comments --- check.sh => .github/scripts/check.sh | 0 .github/workflows/check.yaml | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename check.sh => .github/scripts/check.sh (100%) diff --git a/check.sh b/.github/scripts/check.sh similarity index 100% rename from check.sh rename to .github/scripts/check.sh diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 7a659339..c43feea2 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -2,7 +2,7 @@ name: Check modules on registry.coder.com on: schedule: - - cron: "23 * * * *" # Runs at 23 minutes past the hour. + - cron: "*/13 * * * *" # Runs every 13th minute workflow_dispatch: # Allows manual triggering of the workflow if needed jobs: @@ -15,4 +15,4 @@ jobs: - name: Run check.sh run: | - ./check.sh + ./.github/scripts/check.sh