From 61ad5ac3bcf7742684aeec28553ec294696f3301 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 28 Sep 2023 11:49:44 +0200 Subject: [PATCH] feat(layers): add `arm64` to integration test matrix (#1720) * feat(layers): add arm64 to test matrix --- .github/workflows/run-e2e-tests.yml | 20 +++++++++--- packages/idempotency/tests/e2e/constants.ts | 2 +- packages/logger/tests/e2e/constants.ts | 2 +- packages/metrics/tests/e2e/constants.ts | 2 +- packages/parameters/tests/e2e/constants.ts | 2 +- .../parameters/tests/helpers/resources.ts | 3 +- packages/testing/src/constants.ts | 22 +++++++++++-- packages/testing/src/helpers.ts | 31 ++++++++++++++++--- .../src/resources/TestNodejsFunction.ts | 9 ++++-- packages/tracer/tests/e2e/constants.ts | 2 +- 10 files changed, 76 insertions(+), 19 deletions(-) diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml index 67a9c4678e..38c85edcf7 100644 --- a/.github/workflows/run-e2e-tests.yml +++ b/.github/workflows/run-e2e-tests.yml @@ -4,9 +4,9 @@ on: workflow_dispatch: inputs: prNumber: - description: "(Optional) PR Number. If you specify a value the value of the branch field will be ignored." + description: '(Optional) PR Number. If you specify a value the value of the branch field will be ignored.' required: false - default: "" + default: '' jobs: run-e2e-tests-on-utils: @@ -19,12 +19,21 @@ jobs: contents: read strategy: matrix: - package: [layers, packages/logger, packages/metrics, packages/tracer, packages/parameters, packages/idempotency] + package: + [ + layers, + packages/logger, + packages/metrics, + packages/tracer, + packages/parameters, + packages/idempotency, + ] version: [14, 16, 18] + arch: [x86_64, arm64] fail-fast: false steps: - name: Checkout Repo - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 # If we pass a PR Number when triggering the workflow we will retrieve the PR info and get its headSHA - name: Extract PR details id: extract_PR_details @@ -38,7 +47,7 @@ jobs: # we checkout the PR at that point in time - name: Checkout PR code if: ${{ inputs.prNumber != '' }} - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 with: ref: ${{ steps.extract_PR_details.outputs.headSHA }} - name: Setup NodeJS @@ -59,5 +68,6 @@ jobs: env: RUNTIME: nodejs${{ matrix.version }}x CI: true + ARCH: ${{ matrix.arch }} JSII_SILENCE_WARNING_DEPRECATED_NODE_VERSION: true run: npm run test:e2e -w ${{ matrix.package }} diff --git a/packages/idempotency/tests/e2e/constants.ts b/packages/idempotency/tests/e2e/constants.ts index 12497dc8b4..53cb30860f 100644 --- a/packages/idempotency/tests/e2e/constants.ts +++ b/packages/idempotency/tests/e2e/constants.ts @@ -1,4 +1,4 @@ -export const RESOURCE_NAME_PREFIX = 'Idempotency-E2E'; +export const RESOURCE_NAME_PREFIX = 'Idempotency'; export const ONE_MINUTE = 60 * 1_000; export const TEARDOWN_TIMEOUT = 5 * ONE_MINUTE; diff --git a/packages/logger/tests/e2e/constants.ts b/packages/logger/tests/e2e/constants.ts index 11ac263ae4..d4e2b18e8e 100644 --- a/packages/logger/tests/e2e/constants.ts +++ b/packages/logger/tests/e2e/constants.ts @@ -1,6 +1,6 @@ import { randomUUID } from 'node:crypto'; -const RESOURCE_NAME_PREFIX = 'Logger-E2E'; +const RESOURCE_NAME_PREFIX = 'Logger'; const ONE_MINUTE = 60 * 1000; const TEST_CASE_TIMEOUT = ONE_MINUTE; const SETUP_TIMEOUT = 5 * ONE_MINUTE; diff --git a/packages/metrics/tests/e2e/constants.ts b/packages/metrics/tests/e2e/constants.ts index 987e234b62..bb6068f56d 100644 --- a/packages/metrics/tests/e2e/constants.ts +++ b/packages/metrics/tests/e2e/constants.ts @@ -1,7 +1,7 @@ import { randomUUID } from 'node:crypto'; import { MetricUnits } from '../../src'; -const RESOURCE_NAME_PREFIX = 'Metrics-E2E'; +const RESOURCE_NAME_PREFIX = 'Metrics'; const ONE_MINUTE = 60 * 1000; const TEST_CASE_TIMEOUT = 3 * ONE_MINUTE; const SETUP_TIMEOUT = 5 * ONE_MINUTE; diff --git a/packages/parameters/tests/e2e/constants.ts b/packages/parameters/tests/e2e/constants.ts index e750986dea..757a2b4290 100644 --- a/packages/parameters/tests/e2e/constants.ts +++ b/packages/parameters/tests/e2e/constants.ts @@ -1,4 +1,4 @@ -export const RESOURCE_NAME_PREFIX = 'Parameters-E2E'; +export const RESOURCE_NAME_PREFIX = 'Parameters'; export const ONE_MINUTE = 60 * 1000; export const TEST_CASE_TIMEOUT = 3 * ONE_MINUTE; export const SETUP_TIMEOUT = 5 * ONE_MINUTE; diff --git a/packages/parameters/tests/helpers/resources.ts b/packages/parameters/tests/helpers/resources.ts index 7067f608fd..0be54d8db4 100644 --- a/packages/parameters/tests/helpers/resources.ts +++ b/packages/parameters/tests/helpers/resources.ts @@ -6,6 +6,7 @@ import type { import { concatenateResourceName, getRuntimeKey, + getArchitectureKey, TestDynamodbTable, TestNodejsFunction, } from '@aws-lambda-powertools/testing-utils'; @@ -58,7 +59,7 @@ class TestSecureStringParameter extends Construct { const { value } = props; - const name = `/secure/${getRuntimeKey()}/${randomUUID()}`; + const name = `/secure/${getRuntimeKey()}/${getArchitectureKey()}/${randomUUID()}`; const secureStringCreator = new AwsCustomResource( testStack.stack, `create-${randomUUID()}`, diff --git a/packages/testing/src/constants.ts b/packages/testing/src/constants.ts index 85d66e625a..e29fbe0132 100644 --- a/packages/testing/src/constants.ts +++ b/packages/testing/src/constants.ts @@ -1,4 +1,4 @@ -import { Runtime } from 'aws-cdk-lib/aws-lambda'; +import { Runtime, Architecture } from 'aws-cdk-lib/aws-lambda'; /** * The default AWS Lambda runtime to use when none is provided. @@ -14,4 +14,22 @@ const TEST_RUNTIMES = { [defaultRuntime]: Runtime.NODEJS_18_X, } as const; -export { TEST_RUNTIMES, defaultRuntime }; +/** + * The default AWS Lambda architecture to use when none is provided. + */ +const defaultArchitecture = 'x86_64'; + +/** + * The AWS Lambda architectures that are supported by the project. + */ +const TEST_ARCHITECTURES = { + [defaultArchitecture]: Architecture.X86_64, + arm64: Architecture.ARM_64, +} as const; + +export { + TEST_RUNTIMES, + defaultRuntime, + TEST_ARCHITECTURES, + defaultArchitecture, +}; diff --git a/packages/testing/src/helpers.ts b/packages/testing/src/helpers.ts index 4a737590b2..ab1a0222e5 100644 --- a/packages/testing/src/helpers.ts +++ b/packages/testing/src/helpers.ts @@ -1,5 +1,10 @@ import { randomUUID } from 'node:crypto'; -import { TEST_RUNTIMES, defaultRuntime } from './constants'; +import { + TEST_RUNTIMES, + defaultRuntime, + TEST_ARCHITECTURES, + defaultArchitecture, +} from './constants'; const isValidRuntimeKey = ( runtime: string @@ -15,6 +20,21 @@ const getRuntimeKey = (): keyof typeof TEST_RUNTIMES => { return runtime; }; +const isValidArchitectureKey = ( + architecture: string +): architecture is keyof typeof TEST_ARCHITECTURES => + architecture in TEST_ARCHITECTURES; + +const getArchitectureKey = (): keyof typeof TEST_ARCHITECTURES => { + const architecture: string = process.env.ARCH || defaultArchitecture; + + if (!isValidArchitectureKey(architecture)) { + throw new Error(`Invalid architecture key value: ${architecture}`); + } + + return architecture; +}; + /** * Generate a unique name for a test. * @@ -23,10 +43,11 @@ const getRuntimeKey = (): keyof typeof TEST_RUNTIMES => { * @example * ```ts * process.env.RUNTIME = 'nodejs18x'; - * const testPrefix = 'E2E-TRACER'; + * process.env.ARCH = 'x86_64'; + * const testPrefix = 'TRACER'; * const testName = 'someFeature'; * const uniqueName = generateTestUniqueName({ testPrefix, testName }); - * // uniqueName = 'E2E-TRACER-node18-12345-someFeature' + * // uniqueName = 'TRACER-18-x86-12345-someFeature' * ``` */ const generateTestUniqueName = ({ @@ -38,7 +59,8 @@ const generateTestUniqueName = ({ }): string => [ testPrefix, - getRuntimeKey().replace(/[jsx]/g, ''), + getRuntimeKey().replace(/[nodejsx]/g, ''), + getArchitectureKey().replace(/_64/g, ''), randomUUID().toString().substring(0, 5), testName, ] @@ -81,4 +103,5 @@ export { generateTestUniqueName, concatenateResourceName, findAndGetStackOutputValue, + getArchitectureKey, }; diff --git a/packages/testing/src/resources/TestNodejsFunction.ts b/packages/testing/src/resources/TestNodejsFunction.ts index d247551723..8ee0ed2f6b 100644 --- a/packages/testing/src/resources/TestNodejsFunction.ts +++ b/packages/testing/src/resources/TestNodejsFunction.ts @@ -3,8 +3,12 @@ import { Tracing } from 'aws-cdk-lib/aws-lambda'; import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'; import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import { randomUUID } from 'node:crypto'; -import { TEST_RUNTIMES } from '../constants'; -import { concatenateResourceName, getRuntimeKey } from '../helpers'; +import { TEST_RUNTIMES, TEST_ARCHITECTURES } from '../constants'; +import { + concatenateResourceName, + getRuntimeKey, + getArchitectureKey, +} from '../helpers'; import type { TestStack } from '../TestStack'; import type { ExtraTestProps, TestNodejsFunctionProps } from './types'; @@ -29,6 +33,7 @@ class TestNodejsFunction extends NodejsFunction { resourceName: extraProps.nameSuffix, }), runtime: TEST_RUNTIMES[getRuntimeKey()], + architecture: TEST_ARCHITECTURES[getArchitectureKey()], logRetention: RetentionDays.ONE_DAY, }); diff --git a/packages/tracer/tests/e2e/constants.ts b/packages/tracer/tests/e2e/constants.ts index 7e817e1aac..e6b5547c0b 100644 --- a/packages/tracer/tests/e2e/constants.ts +++ b/packages/tracer/tests/e2e/constants.ts @@ -1,5 +1,5 @@ // Prefix for all resources created by the E2E tests -const RESOURCE_NAME_PREFIX = 'Tracer-E2E'; +const RESOURCE_NAME_PREFIX = 'Tracer'; // Constants relating time to be used in the tests const ONE_MINUTE = 60 * 1_000; const TEST_CASE_TIMEOUT = 5 * ONE_MINUTE;