From e64f1ede52c9124af3e9baab2e33104e9ab778c9 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 28 Jan 2025 01:13:07 -0500 Subject: [PATCH] fix: ensure Terraform is available for integration tests (#390) --- .github/workflows/ci.yaml | 19 ++++++++++++++----- setup.ts | 2 +- test.ts | 15 ++++++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c5d9c73..2de2364 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,14 +16,23 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: coder/coder/.github/actions/setup-tf@main - - uses: oven-sh/setup-bun@v2 + - name: Check out code + uses: actions/checkout@v4 + - name: Set up Terraform + uses: coder/coder/.github/actions/setup-tf@main + - name: Set up Bun + uses: oven-sh/setup-bun@v2 with: + # We're using the latest version of Bun for now, but it might be worth + # reconsidering. They've pushed breaking changes in patch releases + # that have broken our CI. + # Our PR where issues started to pop up: https://github.com/coder/modules/pull/383 + # The Bun PR that broke things: https://github.com/oven-sh/bun/pull/16067 bun-version: latest - - name: Setup + - name: Install dependencies run: bun install - - run: bun test + - name: Run tests + run: bun test pretty: runs-on: ubuntu-latest steps: diff --git a/setup.ts b/setup.ts index 3cfb871..a867c75 100644 --- a/setup.ts +++ b/setup.ts @@ -25,7 +25,7 @@ const removeOldContainers = async () => { "-a", "-q", "--filter", - `label=modules-test`, + "label=modules-test", ]); let containerIDsRaw = await readableStreamToText(proc.stdout); let exitCode = await proc.exited; diff --git a/test.ts b/test.ts index 5437374..0c48ee9 100644 --- a/test.ts +++ b/test.ts @@ -194,13 +194,18 @@ export const testRequiredVariables = ( export const runTerraformApply = async ( dir: string, vars: Readonly, - env?: Record, + customEnv?: Record, ): Promise => { const stateFile = `${dir}/${crypto.randomUUID()}.tfstate`; - const combinedEnv = env === undefined ? {} : { ...env }; - for (const [key, value] of Object.entries(vars)) { - combinedEnv[`TF_VAR_${key}`] = String(value); + const childEnv: Record = { + ...process.env, + ...(customEnv ?? {}), + }; + for (const [key, value] of Object.entries(vars) as [string, JsonValue][]) { + if (value !== null) { + childEnv[`TF_VAR_${key}`] = String(value); + } } const proc = spawn( @@ -216,7 +221,7 @@ export const runTerraformApply = async ( ], { cwd: dir, - env: combinedEnv, + env: childEnv, stderr: "pipe", stdout: "pipe", },