Skip to content

Commit

Permalink
Merge pull request #181 from dash0hq/env-deletion-fix
Browse files Browse the repository at this point in the history
fix: test environment deletion on PR closing
  • Loading branch information
mmanciop authored Nov 8, 2023
2 parents 27e53eb + bcf8b79 commit 755791d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<pr_id>/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
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/clean-up-test-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<pr_id>/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
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/scripts/test_env_name.sh
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 2 additions & 0 deletions packages/otelbin-validation/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 755791d

Please sign in to comment.