-
Notifications
You must be signed in to change notification settings - Fork 819
Expand file tree
/
Copy pathselect-region-for-e2e-test.ts
More file actions
36 lines (32 loc) · 1.44 KB
/
select-region-for-e2e-test.ts
File metadata and controls
36 lines (32 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { AWS_REGIONS_TO_RUN_TESTS } from './cci-utils';
import * as fs from 'fs-extra';
import path from 'path';
/**
* This script prints region assignment for an e2e test job.
* The algorithm takes input via environment variable - CODEBUILD_BATCH_BUILD_IDENTIFIER
* and computes deterministic region assignment by looking at position
* of build job in 'wait_for_ids.json' file.
* In order to reshuffle regions 'offset' constant below should be modified.
*
* If region is already assigned, i.e. CLI_REGION environment variable is set this script is pass-through.
*/
// if region is specified by job honor it.
let selectedRegion = process.env.CLI_REGION;
if (!selectedRegion) {
const jobId = process.env.CODEBUILD_BATCH_BUILD_IDENTIFIER;
if (!jobId) {
throw Error('CODEBUILD_BATCH_BUILD_IDENTIFIER environment variable must be set');
}
// Offset should be changed if we want re-shuffle regions.
const offset = 0;
const waitForIdsFilePath = path.join('.', 'codebuild_specs', 'wait_for_ids.json');
const jobIds = JSON.parse(fs.readFileSync(waitForIdsFilePath, 'utf-8')) as Array<string>;
let jobPosition = jobIds.indexOf(jobId);
if (jobPosition < 0) {
// this should never happen if PR checks pass, but just in case fall back to first region.
jobPosition = 0;
}
const regionIndex = (jobPosition + offset) % AWS_REGIONS_TO_RUN_TESTS.length;
selectedRegion = AWS_REGIONS_TO_RUN_TESTS[regionIndex];
}
console.log(selectedRegion);