From 4a5a05352a2f59ee11bd2aa5b65ca6d711f4b941 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Tue, 23 Jul 2024 23:46:54 +0100 Subject: [PATCH] Add build number to application artifact --- .github/workflows/ci.yaml | 2 +- .gitignore | 1 + cdk/jest.setup.js | 4 +++- cdk/lib/__snapshots__/cdk-playground.test.ts.snap | 6 +++--- cdk/lib/cdk-playground.ts | 6 ++++-- script/ci | 4 ++-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0ef58984..326d5bc8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -49,6 +49,6 @@ jobs: cdk.out: - cdk/cdk.out cdk-playground: - - target/cdk-playground.deb + - dist/cdk-playground cdk-playground-lambda: - lambda/cdk-playground-lambda.zip diff --git a/.gitignore b/.gitignore index e2b56d18..e5a4da4b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target logs lambda/cdk-playground-lambda.zip +dist/ diff --git a/cdk/jest.setup.js b/cdk/jest.setup.js index 993e2e71..75f8bd42 100644 --- a/cdk/jest.setup.js +++ b/cdk/jest.setup.js @@ -1 +1,3 @@ -jest.mock("@guardian/cdk/lib/constants/tracking-tag"); +jest.mock('@guardian/cdk/lib/constants/tracking-tag'); + +process.env.GITHUB_RUN_NUMBER = 'TEST'; diff --git a/cdk/lib/__snapshots__/cdk-playground.test.ts.snap b/cdk/lib/__snapshots__/cdk-playground.test.ts.snap index d3a50404..2fff7799 100644 --- a/cdk/lib/__snapshots__/cdk-playground.test.ts.snap +++ b/cdk/lib/__snapshots__/cdk-playground.test.ts.snap @@ -1739,13 +1739,13 @@ exitCode=$? } trap exitTrap EXIT -mkdir -p $(dirname '/cdk-playground/cdk-playground.deb') +mkdir -p $(dirname '/cdk-playground/cdk-playground-TEST.deb') aws s3 cp 's3://", Object { "Ref": "DistributionBucketName", }, - "/playground/PROD/cdk-playground/cdk-playground.deb' '/cdk-playground/cdk-playground.deb' -dpkg -i /cdk-playground/cdk-playground.deb + "/playground/PROD/cdk-playground/cdk-playground-TEST.deb' '/cdk-playground/cdk-playground-TEST.deb' +dpkg -i /cdk-playground/cdk-playground-TEST.deb # GuEc2AppExperimental UserData Start INSTANCE_ID=$(ec2metadata --instance-id) diff --git a/cdk/lib/cdk-playground.ts b/cdk/lib/cdk-playground.ts index f3d0f6a8..a5ee27e8 100644 --- a/cdk/lib/cdk-playground.ts +++ b/cdk/lib/cdk-playground.ts @@ -27,6 +27,8 @@ export class CdkPlayground extends GuStack { const ec2App = 'cdk-playground'; const ec2AppDomainName = 'cdk-playground.gutools.co.uk'; + const buildNumber = process.env.GITHUB_RUN_NUMBER ?? 'DEV'; + const { loadBalancer } = new GuEc2AppExperimental(this, { applicationPort: 9000, app: ec2App, @@ -34,8 +36,8 @@ export class CdkPlayground extends GuStack { access: { scope: AccessScope.PUBLIC }, userData: { distributable: { - fileName: `${ec2App}.deb`, - executionStatement: `dpkg -i /${ec2App}/${ec2App}.deb`, + fileName: `${ec2App}-${buildNumber}.deb`, + executionStatement: `dpkg -i /${ec2App}/${ec2App}-${buildNumber}.deb`, }, }, certificateProps: { diff --git a/script/ci b/script/ci index 81847cfc..a4c52754 100755 --- a/script/ci +++ b/script/ci @@ -17,5 +17,5 @@ set -e sbt clean compile test debian:packageBin -# `sbt debian:packageBin` produces `target/cdk-playground_1.0-SNAPSHOT_all.deb`. Rename it to something easier. -mv target/cdk-playground_1.0-SNAPSHOT_all.deb target/cdk-playground.deb +mkdir -p dist/cdk-playground +mv target/cdk-playground_1.0-SNAPSHOT_all.deb "dist/cdk-playground/cdk-playground-$GITHUB_RUN_NUMBER.deb"