chore: update CONTRIBUTION docs to explain both tests, and update CI for both tests (#384)

Closes #383 

## Description

- Update CONTRIBUTION.md to elaborate on ts and tf tests
- Add ./scripts/terraform_test_all.sh to CI for ts tests

<!-- Briefly describe what this PR does and why -->

## Type of Change

- [ ] New module
- [ ] Bug fix
- [ ] Feature/enhancement
- [X] Documentation
- [X] Other

## Testing & Validation

- [ ] Tests pass (`bun test`)
- [X] Code formatted (`bun run fmt`)
- [ ] Changes tested locally

---------

Co-authored-by: Atif Ali <atif@coder.com>
This commit is contained in:
DevCats
2025-10-09 07:42:07 -05:00
committed by GitHub
parent ce039f64df
commit ccdca6daf5
4 changed files with 31 additions and 22 deletions
+2
View File
@@ -28,6 +28,8 @@ jobs:
run: bun install run: bun install
- name: Run TypeScript tests - name: Run TypeScript tests
run: bun test run: bun test
- name: Run Terraform tests
run: ./scripts/terraform_test_all.sh
- name: Run Terraform Validate - name: Run Terraform Validate
run: bun terraform-validate run: bun terraform-validate
validate-style: validate-style:
+15 -8
View File
@@ -124,18 +124,23 @@ This script generates:
- Accurate description and usage examples - Accurate description and usage examples
- Correct icon path (usually `../../../../.icons/your-icon.svg`) - Correct icon path (usually `../../../../.icons/your-icon.svg`)
- Proper tags that describe your module - Proper tags that describe your module
3. **Create at least one `.tftest.hcl`** to test your module with `terraform test` 3. **Create tests for your module:**
- **Terraform tests**: Create a `*.tftest.hcl` file and test with `terraform test`
- **TypeScript tests**: Create `main.test.ts` file if your module runs scripts or has business logic that Terraform tests can't cover
4. **Add any scripts** or additional files your module needs 4. **Add any scripts** or additional files your module needs
### 4. Test and Submit ### 4. Test and Submit
```bash ```bash
# Test your module (from the module directory) # Test your module
cd registry/[namespace]/modules/[module-name]
# Required: Test Terraform functionality
terraform init -upgrade terraform init -upgrade
terraform test -verbose terraform test -verbose
# Or run all tests in the repo # Optional: Test TypeScript files if you have main.test.ts
./scripts/terraform_test_all.sh bun test main.test.ts
# Format code # Format code
bun run fmt bun run fmt
@@ -343,8 +348,8 @@ coder templates push test-[template-name] -d .
terraform init -upgrade terraform init -upgrade
terraform test -verbose terraform test -verbose
# Test all modules # Optional: If you have TypeScript tests
./scripts/terraform_test_all.sh bun test main.test.ts
``` ```
### 3. Maintain Backward Compatibility ### 3. Maintain Backward Compatibility
@@ -393,7 +398,9 @@ Example: `https://github.com/coder/registry/compare/main...your-branch?template=
### Every Module Must Have ### Every Module Must Have
- `main.tf` - Terraform code - `main.tf` - Terraform code
- One or more `.tftest.hcl` files - Working tests with `terraform test` - **Tests**:
- `*.tftest.hcl` files with `terraform test` (to test terraform specific logic)
- `main.test.ts` file with `bun test` (to test business logic, i.e., `coder_script` to install a package.)
- `README.md` - Documentation with frontmatter - `README.md` - Documentation with frontmatter
### Every Template Must Have ### Every Template Must Have
@@ -493,7 +500,7 @@ When reporting bugs, include:
2. **No tests** or broken tests 2. **No tests** or broken tests
3. **Hardcoded values** instead of variables 3. **Hardcoded values** instead of variables
4. **Breaking changes** without defaults 4. **Breaking changes** without defaults
5. **Not running** formatting (`bun run fmt`) and tests (`terraform test`) before submitting 5. **Not running** formatting (`bun run fmt`) and tests (`terraform test`, and `bun test main.test.ts` if applicable) before submitting
## For Maintainers ## For Maintainers
+2 -2
View File
@@ -15,7 +15,7 @@ run "app_url_uses_port" {
} }
assert { assert {
condition = resource.coder_app.MODULE_NAME.url == "http://localhost:19999" condition = resource.coder_app.module_name.url == "http://localhost:19999"
error_message = "Expected MODULE_NAME app URL to include configured port" error_message = "Expected module-name app URL to include configured port"
} }
} }
+12 -12
View File
@@ -35,13 +35,13 @@ variable "agent_id" {
variable "log_path" { variable "log_path" {
type = string type = string
description = "The path to log MODULE_NAME to." description = "The path to the module log file."
default = "/tmp/MODULE_NAME.log" default = "/tmp/module_name.log"
} }
variable "port" { variable "port" {
type = number type = number
description = "The port to run MODULE_NAME on." description = "The port to run the application on."
default = 19999 default = 19999
} }
@@ -59,9 +59,9 @@ variable "order" {
# Add other variables here # Add other variables here
resource "coder_script" "MODULE_NAME" { resource "coder_script" "module_name" {
agent_id = var.agent_id agent_id = var.agent_id
display_name = "MODULE_NAME" display_name = "Module Name"
icon = local.icon_url icon = local.icon_url
script = templatefile("${path.module}/run.sh", { script = templatefile("${path.module}/run.sh", {
LOG_PATH : var.log_path, LOG_PATH : var.log_path,
@@ -70,10 +70,10 @@ resource "coder_script" "MODULE_NAME" {
run_on_stop = false run_on_stop = false
} }
resource "coder_app" "MODULE_NAME" { resource "coder_app" "module_name" {
agent_id = var.agent_id agent_id = var.agent_id
slug = "MODULE_NAME" slug = "module-name"
display_name = "MODULE_NAME" display_name = "Module Name"
url = "http://localhost:${var.port}" url = "http://localhost:${var.port}"
icon = local.icon_url icon = local.icon_url
subdomain = false subdomain = false
@@ -88,10 +88,10 @@ resource "coder_app" "MODULE_NAME" {
} }
} }
data "coder_parameter" "MODULE_NAME" { data "coder_parameter" "module_name" {
type = "list(string)" type = "string"
name = "MODULE_NAME" name = "module_name"
display_name = "MODULE_NAME" display_name = "Module Name"
icon = local.icon_url icon = local.icon_url
mutable = var.mutable mutable = var.mutable
default = local.options["Option 1"]["value"] default = local.options["Option 1"]["value"]