From 8887551730dbc7f29254ff788c7f1eac6be2d6a2 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Thu, 13 Jun 2024 13:33:43 -0600 Subject: [PATCH] ci: don't use me-south-1 region for e2e tests when using beta layer (#2614) --- package.json | 3 ++- scripts/e2e-test-regions.json | 38 ++++++++++++++++---------------- scripts/split-e2e-tests.ts | 41 +++++++++++++++++++++++++---------- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 523cd777f1..5b51128fe6 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "rm-dev-link": "rimraf -f \"$(yarn global bin)/amplify-dev\"", "setup-dev-win": "(yarn && lerna run build) && yarn add-cli-no-save && (yarn hoist-cli-win && yarn rm-dev-link && yarn link-win)", "setup-dev": "(yarn && lerna run build) && yarn add-cli-no-save && (yarn hoist-cli && yarn rm-dev-link && yarn link-dev)", - "split-e2e-tests": "yarn ts-node ./scripts/split-e2e-tests.ts && git add codebuild_specs/e2e_workflow.yml", + "split-e2e-tests": "yarn ts-node ./scripts/split-e2e-tests.ts prod && git add codebuild_specs/e2e_workflow.yml", + "split-e2e-tests-beta": "yarn ts-node ./scripts/split-e2e-tests.ts beta && git add codebuild_specs/e2e_workflow.yml", "test-changed": "lerna run test --since main", "test-ci": "lerna run test --concurrency 1 -- --ci -i", "test-v2-transformers": "lerna run --scope '@aws-amplify/graphql-*-transformer' test", diff --git a/scripts/e2e-test-regions.json b/scripts/e2e-test-regions.json index 627d296be7..b7273ab78e 100644 --- a/scripts/e2e-test-regions.json +++ b/scripts/e2e-test-regions.json @@ -1,21 +1,21 @@ [ - { "name": "ap-east-1", "optIn": true, "cognitoSupported": false }, - { "name": "ap-northeast-1", "optIn": false, "cognitoSupported": true }, - { "name": "ap-northeast-2", "optIn": false, "cognitoSupported": true }, - { "name": "ap-south-1", "optIn": false, "cognitoSupported": true }, - { "name": "ap-southeast-1", "optIn": false, "cognitoSupported": true }, - { "name": "ap-southeast-2", "optIn": false, "cognitoSupported": true }, - { "name": "ca-central-1", "optIn": false, "cognitoSupported": true }, - { "name": "eu-central-1", "optIn": false, "cognitoSupported": true }, - { "name": "eu-north-1", "optIn": false, "cognitoSupported": true }, - { "name": "eu-south-1", "optIn": true, "cognitoSupported": true }, - { "name": "eu-west-1", "optIn": false, "cognitoSupported": true }, - { "name": "eu-west-2", "optIn": false, "cognitoSupported": true }, - { "name": "eu-west-3", "optIn": false, "cognitoSupported": true }, - { "name": "me-south-1", "optIn": true, "cognitoSupported": true }, - { "name": "sa-east-1", "optIn": false, "cognitoSupported": true }, - { "name": "us-east-1", "optIn": false, "cognitoSupported": true }, - { "name": "us-east-2", "optIn": false, "cognitoSupported": true }, - { "name": "us-west-1", "optIn": false, "cognitoSupported": true }, - { "name": "us-west-2", "optIn": false, "cognitoSupported": true } + { "name": "ap-east-1", "optIn": true, "cognitoSupported": false, "betaLayerDeployed": true }, + { "name": "ap-northeast-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "ap-northeast-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "ap-south-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "ap-southeast-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "ap-southeast-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "ca-central-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "eu-central-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "eu-north-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "eu-south-1", "optIn": true, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "eu-west-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "eu-west-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "eu-west-3", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "me-south-1", "optIn": true, "cognitoSupported": true, "betaLayerDeployed": false }, + { "name": "sa-east-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "us-east-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "us-east-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "us-west-1", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true }, + { "name": "us-west-2", "optIn": false, "cognitoSupported": true, "betaLayerDeployed": true } ] diff --git a/scripts/split-e2e-tests.ts b/scripts/split-e2e-tests.ts index b8a52ba9d3..2c6d2717cc 100644 --- a/scripts/split-e2e-tests.ts +++ b/scripts/split-e2e-tests.ts @@ -7,18 +7,23 @@ type TestRegion = { name: string; optIn: boolean; cognitoSupported: boolean; + betaLayerDeployed: boolean; // is the beta layer deployed in this region }; const REPO_ROOT = join(__dirname, '..'); const supportedRegionsPath = join(REPO_ROOT, 'scripts', 'e2e-test-regions.json'); -const suportedRegions: TestRegion[] = JSON.parse(fs.readFileSync(supportedRegionsPath, 'utf-8')); -const testRegions = suportedRegions.map((region) => region.name); -const supportedRegionsByRegionName: Record = suportedRegions.reduce( +const supportedRegions: TestRegion[] = JSON.parse(fs.readFileSync(supportedRegionsPath, 'utf-8')); +const testRegions = supportedRegions.map((region) => region.name); +const supportedRegionsByRegionName: Record = supportedRegions.reduce( (acc, region) => ({ ...acc, [region.name]: region }), {}, ); +// list of regions the beta layer is not deployed in +// the tests should not use these regions when using the beta layer +const BETA_LAYER_NOT_DEPLOYED = supportedRegions.filter((region) => !region.betaLayerDeployed).map((region) => region.name); + // https://github.com/aws-amplify/amplify-cli/blob/d55917fd83140817a4447b3def1736f75142df44/packages/amplify-provider-awscloudformation/src/aws-regions.js#L4-L17 const v1TransformerSupportedRegionsPath = join(REPO_ROOT, 'scripts', 'v1-transformer-supported-regions.json'); const v1TransformerSupportedRegions = JSON.parse(fs.readFileSync(v1TransformerSupportedRegionsPath, 'utf-8')).map( @@ -216,7 +221,12 @@ const getTestNameFromPath = (testSuitePath: string, region?: string): string => return testSuitePath.substring(startIndex, endIndex).split('.e2e').join('').split('.').join('-').concat(regionSuffix); }; -const splitTests = (baseJobLinux: any, testDirectory: string, pickTests?: (testSuites: string[]) => string[]): BatchBuildJob[] => { +const splitTests = ( + baseJobLinux: any, + testDirectory: string, + useBetaLayer: boolean = false, + pickTests?: (testSuites: string[]) => string[], +): BatchBuildJob[] => { const output: any[] = []; let testSuites = getTestFiles(testDirectory); if (pickTests && typeof pickTests === 'function') { @@ -245,7 +255,8 @@ const splitTests = (baseJobLinux: any, testDirectory: string, pickTests?: (testS if (RUN_SOLO.find((solo) => test === solo || test.match(solo))) { if (RUN_IN_ALL_REGIONS.find((allRegionsTest) => test === allRegionsTest || test.match(allRegionsTest))) { - const candidateRegions = filterCandidateRegions(test, testRegions); + // always run these jobs in regions that do not have the beta layer deployed + const candidateRegions = filterCandidateRegions(test, testRegions, false); candidateRegions.forEach((region) => { const newSoloJob = createJob(os, jobIdx, true); jobIdx++; @@ -262,14 +273,14 @@ const splitTests = (baseJobLinux: any, testDirectory: string, pickTests?: (testS if (USE_PARENT) { newSoloJob.useParentAccount = true; } - setJobRegion(test, newSoloJob, jobIdx); + setJobRegion(test, newSoloJob, jobIdx, useBetaLayer); soloJobs.push(newSoloJob); continue; } // add the test currentJob.tests.push(test); - setJobRegion(test, currentJob, jobIdx); + setJobRegion(test, currentJob, jobIdx, useBetaLayer); if (USE_PARENT) { currentJob.useParentAccount = true; } @@ -308,7 +319,7 @@ const splitTests = (baseJobLinux: any, testDirectory: string, pickTests?: (testS return result; }; -const setJobRegion = (test: string, job: CandidateJob, jobIdx: number): void => { +const setJobRegion = (test: string, job: CandidateJob, jobIdx: number, useBetaLayer: boolean): void => { const FORCE_REGION = Object.keys(FORCE_REGION_MAP).find((key) => { const testName = getTestNameFromPath(test); return testName.startsWith(key); @@ -325,7 +336,7 @@ const setJobRegion = (test: string, job: CandidateJob, jobIdx: number): void => return; } - const candidateRegions = filterCandidateRegions(test, testRegions); + const candidateRegions = filterCandidateRegions(test, testRegions, useBetaLayer); if (candidateRegions.length === 0) { throw new Error(`No candidate regions found for test ${test}`); @@ -334,7 +345,7 @@ const setJobRegion = (test: string, job: CandidateJob, jobIdx: number): void => job.region = candidateRegions[jobIdx % candidateRegions.length]; }; -const filterCandidateRegions = (test: string, candidateRegions: string[]): string[] => { +const filterCandidateRegions = (test: string, candidateRegions: string[], useBetaLayer: boolean): string[] => { let resolvedRegions = [...candidateRegions]; // Parent E2E account does not have opt-in regions. Choose non-opt-in region. @@ -357,11 +368,16 @@ const filterCandidateRegions = (test: string, candidateRegions: string[]): strin resolvedRegions = resolvedRegions.filter((region) => supportedRegionsByRegionName[region].cognitoSupported); } + if (useBetaLayer) { + resolvedRegions = resolvedRegions.filter((region) => !BETA_LAYER_NOT_DEPLOYED.includes(region)); + } + return resolvedRegions; }; const main = (): void => { - const filteredTests = process.argv.slice(2); + const useBetaLayer = process.argv[2] === 'beta'; + const filteredTests = process.argv.slice(3); const configBase: ConfigBase = loadConfigBase(); const baseBuildGraph = configBase.batch['build-graph']; @@ -376,6 +392,7 @@ const main = (): void => { 'depend-on': ['publish_to_local_registry'], }, join(REPO_ROOT, 'packages', 'amplify-e2e-tests'), + useBetaLayer, ), ...splitTests( { @@ -387,6 +404,7 @@ const main = (): void => { 'depend-on': ['publish_to_local_registry'], }, join(REPO_ROOT, 'packages', 'amplify-graphql-api-construct-tests'), + useBetaLayer, ), ...splitTests( { @@ -398,6 +416,7 @@ const main = (): void => { 'depend-on': ['publish_to_local_registry'], }, join(REPO_ROOT, 'packages', 'graphql-transformers-e2e-tests'), + useBetaLayer, ), ];