diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index b838ddc..0ca5c6b 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -54,16 +54,22 @@ jobs: name: artifacts-json-first-region path: src - - name: Deploy the function on the published runtime too - if: inputs.published-layer - run: echo "BUN_CMR=1" >> "$GITHUB_ENV" - - name: Build the layer from source if: ${{ !inputs.published-layer }} run: | bun run build:layer echo "BUN_LAYER_ZIP=$PWD/lib/bun-lambda-layer-$(cat .bun-version).zip" >> "$GITHUB_ENV" + # PR runs have no fresh release, so the CMR echo function points at the runtime published + # by the latest GitHub release instead of the stack's region lookup. + - name: Resolve the published runtime for PR runs + if: ${{ !inputs.published-layer }} + run: | + curl -sSfL -o /tmp/artifacts.json \ + https://github.com/${{ github.repository }}/releases/latest/download/artifacts.json + echo "BUN_RUNTIME_ARN=$(jq -r '.regions["eu-central-1"].runtimeArn' /tmp/artifacts.json)" >> "$GITHUB_ENV" + echo "BUN_RUNTIME_ALIAS=$(jq -r '.regions["eu-central-1"].runtimeAlias' /tmp/artifacts.json)" >> "$GITHUB_ENV" + - run: bun run build - run: bun run integ:deploy-test-destroy diff --git a/command/cleanupIntegStacks.sh b/command/cleanupIntegStacks.sh new file mode 100755 index 0000000..ec4dd7f --- /dev/null +++ b/command/cleanupIntegStacks.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Destroys any leftover BunLayerInteg-* CloudFormation stacks, run by the integration +# workflow after the test (which should have destroyed its own stack already). +set -euo pipefail + +stacks=$(aws cloudformation list-stacks \ + --stack-status-filter CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE ROLLBACK_COMPLETE \ + --query 'StackSummaries[].StackName' --output text) + +for stack in $stacks; do + case "$stack" in + BunLayerInteg-*) + echo "Destroying $stack" + (cd examples/sample-app && INTEG_STACK_NAME="$stack" bunx cdk destroy "$stack" --force) + ;; + esac +done diff --git a/examples/sample-app/lib/sample-stack.ts b/examples/sample-app/lib/sample-stack.ts index 74cfdc4..ef5318c 100644 --- a/examples/sample-app/lib/sample-stack.ts +++ b/examples/sample-app/lib/sample-stack.ts @@ -54,12 +54,15 @@ export class SampleStack extends Stack { bunLayer, }); - // Echo on the customer-managed runtime. Needs the published runtime for the stack's region, - // so it is only deployed when BUN_CMR=1 (release runs). - const cmrEchoFn = - process.env.BUN_CMR === "1" - ? new BunFunction(this, "CmrEchoFn", { entrypoint: src("echo.ts") }) - : undefined; + // Echo on the customer-managed runtime (CMR) — no layer involved. Uses the published + // runtime for the stack's region by default; BUN_RUNTIME_ARN/BUN_RUNTIME_ALIAS override it + // for PR runs, which have no release yet and use artifacts.json from the latest GitHub release. + const runtimeArn = process.env.BUN_RUNTIME_ARN; + const runtimeAlias = process.env.BUN_RUNTIME_ALIAS; + const cmrEchoFn = new BunFunction(this, "CmrEchoFn", { + entrypoint: src("echo.ts"), + ...(runtimeArn == null ? {} : { bunRuntime: { runtimeArn, runtimeAlias } }), + }); // Streaming — async generator handler, invoked via InvokeWithResponseStream const streamingFn = new BunFunctionWithLayer(this, "StreamingFn", { @@ -90,9 +93,7 @@ export class SampleStack extends Stack { new CfnOutput(this, "HttpV2PlainFunctionUrl", { value: plainFnUrl.url }); new CfnOutput(this, "HttpV1RestApiUrl", { value: restApi.url }); new CfnOutput(this, "EchoFnArn", { value: echoFn.functionArn }); - if (cmrEchoFn != null) { - new CfnOutput(this, "CmrEchoFnArn", { value: cmrEchoFn.functionArn }); - } + new CfnOutput(this, "CmrEchoFnArn", { value: cmrEchoFn.functionArn }); new CfnOutput(this, "S3WriterFnArn", { value: s3WriterFn.functionArn }); new CfnOutput(this, "TestBucketName", { value: testBucket.bucketName }); new CfnOutput(this, "StreamingFnArn", { value: streamingFn.functionArn }); diff --git a/package.json b/package.json index 9ed8c2c..b0e71ef 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "lint": "oxlint .", "test": "bun test", "integ:deploy-test-destroy": "RUN_AWS_INTEG=1 bun test test/integration/deploy-destroy.test.ts", - "integ:cleanup": "bash -lc \"set -euo pipefail; stacks=$(aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE ROLLBACK_COMPLETE --query 'StackSummaries[].StackName' --output text); for stack in $stacks; do case \\\"$stack\\\" in BunLayerInteg-*) echo \\\"Destroying $stack\\\"; (cd examples/sample-app && INTEG_STACK_NAME=\\\"$stack\\\" bunx cdk destroy \\\"$stack\\\" --force);; esac; done\"" + "integ:cleanup": "bash command/cleanupIntegStacks.sh" }, "devDependencies": { "@aws-sdk/client-lambda": "3.1077.0", diff --git a/test/integration/deploy-destroy.test.ts b/test/integration/deploy-destroy.test.ts index e8a0282..ecb6886 100644 --- a/test/integration/deploy-destroy.test.ts +++ b/test/integration/deploy-destroy.test.ts @@ -29,7 +29,7 @@ interface StackOutputs { HttpV2PlainFunctionUrl: string; HttpV1RestApiUrl: string; EchoFnArn: string; - CmrEchoFnArn?: string; + CmrEchoFnArn: string; S3WriterFnArn: string; TestBucketName: string; StreamingFnArn: string; @@ -129,7 +129,6 @@ describeInteg( }); test("direct invoke echo on the customer-managed runtime", async () => { - if (outputs.CmrEchoFnArn == null) return; const result = await invokeLambda(outputs.CmrEchoFnArn, { hello: "cmr" }); expect((result as { echo: unknown }).echo).toEqual({ hello: "cmr" }); });