Skip to content

Commit ca01bdd

Browse files
Travis Sheppardhaverchuck
authored andcommitted
chore: enable integration tests in gh actions (#1754)
1 parent 544d86b commit ca01bdd

File tree

9 files changed

+310
-34
lines changed

9 files changed

+310
-34
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "Fetch backends"
2+
description: "Downloads Amplify configurations after getting temporary AWS credentials"
3+
inputs:
4+
aws-region:
5+
required: true
6+
role-to-assume:
7+
required: true
8+
# scope for melos, e.g. "amplify_api_example"
9+
scope:
10+
required: true
11+
# Amplify app IDs for specific categories
12+
api-app-id:
13+
required: true
14+
auth-app-id:
15+
required: true
16+
datastore-app-id:
17+
required: true
18+
storage-app-id:
19+
required: true
20+
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: Configure AWS credentials
25+
uses: aws-actions/configure-aws-credentials@05b148adc31e091bafbaf404f745055d4d3bc9d2 # 1.6.1
26+
with:
27+
role-to-assume: ${{ inputs.role-to-assume }}
28+
aws-region: ${{ inputs.aws-region }}
29+
role-duration-seconds: 900
30+
31+
- name: Create AWS profile
32+
run: ./build-support/create_integration_test_profile.sh
33+
shell: bash
34+
35+
- name: Pull Amplify Configurations
36+
run: |
37+
API_APP_ID=${{ inputs.api-app-id }} \
38+
AUTH_APP_ID=${{ inputs.auth-app-id }} \
39+
DATASTORE_APP_ID=${{ inputs.datastore-app-id }} \
40+
STORAGE_APP_ID=${{ inputs.storage-app-id }} \
41+
melos exec --scope=${{ inputs.scope }} ./tool/pull_test_backend.sh
42+
shell: bash
43+
44+
- name: Delete AWS profile
45+
run: rm -rf ~/.aws
46+
shell: bash
47+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: "Install Non-Platform Dependencies"
2+
description: "Installs non-platform dependencies: Amplify CLI, Flutter and runs melos bootstrap"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Install Amplify CLI
8+
# retry once
9+
run: |
10+
yarn global add @aws-amplify/cli --network-timeout 100000 || yarn global add @aws-amplify/cli --network-timeout 100000
11+
shell: bash
12+
13+
- uses: subosito/flutter-action@d8687e6979e8ef66d2b2970e2c92c1d8e801d7bf # 2.4.0
14+
with:
15+
channel: 'stable'
16+
architecture: x64 # needed to prevent "Bad CPU type" error
17+
18+
- name: Run Melos bootstrap
19+
run: |
20+
flutter pub global activate melos 2.4.0
21+
melos bootstrap
22+
shell: bash
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Amplify Integration Tests
2+
on:
3+
push:
4+
branches: [main, next, stable, feat/*]
5+
schedule:
6+
# 6am pacific time daily, only runs on default branch
7+
- cron: '0 13 * * *'
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
android:
15+
runs-on: macos-latest
16+
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
17+
permissions:
18+
id-token: write
19+
contents: read
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
scope: ["amplify_api_example"] #, "amplify_storage_s3_example", "amplify_auth_cognito_example"]
24+
steps:
25+
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
26+
with:
27+
persist-credentials: false
28+
29+
# Flutter requires Java 11 to build android apps with Gradle.
30+
- uses: actions/setup-java@860f60056505705214d223b91ed7a30f173f6142 # 3.3.0
31+
with:
32+
distribution: 'corretto' # Amazon Corretto Build of OpenJDK
33+
java-version: '11'
34+
35+
- name: Install dependencies
36+
uses: ./.github/composite_actions/install_dependencies
37+
38+
- name: Fetch Amplify backend configurations
39+
uses: ./.github/composite_actions/fetch_backends
40+
with:
41+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
42+
aws-region: ${{ secrets.AWS_REGION }}
43+
scope: ${{ matrix.scope }}
44+
api-app-id: ${{ secrets.API_APP_ID }}
45+
auth-app-id: ${{ secrets.AUTH_APP_ID }}
46+
datastore-app-id: ${{ secrets.DATASTORE_APP_ID }}
47+
storage-app-id: ${{ secrets.STORAGE_APP_ID }}
48+
49+
- name: Build example app with integration tests
50+
run: |
51+
melos exec --scope=${{ matrix.scope }} --file-exists="integration_test/main_test.dart" --fail-fast flutter build apk --verbose
52+
53+
- name: Run Android integration tests
54+
uses: reactivecircus/android-emulator-runner@e790971012b979513b4e2fe70d4079bc0ca8a1ae # 2.24.0
55+
timeout-minutes: 25
56+
with:
57+
# API levels 30+ too slow https://github.com/ReactiveCircus/android-emulator-runner/issues/222
58+
api-level: 29
59+
script: melos exec -c 1 --scope ${{ matrix.scope }} -- "deviceId=emulator-5554 retries=1 \$MELOS_ROOT_PATH/build-support/integ_test_android.sh"
60+
61+
ios:
62+
runs-on: macos-latest
63+
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
64+
permissions:
65+
id-token: write
66+
contents: read
67+
strategy:
68+
fail-fast: false
69+
matrix:
70+
scope: ["amplify_api_example"] #, "amplify_storage_s3_example", "amplify_auth_cognito_example"]
71+
steps:
72+
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # 2.4.0
73+
with:
74+
persist-credentials: false
75+
76+
- name: Install dependencies
77+
uses: ./.github/composite_actions/install_dependencies
78+
79+
- name: Boot iOS Simulator
80+
run: |
81+
xcrun simctl boot "iPhone 13"
82+
83+
- name: Fetch Amplify backend configurations
84+
uses: ./.github/composite_actions/fetch_backends
85+
with:
86+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
87+
aws-region: ${{ secrets.AWS_REGION }}
88+
scope: ${{ matrix.scope }}
89+
api-app-id: ${{ secrets.API_APP_ID }}
90+
auth-app-id: ${{ secrets.AUTH_APP_ID }}
91+
datastore-app-id: ${{ secrets.DATASTORE_APP_ID }}
92+
storage-app-id: ${{ secrets.STORAGE_APP_ID }}
93+
94+
- name: Build example app with integration tests
95+
run: |
96+
melos exec --scope=${{ matrix.scope }} flutter build ios --simulator
97+
98+
- name: Run integration tests
99+
run: |
100+
melos exec -c 1 --scope ${{ matrix.scope }} -- "retries=1 \$MELOS_ROOT_PATH/build-support/integ_test_ios.sh"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Podfile.lock
1414
**/test-results/
1515
.test_coverage.dart
1616
.last_build_id
17+
temp/
1718
.fvm/
1819

1920
# IDEs
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
6+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
7+
aws configure set aws_session_token $AWS_SESSION_TOKEN
8+
aws configure set default.region $AWS_DEFAULT_REGION

build-support/integ_test_android.sh

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fi
77

88
DEFAULT_DEVICE_ID="sdk"
99
DEFAULT_ENABLE_CLOUD_SYNC="true"
10+
DEFAULT_RETRIES=0
1011

1112
while [ $# -gt 0 ]; do
1213
case "$1" in
@@ -33,6 +34,7 @@ done
3334

3435
deviceId=${deviceId:-$DEFAULT_DEVICE_ID}
3536
enableCloudSync=${enableCloudSync:-$DEFAULT_ENABLE_CLOUD_SYNC}
37+
retries=${retries:-$DEFAULT_RETRIES}
3638

3739
declare -a testsList
3840
declare -a resultsList
@@ -44,14 +46,28 @@ if [ ! -e $TARGET ]; then
4446
fi
4547

4648
testsList+=("$TARGET")
47-
if flutter test \
48-
--no-pub \
49-
-d $deviceId \
50-
$TARGET; then
51-
resultsList+=(0)
52-
else
53-
resultsList+=(1)
54-
fi
49+
# Run tests with retry.
50+
n=0
51+
until [ "$n" -gt $retries ]
52+
do
53+
if flutter test \
54+
--no-pub \
55+
-d $deviceId \
56+
$TARGET;
57+
then
58+
resultsList+=(0)
59+
break
60+
else
61+
n=$((n+1))
62+
echo "Integration test failed on attempt: $n"
63+
if [ "$n" -gt $retries ]
64+
then
65+
resultsList+=(1)
66+
else
67+
echo "Retrying..."
68+
fi
69+
fi
70+
done
5571

5672
TEST_ENTRIES="integration_test/separate_integration_tests/*.dart"
5773
for ENTRY in $TEST_ENTRIES; do
@@ -65,15 +81,29 @@ for ENTRY in $TEST_ENTRIES; do
6581
echo "Run $ENTRY WITHOUT API Sync"
6682
fi
6783

68-
if flutter test \
69-
--no-pub \
70-
--dart-define ENABLE_CLOUD_SYNC=$enableCloudSync \
71-
-d $deviceId \
72-
$ENTRY; then
73-
resultsList+=(0)
74-
else
75-
resultsList+=(1)
76-
fi
84+
# Run tests with retry.
85+
n=0
86+
until [ "$n" -gt $retries ]
87+
do
88+
if flutter test \
89+
--no-pub \
90+
--dart-define ENABLE_CLOUD_SYNC=$enableCloudSync \
91+
-d $deviceId \
92+
$ENTRY;
93+
then
94+
resultsList+=(0)
95+
break
96+
else
97+
n=$((n+1))
98+
echo "Integration test failed on attempt: $n"
99+
if [ "$n" -gt $retries ]
100+
then
101+
resultsList+=(1)
102+
else
103+
echo "Retrying..."
104+
fi
105+
fi
106+
done
77107
done
78108

79109
testFailure=0

build-support/integ_test_ios.sh

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fi
99

1010
DEFAULT_DEVICE_ID="iPhone"
1111
DEFAULT_ENABLE_CLOUD_SYNC="true"
12+
DEFAULT_RETRIES=0
1213

1314
while [ $# -gt 0 ]; do
1415
case "$1" in
@@ -35,6 +36,7 @@ done
3536

3637
deviceId=${deviceId:-$DEFAULT_DEVICE_ID}
3738
enableCloudSync=${enableCloudSync:-$DEFAULT_ENABLE_CLOUD_SYNC}
39+
retries=${retries:-$DEFAULT_RETRIES}
3840

3941
declare -a testsList
4042
declare -a resultsList
@@ -59,14 +61,28 @@ if xcodebuild -workspace ios/Runner.xcworkspace -list -json | jq -e '.workspace.
5961
test
6062
else
6163
testsList+=("$TARGET")
62-
if flutter test \
63-
--no-pub \
64-
-d $deviceId \
65-
$TARGET; then
66-
resultsList+=(0)
67-
else
68-
resultsList+=(1)
69-
fi
64+
# Run tests with retry.
65+
n=0
66+
until [ "$n" -gt $retries ]
67+
do
68+
if flutter test \
69+
--no-pub \
70+
-d $deviceId \
71+
$TARGET;
72+
then
73+
resultsList+=(0)
74+
break
75+
else
76+
n=$((n+1))
77+
echo "Integration test failed on attempt: $n"
78+
if [ "$n" -gt $retries ]
79+
then
80+
resultsList+=(1)
81+
else
82+
echo "Retrying..."
83+
fi
84+
fi
85+
done
7086
fi
7187

7288
TEST_ENTRIES="integration_test/separate_integration_tests/*.dart"
@@ -81,15 +97,29 @@ for ENTRY in $TEST_ENTRIES; do
8197
echo "Run $ENTRY WITHOUT API Sync"
8298
fi
8399

84-
if flutter test \
85-
--no-pub \
86-
--dart-define ENABLE_CLOUD_SYNC=$enableCloudSync \
87-
-d $deviceId \
88-
$ENTRY; then
89-
resultsList+=(0)
90-
else
91-
resultsList+=(1)
92-
fi
100+
# Run tests with retry.
101+
n=0
102+
until [ "$n" -gt $retries ]
103+
do
104+
if flutter test \
105+
--no-pub \
106+
--dart-define ENABLE_CLOUD_SYNC=$enableCloudSync \
107+
-d $deviceId \
108+
$ENTRY;
109+
then
110+
resultsList+=(0)
111+
break
112+
else
113+
n=$((n+1))
114+
echo "Integration test failed on attempt: $n"
115+
if [ "$n" -gt $retries ]
116+
then
117+
resultsList+=(1)
118+
else
119+
echo "Retrying..."
120+
fi
121+
fi
122+
done
93123
done
94124

95125
testFailure=0

0 commit comments

Comments
 (0)