Skip to content

Commit dc087ec

Browse files
committed
feat: let tests run on macos runner
fix: killall script naming chore: debug path issues chore: homebrew android installation in path chore: set path in all steps chore: try to fix path issues chore: keep debugging android sdk install chore: hopefully last sdk fix chore: fix missing env vars chore: return android sdk root to env fix: actually allow 9 emulators fix: try 6 emulators only chore: 6 emulators for all 3 runs fix: try to download arm64 playstore build fix: correct number of workers for macos runner chore: try to run without snapshots for reliability fix: tests cannot run headless
1 parent 0ae81ca commit dc087ec

File tree

4 files changed

+79
-47
lines changed

4 files changed

+79
-47
lines changed

.github/workflows/android-regression.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ run-name: '${{ inputs.RISK }} regressions on ${{ github.head_ref || github.ref }
44
on:
55
workflow_dispatch:
66
inputs:
7+
RUNNER:
8+
description: 'Which runner to use'
9+
required: true
10+
type: choice
11+
options:
12+
- 'linux'
13+
- 'mac'
14+
default: 'linux'
715
APK_URL:
816
description: 'apk url to test (.tar.xz)'
917
required: true
@@ -70,18 +78,17 @@ on:
7078

7179
jobs:
7280
android-regression:
73-
runs-on: [self-hosted, linux, X64, qa-android]
81+
runs-on: ${{ github.event.inputs.RUNNER == 'mac' && fromJSON('["self-hosted", "macOS"]') || fromJSON('["self-hosted", "linux", "X64", "qa-android"]') }}
7482
env:
7583
PLATFORM: 'android'
84+
EMULATOR_COUNT: ${{ github.event.inputs.RUNNER == 'mac' && '6' || '4' }}
7685
APK_URL: ${{ github.event.inputs.APK_URL }}
7786
BUILD_NUMBER: ${{ github.event.inputs.BUILD_NUMBER }}
7887
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7988
CI: 1
8089
ALLURE_ENABLED: ${{ github.event.inputs.ALLURE_ENABLED}}
8190
IOS_APP_PATH_PREFIX: '<just_not_empty>'
8291
ANDROID_APK: './extracted/session-android.apk'
83-
APPIUM_ADB_FULL_PATH: '/opt/android/platform-tools/adb'
84-
ANDROID_SDK_ROOT: '/opt/android'
8592
PLAYWRIGHT_RETRIES_COUNT: ${{ github.event.inputs.PLAYWRIGHT_RETRIES_COUNT }}
8693
PRINT_FAILED_TEST_LOGS: ${{ github.event.inputs.PRINT_FAILED_TEST_LOGS }}
8794
PRINT_ONGOING_TEST_LOGS: ${{ github.event.inputs.PRINT_ONGOING_TEST_LOGS }}
@@ -121,7 +128,11 @@ jobs:
121128
- name: Download APK & extract it
122129
run: |
123130
pwd
124-
wget -q -O session-android.apk.tar.xz ${{ github.event.inputs.APK_URL }}
131+
if [[ "${{ runner.os }}" == "macOS" ]]; then
132+
curl -L -o session-android.apk.tar.xz ${{ github.event.inputs.APK_URL }}
133+
else
134+
wget -q -O session-android.apk.tar.xz ${{ github.event.inputs.APK_URL }}
135+
fi
125136
tar xf session-android.apk.tar.xz
126137
mv session-android-*universal extracted
127138
@@ -144,14 +155,15 @@ jobs:
144155
continue-on-error: true # just so we don't fail if adb wasn't already running
145156
run: |
146157
source ./scripts/ci.sh
158+
echo "ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT}" >> $GITHUB_ENV
147159
adb kill-server;
148160
adb start-server;
149161
150162
- name: Start emulators from snapshot
151163
shell: bash
152164
run: |
153165
source ./scripts/ci.sh
154-
start_with_snapshots
166+
start_for_snapshots
155167
wait_for_emulators
156168
157169
- name: List tests part of this run
@@ -164,7 +176,7 @@ jobs:
164176
continue-on-error: true
165177
id: devices-1-test-run
166178
env:
167-
PLAYWRIGHT_WORKERS_COUNT: 4
179+
PLAYWRIGHT_WORKERS_COUNT: ${{ env.EMULATOR_COUNT }} # 6 on mac, 4 on linux
168180
DEVICES_PER_TEST_COUNT: 1
169181
run: |
170182
pwd
@@ -180,7 +192,7 @@ jobs:
180192
continue-on-error: true
181193
id: devices-2-test-run
182194
env:
183-
PLAYWRIGHT_WORKERS_COUNT: 2
195+
PLAYWRIGHT_WORKERS_COUNT: ${{ github.event.inputs.RUNNER == 'mac' && '3' || '2' }}
184196
DEVICES_PER_TEST_COUNT: 2
185197
run: |
186198
pwd
@@ -196,8 +208,8 @@ jobs:
196208
continue-on-error: true
197209
id: other-devices-test-run
198210
env:
199-
PLAYWRIGHT_WORKERS_COUNT: 1
200-
DEVICES_PER_TEST_COUNT: 4
211+
PLAYWRIGHT_WORKERS_COUNT: ${{ github.event.inputs.RUNNER == 'mac' && '2' || '1' }}
212+
DEVICES_PER_TEST_COUNT: 3
201213
run: |
202214
pwd
203215
_TESTING=${{ github.event.inputs.HIDE_WEBDRIVER_LOGS }} npx playwright test --grep "(?=.*@${PLATFORM})(?=.*@${{ github.event.inputs.RISK }})" --grep-invert "@1-devices|@2-devices" #Note: this has to be double quotes

