diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bea8b0ea..694c5b8f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -77,18 +77,13 @@ jobs: - name: Get test environment name id: get_test_env_name shell: bash + env: + REF_NAME: ${{ github.head_ref || github.ref_name }} # When the trigger is a pull event, use the PR's branch name (`github.head_ref`), which # is available only for pull trigger. Otherwise, use the branch on which the commit was pushed. # (Ref names in pull requests are in the shape of `/merge` and those will break CDK.) run: | - export REF_NAME="${{ github.head_ref || github.ref_name }}" - # Ensure test name is not long enough to break restrictions on length names in AWS (e.g., role-name length) - # This logic ensures test envs have max length 18. Names of length 13 to 17 will become of length 18 to ensure - # no accidental clashes. - if [[ ${#REF_NAME} -gt 12 ]]; then - REF_NAME="${REF_NAME:0:12}-$(echo "${REF_NAME:12}" | md5sum | awk '{print $1}' | cut -c 1-5 | tr -d '\n')" - fi - echo "test_env_name=${REF_NAME}" >> $GITHUB_OUTPUT || exit 1 + echo "test_env_name=$(./.github/workflows/scripts/test_env_name.sh)" >> $GITHUB_OUTPUT || exit 1 - name: Deploy validation backend shell: bash diff --git a/.github/workflows/clean-up-test-env.yaml b/.github/workflows/clean-up-test-env.yaml index 35fc80f2..59b76adc 100644 --- a/.github/workflows/clean-up-test-env.yaml +++ b/.github/workflows/clean-up-test-env.yaml @@ -26,6 +26,17 @@ jobs: run: | npm ci + - name: Get test environment name + id: get_test_env_name + shell: bash + env: + REF_NAME: ${{ github.head_ref || github.ref_name }} + # When the trigger is a pull event, use the PR's branch name (`github.head_ref`), which + # is available only for pull trigger. Otherwise, use the branch on which the commit was pushed. + # (Ref names in pull requests are in the shape of `/merge` and those will break CDK.) + run: | + echo "test_env_name=$(./.github/workflows/scripts/test_env_name.sh)" >> $GITHUB_OUTPUT || exit 1 + - name: Delete validation backend shell: bash working-directory: packages/otelbin-validation diff --git a/.github/workflows/scripts/test_env_name.sh b/.github/workflows/scripts/test_env_name.sh new file mode 100755 index 00000000..36da25cc --- /dev/null +++ b/.github/workflows/scripts/test_env_name.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Ensure test name is not long enough to break restrictions on length names in AWS (e.g., role-name length) +# This logic ensures test envs have max length 18. Names of length 13 to 17 will become of length 18 to ensure +# no accidental clashes. +if [[ ${#REF_NAME} -gt 12 ]]; then + REF_NAME="${REF_NAME:0:12}-$(echo "${REF_NAME:12}" | md5sum | awk '{print $1}' | cut -c 1-5 | tr -d '\n')" +fi + +echo "${REF_NAME}" \ No newline at end of file diff --git a/packages/otelbin-validation/src/main.ts b/packages/otelbin-validation/src/main.ts index 46d25618..8431053d 100644 --- a/packages/otelbin-validation/src/main.ts +++ b/packages/otelbin-validation/src/main.ts @@ -5,6 +5,7 @@ import { ApiKeySourceType, AwsIntegration, LambdaIntegration, RestApi, UsagePlan import { Platform } from 'aws-cdk-lib/aws-ecr-assets'; import { PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; import { Architecture, DockerImageCode, DockerImageFunction } from 'aws-cdk-lib/aws-lambda'; +import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import { Bucket, BlockPublicAccess } from 'aws-cdk-lib/aws-s3'; import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment'; import { Construct } from 'constructs'; @@ -166,6 +167,7 @@ export class OTelBinValidationStack extends Stack { */ memorySize: 1024, timeout: Duration.seconds(15), + logRetention: RetentionDays.THREE_DAYS, }); const releaseResource = distributionResource.addResource(release.version);