Skip to content

Commit c6d1152

Browse files
authored
Merge pull request #633 from aws-amplify/fix-e2e-cb
fix: codebuild e2e modelgen tests
2 parents 310e792 + ad37156 commit c6d1152

File tree

10 files changed

+103
-33
lines changed

10 files changed

+103
-33
lines changed

.codebuild/e2e_workflow.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ batch:
3737
CLI_REGION: us-east-2
3838
depend-on:
3939
- publish_to_local_registry
40+
- identifier: build_app_android
41+
buildspec: .codebuild/run_android_modelgen_e2e_test.yml
42+
env:
43+
compute-type: BUILD_GENERAL1_LARGE
44+
variables:
45+
TEST_SUITE: src/__tests__/build-app-android.test.ts
46+
CLI_REGION: us-east-2
47+
depend-on:
48+
- publish_to_local_registry
4049
- identifier: >-
4150
add_codegen_ios_configure_codegen_android_configure_codegen_js_graphql_codegen_android
4251
buildspec: .codebuild/run_e2e_tests.yml
@@ -100,7 +109,7 @@ batch:
100109
variables:
101110
TEST_SUITE: >-
102111
src/__tests__/push-codegen-ios.test.ts|src/__tests__/push-codegen-android.test.ts|src/__tests__/graphql-documents-generator.test.ts|src/__tests__/push-codegen-js.test.ts
103-
CLI_REGION: ap-southeast-1
112+
CLI_REGION: ap-northeast-1
104113
depend-on:
105114
- publish_to_local_registry
106115
- identifier: build_app_ts
@@ -109,16 +118,7 @@ batch:
109118
compute-type: BUILD_GENERAL1_LARGE
110119
variables:
111120
TEST_SUITE: src/__tests__/build-app-ts.test.ts
112-
CLI_REGION: ap-southeast-2
113-
depend-on:
114-
- publish_to_local_registry
115-
- identifier: build_app_android
116-
buildspec: .codebuild/run_e2e_tests.yml
117-
env:
118-
compute-type: BUILD_GENERAL1_MEDIUM
119-
variables:
120-
TEST_SUITE: src/__tests__/build-app-android.test.ts
121-
CLI_REGION: ap-northeast-1
121+
CLI_REGION: ap-southeast-1
122122
depend-on:
123123
- publish_to_local_registry
124124
- identifier: cleanup_e2e_resources

