-
Notifications
You must be signed in to change notification settings - Fork 393
236 lines (227 loc) · 10.9 KB
/
reusable-ui-workflow.yaml
File metadata and controls
236 lines (227 loc) · 10.9 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
on:
workflow_call:
inputs:
is_pr:
type: boolean
default: false
jobs:
test-android:
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/.github/DangerFiles/Gemfile
steps:
- uses: actions/checkout@v4
if: ${{ inputs.is_pr }}
with:
# We need a sufficient depth or Danger will occasionally run into issues checking which files were modified.
fetch-depth: 100
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/checkout@v4
if: ${{ ! inputs.is_pr }}
with:
ref: ${{ github.head_ref }}
- name: Install Dependencies
env:
MSDK_ANDROID_REMOTE_ACCESS_CALLBACK_URL: ${{ secrets.MSDK_ANDROID_REMOTE_ACCESS_CALLBACK_URL }}
MSDK_ANDROID_REMOTE_ACCESS_CONSUMER_KEY: ${{ secrets.MSDK_ANDROID_REMOTE_ACCESS_CONSUMER_KEY }}
UI_TEST_CONFIG: ${{ secrets.UI_TEST_CONFIG }}
run: |
./install.sh
echo $UI_TEST_CONFIG > ./shared/test/ui_test_config.json
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- uses: gradle/actions/setup-gradle@v4
with:
# This is the actual Gradle version (not AGP), which can be found in the gradle-wrapper.properties file.
gradle-version: "8.14.3"
add-job-summary: on-failure
add-job-summary-as-pr-comment: on-failure
- name: Build App for Testing
if: success() || failure()
run: |
./gradlew native:NativeSampleApps:AuthFlowTester:assembleDebug
- name: Build UI Tests
run: |
./gradlew native:NativeSampleApps:AuthFlowTester:assembleAndroidTest
- uses: 'google-github-actions/auth@v2'
if: success() || failure()
with:
credentials_json: '${{ secrets.GCLOUD_SERVICE_KEY }}'
- uses: 'google-github-actions/setup-gcloud@v2'
if: success() || failure()
- name: Run PR Tests
continue-on-error: true
if: ${{ inputs.is_pr }}
env:
# Most used according to https://gs.statcounter.com/android-version-market-share/mobile-tablet/worldwide
PR_API_VERSION: "35"
run: |
GCLOUD_RESULTS_DIR=authflowtester-pr-build-${{github.run_number}}
PR_TESTS="class com.salesforce.samples.authflowtester.BootConfigLoginTests#testCAOpaque_DefaultScopes_WebServerFlow, \
class com.salesforce.samples.authflowtester.ECALoginTests#testECAOpaque_DefaultScopes, \
class com.salesforce.samples.authflowtester.ECALoginTests#testECAJwt_AllScopes, \
class com.salesforce.samples.authflowtester.TokenMigrationTest#testMigrate_ECA_AddMoreScopes, \
class com.salesforce.samples.authflowtester.MultiUserLoginTests#testSameApp_SameScopes_uniqueTokens, \
class com.salesforce.samples.authflowtester.BeaconLoginTests#testBeaconOpaque_DefaultScopes, \
class com.salesforce.samples.authflowtester.AdvancedAuthBeaconLoginTests#testBeaconOpaque_DefaultScopes"
gcloud firebase test android run \
--project mobile-apps-firebase-test \
--type instrumentation \
--use-orchestrator \
--environment-variables clearPackageData=true \
--app "native/NativeSampleApps/AuthFlowTester/build/outputs/apk/debug/AuthFlowTester-debug.apk" \
--test "native/NativeSampleApps/AuthFlowTester/build/outputs/apk/androidTest/debug/AuthFlowTester-debug-androidTest.apk" \
--device model=MediumPhone.arm,version="${PR_API_VERSION}",locale=en,orientation=portrait \
--directories-to-pull=/sdcard \
--results-dir="${GCLOUD_RESULTS_DIR}" \
--results-history-name=AuthFlowTester \
--no-performance-metrics \
--test-targets="${PR_TESTS}" \
--timeout=10m \
--num-flaky-test-attempts=1
- name: Run All Single User Tests
continue-on-error: true
if: ${{ ! inputs.is_pr }}
env:
FULL_API_RANGE: "28 29 30 31 32 33 34 35 36"
run: |
GCLOUD_RESULTS_DIR=authflowtester-single-user-build-${{github.run_number}}
DEVICE_ARGS=()
for LEVEL in $FULL_API_RANGE; do
DEVICE_ARGS+=(--device "model=MediumPhone.arm,version=${LEVEL},locale=en,orientation=portrait")
done
gcloud firebase test android run \
--project mobile-apps-firebase-test \
--type instrumentation \
--use-orchestrator \
--environment-variables clearPackageData=true \
--app "native/NativeSampleApps/AuthFlowTester/build/outputs/apk/debug/AuthFlowTester-debug.apk" \
--test "native/NativeSampleApps/AuthFlowTester/build/outputs/apk/androidTest/debug/AuthFlowTester-debug-androidTest.apk" \
--test-targets "notClass com.salesforce.samples.authflowtester.MultiUserLoginTests" \
"${DEVICE_ARGS[@]}" \
--directories-to-pull=/sdcard \
--results-dir="${GCLOUD_RESULTS_DIR}" \
--results-history-name=AuthFlowTester \
--no-performance-metrics \
--num-flaky-test-attempts=1 \
--timeout=30m || true
- name: Run All Multi User Tests
continue-on-error: true
if: ${{ ! inputs.is_pr }}
env:
FULL_API_RANGE: "28 29 30 31 32 33 34 35 36"
run: |
GCLOUD_RESULTS_DIR=authflowtester-multi-user-build-${{github.run_number}}
DEVICE_ARGS=()
for LEVEL in $FULL_API_RANGE; do
DEVICE_ARGS+=(--device "model=MediumPhone.arm,version=${LEVEL},locale=en,orientation=portrait")
done
gcloud firebase test android run \
--project mobile-apps-firebase-test \
--type instrumentation \
--use-orchestrator \
--environment-variables clearPackageData=true \
--app "native/NativeSampleApps/AuthFlowTester/build/outputs/apk/debug/AuthFlowTester-debug.apk" \
--test "native/NativeSampleApps/AuthFlowTester/build/outputs/apk/androidTest/debug/AuthFlowTester-debug-androidTest.apk" \
--test-targets "class com.salesforce.samples.authflowtester.MultiUserLoginTests" \
"${DEVICE_ARGS[@]}" \
--directories-to-pull=/sdcard \
--results-dir="${GCLOUD_RESULTS_DIR}" \
--results-history-name=AuthFlowTester \
--no-performance-metrics \
--num-flaky-test-attempts=1 \
--timeout=15m || true
- name: Copy Test Results
continue-on-error: true
if: success() || failure()
env:
IS_PR: ${{ inputs.is_pr }}
run: |
mkdir -p firebase_results
BUCKET="gs://test-lab-w87i9sz6q175u-kwp8ium6js0zw"
copy_results_by_api_level() {
local BUCKET_PATH=$1
local OUTPUT_PREFIX=$2
# Pass 1: copy original (non-rerun) results
for RESULT_FILE in $(gsutil ls "${BUCKET_PATH}/*/test_result_1.xml" 2>/dev/null | grep -v "rerun"); do
DEVICE_DIR=$(echo "${RESULT_FILE}" | sed 's|.*/\([^/]*\)/test_result_1.xml|\1|')
API_LEVEL=$(echo "${DEVICE_DIR}" | sed 's/.*-\([0-9]*\)-.*/\1/')
gsutil cp "${RESULT_FILE}" "firebase_results/${OUTPUT_PREFIX}_api_${API_LEVEL}_test_result.xml"
done
# Pass 2: merge rerun testcases into originals so check_retries detects flaky tests
for RESULT_FILE in $(gsutil ls "${BUCKET_PATH}/*/test_result_1.xml" 2>/dev/null | grep "rerun"); do
DEVICE_DIR=$(echo "${RESULT_FILE}" | sed 's|.*/\([^/]*\)/test_result_1.xml|\1|')
API_LEVEL=$(echo "${DEVICE_DIR}" | sed 's/.*-\([0-9]*\)-.*/\1/')
RERUN_TMP="firebase_results/${OUTPUT_PREFIX}_api_${API_LEVEL}_rerun_tmp.xml"
ORIG_FILE="firebase_results/${OUTPUT_PREFIX}_api_${API_LEVEL}_test_result.xml"
gsutil cp "${RESULT_FILE}" "${RERUN_TMP}"
python3 - "${ORIG_FILE}" "${RERUN_TMP}" "${ORIG_FILE}" << 'PYEOF'
import sys, xml.etree.ElementTree as ET
orig = ET.parse(sys.argv[1])
rerun = ET.parse(sys.argv[2])
def suite(t):
r = t.getroot()
return r if r.tag == 'testsuite' else r.find('testsuite')
os_el, rs_el = suite(orig), suite(rerun)
failed_keys = set()
for tc in os_el.findall('testcase'):
if tc.find('failure') is not None or tc.find('error') is not None:
failed_keys.add(f"{tc.get('name','')}|{tc.get('classname','')}|{tc.get('file','')}")
added = 0
for tc in rs_el.findall('testcase'):
if f"{tc.get('name','')}|{tc.get('classname','')}|{tc.get('file','')}" in failed_keys:
os_el.append(tc)
added += 1
os_el.set('tests', str(int(os_el.get('tests','0')) + added))
with open(sys.argv[3], 'w') as f:
f.write(ET.tostring(orig.getroot(), encoding='unicode'))
PYEOF
rm "${RERUN_TMP}"
done
}
if $IS_PR ; then
BUCKET_PATH="${BUCKET}/authflowtester-pr-build-${{github.run_number}}"
if gsutil ls "${BUCKET_PATH}" > /dev/null 2>&1; then
copy_results_by_api_level "${BUCKET_PATH}" "pr"
fi
else
SINGLE_PATH="${BUCKET}/authflowtester-single-user-build-${{github.run_number}}"
if gsutil ls "${SINGLE_PATH}" > /dev/null 2>&1; then
copy_results_by_api_level "${SINGLE_PATH}" "single-user"
fi
MULTI_PATH="${BUCKET}/authflowtester-multi-user-build-${{github.run_number}}"
if gsutil ls "${MULTI_PATH}" > /dev/null 2>&1; then
copy_results_by_api_level "${MULTI_PATH}" "multi-user"
fi
fi
- name: Test Report
uses: mikepenz/action-junit-report@v6
if: success() || failure()
with:
check_name: AuthFlowTester Test Results
job_name: AuthFlowTester Test Results
require_tests: true
check_retries: true
flaky_summary: true
fail_on_failure: true
group_reports: false
include_passed: true
include_empty_in_summary: false
simplified_summary: true
report_paths: 'firebase_results/**.xml'
- name: Archive APK
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: AuthFlowTester-debug-${{ github.run_number }}
path: native/NativeSampleApps/AuthFlowTester/build/outputs/apk/debug/AuthFlowTester-debug.apk
- name: Archive Test Results
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: ui-test-results
path: 'firebase_results/**.xml'