From b2c97ce7c94e64509a58197153f8d41902bbd4ff Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 22 Apr 2025 20:37:09 +0000 Subject: [PATCH 1/5] chore: add deploy script --- .github/workflows/deploy-registry.yaml | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/deploy-registry.yaml diff --git a/.github/workflows/deploy-registry.yaml b/.github/workflows/deploy-registry.yaml new file mode 100644 index 0000000..fc21ee7 --- /dev/null +++ b/.github/workflows/deploy-registry.yaml @@ -0,0 +1,34 @@ +name: deploy-registry + +on: + push: + branches: + - main + tags: + - "release/*/v*" # Matches tags like release/module-name/v1.0.0 + +jobs: + deploy: + runs-on: ubuntu-latest + + # Set id-token permission for gcloud + permissions: + contents: read + id-token: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Authenticate with Google Cloud + uses: google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 + with: + workload_identity_provider: projects/309789351055/locations/global/workloadIdentityPools/github-actions/providers/github + service_account: registry-v2-github@coder-registry-1.iam.gserviceaccount.com + - name: Set up Google Cloud SDK + uses: google-github-actions/setup-gcloud@77e7a554d41e2ee56fc945c52dfd3f33d12def9a + # For the time being, let's have the first couple merges to main in + # modules deploy a new version to *dev*. Once we review and make sure + # everything's working, we can deploy a new version to *main*. Maybe in + # the future we could automate this based on the result of E2E tests. + - name: Deploy to dev.registry.coder.com + run: gcloud builds triggers run 29818181-126d-4f8a-a937-f228b27d3d34 --branch dev From 12d4d7264047e8270127b50b6e1547d06f2d5e7b Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 22 Apr 2025 21:26:24 +0000 Subject: [PATCH 2/5] wip: commit progress on terraform validation --- .github/workflows/ci.yaml | 4 +++- package.json | 4 ++-- scripts/terraform_validate.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 scripts/terraform_validate.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 159e8c9..1d7b46e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,5 +38,7 @@ jobs: bun-version: latest - name: Install dependencies run: bun install - - name: Run tests + - name: Run TypeScript tests run: bun test + - name: Run Terraform Validate + run: bun terraform-validate diff --git a/package.json b/package.json index aa3c7e2..0813154 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "name": "modules", "scripts": { "test": "bun test", + "terraform-validate": "./scripts/terraform_validate.sh", "fmt": "bun x prettier -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf", - "fmt:ci": "bun x prettier --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf", - "update-version": "./update-version.sh" + "fmt:ci": "bun x prettier --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf" }, "devDependencies": { "@types/bun": "^1.2.9", diff --git a/scripts/terraform_validate.sh b/scripts/terraform_validate.sh new file mode 100644 index 0000000..125faaa --- /dev/null +++ b/scripts/terraform_validate.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -euo pipefail + +validate_terraform_directory() { + local dir="$1" + echo "Running \`terraform validate\` in $dir" + pushd "$dir" + terraform init -upgrade + terraform validate + popd +} + +main() { + # Get the directory of the script + local script_dir=$(dirname "$(readlink -f "$0")") + + # Code assumes that registry directory will always be in same position + # relative to the main script directory + local registry_dir="$script_dir/../registry" + + # Get all subdirectories in the registry directory. Code assumes that + # Terraform directories won't begin to appear until three levels deep into + # the registry (e.g., registry/coder/modules/coder-login, which will then + # have a main.tf file inside it) + local subdirs=$(find "$registry_dir" -mindepth 3 -type d | sort) + + for dir in $subdirs; do + validate_terraform_directory "$dir" + done +} + +main From 62cf5fdd33ab7f5836e070b3b762d9873e33df9d Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 22 Apr 2025 21:27:31 +0000 Subject: [PATCH 3/5] fix: update permission level for terraform_validate --- scripts/terraform_validate.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/terraform_validate.sh diff --git a/scripts/terraform_validate.sh b/scripts/terraform_validate.sh old mode 100644 new mode 100755 From 5d14f876ae166c290be82bf2484326e00d2ae877 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 22 Apr 2025 21:32:37 +0000 Subject: [PATCH 4/5] fix: add filter logic to Bash scraping --- scripts/terraform_validate.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/terraform_validate.sh b/scripts/terraform_validate.sh index 125faaa..2c28a0d 100755 --- a/scripts/terraform_validate.sh +++ b/scripts/terraform_validate.sh @@ -26,7 +26,11 @@ main() { local subdirs=$(find "$registry_dir" -mindepth 3 -type d | sort) for dir in $subdirs; do - validate_terraform_directory "$dir" + # Skip over any directories that obviously don't have the necessary + # files + if test -f "$dir/main.tf"; then + validate_terraform_directory "$dir" + fi done } From d8ae7448646477d48bf5cae50962b3931cda65b1 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 22 Apr 2025 21:42:37 +0000 Subject: [PATCH 5/5] fix: remove changes from different branch --- .github/workflows/ci.yaml | 4 +--- package.json | 1 - scripts/terraform_validate.sh | 37 ----------------------------------- 3 files changed, 1 insertion(+), 41 deletions(-) delete mode 100755 scripts/terraform_validate.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1d7b46e..159e8c9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,7 +38,5 @@ jobs: bun-version: latest - name: Install dependencies run: bun install - - name: Run TypeScript tests + - name: Run tests run: bun test - - name: Run Terraform Validate - run: bun terraform-validate diff --git a/package.json b/package.json index 0813154..8cfecf1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "modules", "scripts": { "test": "bun test", - "terraform-validate": "./scripts/terraform_validate.sh", "fmt": "bun x prettier -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf", "fmt:ci": "bun x prettier --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf" }, diff --git a/scripts/terraform_validate.sh b/scripts/terraform_validate.sh deleted file mode 100755 index 2c28a0d..0000000 --- a/scripts/terraform_validate.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -validate_terraform_directory() { - local dir="$1" - echo "Running \`terraform validate\` in $dir" - pushd "$dir" - terraform init -upgrade - terraform validate - popd -} - -main() { - # Get the directory of the script - local script_dir=$(dirname "$(readlink -f "$0")") - - # Code assumes that registry directory will always be in same position - # relative to the main script directory - local registry_dir="$script_dir/../registry" - - # Get all subdirectories in the registry directory. Code assumes that - # Terraform directories won't begin to appear until three levels deep into - # the registry (e.g., registry/coder/modules/coder-login, which will then - # have a main.tf file inside it) - local subdirs=$(find "$registry_dir" -mindepth 3 -type d | sort) - - for dir in $subdirs; do - # Skip over any directories that obviously don't have the necessary - # files - if test -f "$dir/main.tf"; then - validate_terraform_directory "$dir" - fi - done -} - -main