.codebuild/e2e_workflow_base.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ batch:
3737
CLI_REGION: us-east-2
3838
depend-on:
3939
- publish_to_local_registry
40+
- identifier: build_app_android
41+
buildspec: .codebuild/run_android_modelgen_e2e_test.yml
42+
env:
43+
compute-type: BUILD_GENERAL1_LARGE
44+
variables:
45+
TEST_SUITE: src/__tests__/build-app-android.test.ts
46+
CLI_REGION: us-east-2
47+
depend-on:
48+
- publish_to_local_registry
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: 0.2
2+
env:
3+
shell: bash
4+
variables:
5+
AMPLIFY_DIR: /root/.npm-global/lib/node_modules/@aws-amplify/cli-internal/bin
6+
AMPLIFY_PATH: /root/.npm-global/lib/node_modules/@aws-amplify/cli-internal/bin/amplify
7+
CI: true
8+
CODEBUILD: true
9+
NODE_OPTIONS: --max-old-space-size=8096
10+
11+
phases:
12+
install:
13+
commands:
14+
- sudo apt update
15+
- yes | sudo apt install android-sdk
16+
- export ANDROID_HOME=/usr/lib/android-sdk
17+
- yes | sudo apt install sdkmanager
18+
# Review SDK licenses
19+
- yes | sudo sdkmanager --licenses
20+
21+
build:
22+
commands:
23+
- source ./shared-scripts.sh && _runE2ETestsLinux
24+
post_build:
25+
commands:
26+
- aws sts get-caller-identity
27+
- source ./shared-scripts.sh && _scanArtifacts
28+
29+
artifacts:
30+
files:
31+
- $CODEBUILD_SRC_DIR/packages/amplify-codegen-e2e-tests/amplify-e2e-reports/*
32+
discard-paths: yes

.codebuild/scripts/run-ios-modelgen-e2e-test.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ get_latest_run_id() {
1313
echo "$latest_run_id"
1414
}
1515

16-
# Function to get the status of a workflow run
16+
# Function to get the status of a workflow run - can be queued or in_progress or completed
1717
get_run_status() {
1818
run_id="$1"
1919
run_status=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
@@ -24,6 +24,17 @@ get_run_status() {
2424
echo "$run_status"
2525
}
2626

27+
# Function to get the status of a test run - can be success or failure
28+
get_test_status() {
29+
run_id="$1"
30+
test_status=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
31+
-H "Accept: application/vnd.github+json" \
32+
-H "X-GitHub-Api-Version: 2022-11-28" \
33+
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs/$run_id" | \
34+
jq -r '.conclusion')
35+
echo "$test_status"
36+
}
37+
2738
# Function to trigger a workflow dispatch event to run the e2e test
2839
trigger_workflow() {
2940
curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
@@ -40,24 +51,25 @@ main() {
4051
# Get the latest run ID and initial status
4152
latest_run_id=$(get_latest_run_id)
4253
echo "Latest run ID: $latest_run_id"
43-
latest_status=$(get_run_status "$latest_run_id")
54+
run_status=$(get_run_status "$latest_run_id")
4455
timeout=$((SECONDS + 600)) # 600 seconds = 10 minutes
4556

4657
# Continuously check for status until completion
47-
while [[ "$latest_status" != "completed" && "$SECONDS" -lt "$timeout" ]]; do
58+
while [[ "$run_status" != "completed" && "$SECONDS" -lt "$timeout" ]]; do
4859
echo "Test run status: $latest_status"
4960
sleep 10 # Wait before checking again
50-
latest_status=$(get_run_status "$latest_run_id")
61+
run_status=$(get_run_status "$latest_run_id")
5162
done
5263

5364
# Check if the run completed within the specified duration
54-
if [[ "$latest_status" != "completed" ]]; then
65+
if [[ "$run_status" != "completed" ]]; then
5566
echo "The test run did not complete within the specified duration."
5667
exit 1
5768
fi
5869

59-
# Check if the run failed and throw an error if it did
60-
if [[ "$latest_status" == "failure" ]]; then
70+
test_status=$(get_test_status "$latest_run_id")
71+
# Check if the test failed and throw an error if it did
72+
if [[ "$test_status" != "success" ]]; then
6173
echo "The test run failed."
6274
exit 1
6375
else

packages/amplify-codegen-e2e-core/src/init/android.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,26 @@ export function androidBuild(cwd: string, settings: Object = {}): Promise<void>
2525
}
2626
});
2727
});
28-
}
28+
};
29+
30+
export function acceptLicenses(cwd: string, settings: Object = {}): Promise<void> {
31+
return new Promise((resolve, reject) => {
32+
const s = { ...defaultSettings, ...settings };
33+
34+
const chain = spawn('sdkmanager', ['--licenses'], {
35+
cwd,
36+
stripColors: true,
37+
disableCIDetection: s.disableCIDetection
38+
})
39+
.wait("Review licenses that have not been accepted (y/N)?")
40+
.sendLine("y");
41+
42+
chain.run((err: Error) => {
43+
if (err) {
44+
reject(err);
45+
} else {
46+
resolve();
47+
}
48+
});
49+
});
50+
};

packages/amplify-codegen-e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"private": true,
1919
"scripts": {
20-
"e2e": "npm run setup-profile && jest --verbose",
20+
"e2e": "npm run setup-profile && jest --verbose --forceExit",
2121
"setup-profile": "ts-node ./src/configure_tests.ts",
2222
"clean-e2e-resources": "ts-node ./src/cleanup-e2e-resources.ts",
2323
"clean-cb-e2e-resources": "ts-node ./src/cleanup-cb-e2e-resources.ts"

packages/amplify-codegen-e2e-tests/src/__tests__/build-app-android.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
initProjectWithQuickstart,
33
DEFAULT_ANDROID_CONFIG,
4-
addApiWithBlankSchemaAndConflictDetection,
54
updateApiSchemaWithText,
65
generateModels,
76
androidBuild,
7+
acceptLicenses
88
} from '@aws-amplify/amplify-codegen-e2e-core';
99
const { schemas } = require('@aws-amplify/graphql-schema-test-library');
1010
import { existsSync, writeFileSync, readdirSync, rmSync } from 'fs';
@@ -21,6 +21,7 @@ describe('build app - Android', () => {
2121
beforeAll(async () => {
2222
await initProjectWithQuickstart(projectRoot, { ...config });
2323
apiName = readdirSync(path.join(projectRoot, 'amplify', 'backend', 'api'))[0];
24+
await acceptLicenses(projectRoot);
2425
});
2526

2627
afterAll(async () => {

scripts/split-e2e-tests-codebuild.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ const REPO_ROOT = join(__dirname, '..');
2121
const TEST_TIMINGS_PATH = join(REPO_ROOT, 'scripts', 'cci', 'test-timings.data.json');
2222
const CODEBUILD_CONFIG_BASE_PATH = join(REPO_ROOT, '.codebuild', 'e2e_workflow_base.yml');
2323
const CODEBUILD_GENERATE_CONFIG_PATH = join(REPO_ROOT, '.codebuild', 'e2e_workflow.yml');
24-
const RUN_SOLO = [
25-
'src/__tests__/build-app-android.test.ts',
26-
];
24+
const RUN_SOLO = [];
2725
const EXCLUDE_TESTS = [
2826
'src/__tests__/build-app-swift.test.ts',
27+
'src/__tests__/build-app-android.test.ts',
2928
];
3029

3130
export function loadConfigBase() {
@@ -166,7 +165,7 @@ const splitTests = (
166165
tmp.env.variables.USE_PARENT_ACCOUNT = 1;
167166
}
168167
if (j.runSolo) {
169-
tmp.env['compute-type'] = 'BUILD_GENERAL1_MEDIUM';
168+
tmp.env['compute-type'] = 'BUILD_GENERAL1_LARGE';
170169
}
171170
result.push(tmp);
172171
}

scripts/test-swift-modelgen.sh

100644100755
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,17 @@ function buildModels() {
2626

2727
function buildAndRunModel() {
2828
modelName=$1
29-
cd $modelName
30-
currentDirectory=$(pwd)
31-
3229
pathToSwiftPackage=$2
3330

34-
# copy with replace all files in current directory to the swift package
31+
# copy with replace all model files to the swift package
3532
mkdir -p $pathToSwiftPackage/Sources/models
3633
rm -rf $pathToSwiftPackage/Sources/models/*
37-
cp -r $currentDirectory/* $pathToSwiftPackage/Sources/models
34+
cp -r $modelName/* $pathToSwiftPackage/Sources/models
35+
ls $pathToSwiftPackage/Sources/models
3836

3937
# build and run the model
4038
cd $pathToSwiftPackage
4139
swift build && swift run
42-
43-
# clean up
44-
cd $currentDirectory
4540
}
4641

4742
function createSwiftPackage() {

scripts/view-test-artifacts.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)