run/test/specs/utils/binaries.ts

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import { existsSync, lstatSync } from 'fs';
1+
import { existsSync, lstatSync} from 'fs';
22
import { toNumber } from 'lodash';
3+
import * as path from 'path';
34

45
function existsAndFileOrThrow(path: string, id: string) {
56
if (!existsSync(path) || !lstatSync(path).isFile()) {
67
throw new Error(`"${id}" does not exist at: ${path} or not a path`);
78
}
89
}
910

11+
const getAndroidSdkRoot = () => {
12+
const sdkRoot = process.env.ANDROID_SDK_ROOT;
13+
if (!sdkRoot) {
14+
throw new Error('env variable `ANDROID_SDK_ROOT` needs to be set');
15+
}
16+
return sdkRoot;
17+
};
18+
1019
export function getAndroidApk() {
1120
const fromEnv = process.env.ANDROID_APK;
1221
if (!fromEnv) {
@@ -17,48 +26,53 @@ export function getAndroidApk() {
1726
}
1827

1928
export const getAdbFullPath = () => {
20-
const fromEnv = process.env.APPIUM_ADB_FULL_PATH;
21-
if (!fromEnv) {
22-
throw new Error('env variable `APPIUM_ADB_FULL_PATH` needs to be set');
23-
}
24-
25-
existsAndFileOrThrow(fromEnv, 'adb');
26-
27-
return fromEnv;
29+
const sdkRoot = getAndroidSdkRoot();
30+
const adbPath = path.join(sdkRoot, 'platform-tools', 'adb');
31+
existsAndFileOrThrow(adbPath, 'adb');
32+
return adbPath;
2833
};
2934

3035
export const getEmulatorFullPath = () => {
31-
const fromEnv = process.env.EMULATOR_FULL_PATH;
32-
33-
if (!fromEnv) {
34-
throw new Error('env variable `EMULATOR_FULL_PATH` needs to be set');
35-
}
36-
existsAndFileOrThrow(fromEnv, 'EMULATOR_FULL_PATH');
37-
38-
return fromEnv;
36+
const sdkRoot = getAndroidSdkRoot();
37+
const emulatorPath = path.join(sdkRoot, 'emulator', 'emulator');
38+
existsAndFileOrThrow(emulatorPath, 'emulator');
39+
return emulatorPath;
3940
};
4041

4142
export const getAvdManagerFullPath = () => {
42-
const fromEnv = process.env.AVD_MANAGER_FULL_PATH;
43-
44-
if (!fromEnv) {
45-
throw new Error('env variable `AVD_MANAGER_FULL_PATH` needs to be set');
43+
const sdkRoot = getAndroidSdkRoot();
44+
// Try multiple possible locations
45+
const possiblePaths = [
46+
path.join(sdkRoot, 'cmdline-tools', 'latest', 'bin', 'avdmanager'),
47+
path.join(sdkRoot, 'cmdline-tools', 'tools', 'bin', 'avdmanager'),
48+
path.join(sdkRoot, 'tools', 'bin', 'avdmanager')
49+
];
50+
51+
for (const path of possiblePaths) {
52+
if (existsSync(path) && lstatSync(path).isFile()) {
53+
return path;
54+
}
4655
}
47-
existsAndFileOrThrow(fromEnv, 'AVD_MANAGER_FULL_PATH');
48-
49-
return fromEnv;
56+
57+
throw new Error(`avdmanager not found in any expected location under ${sdkRoot}`);
5058
};
5159

5260
export const getSdkManagerFullPath = () => {
53-
const fromEnv = process.env.SDK_MANAGER_FULL_PATH;
54-
55-
if (!fromEnv) {
56-
throw new Error('env variable `SDK_MANAGER_FULL_PATH` needs to be set');
61+
const sdkRoot = getAndroidSdkRoot();
62+
// Try multiple possible locations
63+
const possiblePaths = [
64+
path.join(sdkRoot, 'cmdline-tools', 'latest', 'bin', 'sdkmanager'),
65+
path.join(sdkRoot, 'cmdline-tools', 'tools', 'bin', 'sdkmanager'),
66+
path.join(sdkRoot, 'tools', 'bin', 'sdkmanager')
67+
];
68+
69+
for (const path of possiblePaths) {
70+
if (existsSync(path) && lstatSync(path).isFile()) {
71+
return path;
72+
}
5773
}
58-
59-
existsAndFileOrThrow(fromEnv, 'SDK_MANAGER_FULL_PATH');
60-
61-
return fromEnv;
74+
75+
throw new Error(`sdkmanager not found in any expected location under ${sdkRoot}`);
6276
};
6377

6478
export const getAndroidSystemImageToUse = () => {

run/test/specs/utils/capabilities_android.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const emulator5Udid = 'emulator-5562';
3535
const emulator6Udid = 'emulator-5564';
3636
const emulator7Udid = 'emulator-5566';
3737
const emulator8Udid = 'emulator-5568';
38+
const emulator9Udid = 'emulator-5570';
3839

3940
const udids = [
4041
emulator1Udid,
@@ -45,6 +46,7 @@ const udids = [
4546
emulator6Udid,
4647
emulator7Udid,
4748
emulator8Udid,
49+
emulator9Udid,
4850
];
4951

5052
const emulatorCapabilities: AppiumCapabilities[] = udids.map(udid => ({
@@ -61,6 +63,7 @@ const emulatorCapabilities5 = emulatorCapabilities[4];
6163
const emulatorCapabilities6 = emulatorCapabilities[5];
6264
const emulatorCapabilities7 = emulatorCapabilities[6];
6365
const emulatorCapabilities8 = emulatorCapabilities[7];
66+
const emulatorCapabilities9 = emulatorCapabilities[8];
6467

6568
export const androidCapabilities = {
6669
sharedCapabilities,
@@ -77,6 +80,7 @@ function getAllCaps() {
7780
emulatorCapabilities6,
7881
emulatorCapabilities7,
7982
emulatorCapabilities8,
83+
emulatorCapabilities9,
8084
];
8185
return emulatorCaps;
8286
}

scripts/ci.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ set -x
66
if [[ "$OSTYPE" == "darwin"* ]]; then
77
# Mac settings
88
ARCH="arm64-v8a"
9-
EMULATOR_COUNT=9
9+
EMULATOR_COUNT=6
1010
API_LEVEL="35"
1111
ANDROID_CMD="commandlinetools-mac-13114758_latest.zip"
1212
EMULATOR_BIN="emulator"
13-
TARGET="google_apis" # Mac ARM doesn't have playstore variant
13+
TARGET="google_apis_playstore" # Mac ARM doesn't have playstore variant
14+
ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT:-"$HOME/Android/sdk"}
1415
else
1516
# Linux settings
1617
ARCH="x86_64"
@@ -19,6 +20,7 @@ else
1920
ANDROID_CMD="commandlinetools-linux-13114758_latest.zip"
2021
EMULATOR_BIN="emulator"
2122
TARGET="google_apis_playstore" # Linux can use playstore
23+
ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT:-"/opt/android"}
2224
fi
2325

2426

@@ -31,7 +33,7 @@ EMULATOR_PACKAGE="system-images;${ANDROID_API_LEVEL};${ANDROID_APIS}"
3133
PLATFORM_VERSION="platforms;${ANDROID_API_LEVEL}"
3234
BUILD_TOOL="build-tools;${BUILD_TOOLS}"
3335
export ANDROID_SDK_PACKAGES="${EMULATOR_PACKAGE} ${PLATFORM_VERSION} ${BUILD_TOOL} platform-tools"
34-
export ANDROID_SDK_ROOT=/opt/android
36+
export ANDROID_SDK_ROOT
3537

3638
export PATH="$PATH:$ANDROID_SDK_ROOT/cmdline-tools/tools:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/tools/bin:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/build-tools/${BUILD_TOOLS}:$ANDROID_SDK_ROOT/platform-tools/"
3739
export EMULATOR_DEVICE="pixel_6" # all emulators are created with the pixel 6 spec for now
@@ -107,8 +109,8 @@ function start_for_snapshots() {
107109
for i in $(seq 1 $EMULATOR_COUNT)
108110
do
109111
if [[ "$OSTYPE" == "darwin"* ]]; then
110-
# Mac: Headless
111-
$EMULATOR_BIN @emulator$i -no-window -no-snapshot-load &
112+
# Mac: Not headless
113+
$EMULATOR_BIN @emulator$i -no-snapshot-load &
112114
else
113115
# Linux: Keep as-is with display
114116
DISPLAY=:0 $EMULATOR_BIN @emulator$i -gpu host -accel on -no-snapshot-load &
@@ -130,7 +132,7 @@ function force_save_snapshots() {
130132

131133
function killall_emulators() {
132134
if [[ "$OSTYPE" == "darwin"* ]]; then
133-
killall qemu-system-aarch64 2>/dev/null || true
135+
killall qemu-system-aarch64-headless 2>/dev/null || true
134136
else
135137
killall qemu-system-x86_64 2>/dev/null || true
136138
fi

0 commit comments

Comments
 (0)