Support non-integer API level (#317)

* Support non-integer API level

* update lib

* Add test

* No need to install platforms.

Mostly application will use different SDK platform.

* Update lib
This commit is contained in:
LoveSy
2023-02-09 20:07:08 +08:00
committed by GitHub
parent e1248ae048
commit 8e947e5bd6
8 changed files with 19 additions and 10 deletions
+8
View File
@@ -32,6 +32,14 @@ describe('api-level validator tests', () => {
validator.checkApiLevel('29'); validator.checkApiLevel('29');
}; };
expect(func2).not.toThrow(); expect(func2).not.toThrow();
const func3 = () => {
validator.checkApiLevel('UpsideDownCake-ext5');
};
expect(func3).not.toThrow();
const func4 = () => {
validator.checkApiLevel('TiramisuPrivacySandbox');
};
expect(func4).not.toThrow();
}); });
}); });
+2
View File
@@ -6,6 +6,8 @@ exports.VALID_TARGETS = ['default', 'google_apis', 'aosp_atd', 'google_atd', 'go
exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a']; exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a'];
exports.VALID_CHANNELS = ['stable', 'beta', 'dev', 'canary']; exports.VALID_CHANNELS = ['stable', 'beta', 'dev', 'canary'];
function checkApiLevel(apiLevel) { function checkApiLevel(apiLevel) {
if (apiLevel.startsWith('UpsideDownCake') || apiLevel === 'TiramisuPrivacySandbox')
return;
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) { if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
throw new Error(`Unexpected API level: '${apiLevel}'.`); throw new Error(`Unexpected API level: '${apiLevel}'.`);
} }
+2 -3
View File
@@ -61,9 +61,8 @@ function run() {
} }
} }
// API level of the platform and system image // API level of the platform and system image
const apiLevelInput = core.getInput('api-level', { required: true }); const apiLevel = core.getInput('api-level', { required: true });
(0, input_validator_1.checkApiLevel)(apiLevelInput); (0, input_validator_1.checkApiLevel)(apiLevel);
const apiLevel = Number(apiLevelInput);
console.log(`API level: ${apiLevel}`); console.log(`API level: ${apiLevel}`);
// target of the system image // target of the system image
const targetInput = core.getInput('target'); const targetInput = core.getInput('target');
+1 -1
View File
@@ -68,7 +68,7 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk
// accept all Android SDK licenses // accept all Android SDK licenses
yield exec.exec(`sh -c \\"yes | sdkmanager --licenses > /dev/null"`); yield exec.exec(`sh -c \\"yes | sdkmanager --licenses > /dev/null"`);
console.log('Installing latest build tools, platform tools, and platform.'); console.log('Installing latest build tools, platform tools, and platform.');
yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`); yield exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools > /dev/null"`);
console.log('Installing latest emulator.'); console.log('Installing latest emulator.');
yield exec.exec(`sh -c \\"sdkmanager --install emulator --channel=${channelId} > /dev/null"`); yield exec.exec(`sh -c \\"sdkmanager --install emulator --channel=${channelId} > /dev/null"`);
if (emulatorBuild) { if (emulatorBuild) {
+1 -1
View File
@@ -7,7 +7,7 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
* Creates and launches a new AVD instance with the specified configurations. * Creates and launches a new AVD instance with the specified configurations.
*/ */
export async function launchEmulator( export async function launchEmulator(
apiLevel: number, apiLevel: string,
target: string, target: string,
arch: string, arch: string,
profile: string, profile: string,
+1
View File
@@ -4,6 +4,7 @@ export const VALID_ARCHS: Array<string> = ['x86', 'x86_64', 'arm64-v8a'];
export const VALID_CHANNELS: Array<string> = ['stable', 'beta', 'dev', 'canary']; export const VALID_CHANNELS: Array<string> = ['stable', 'beta', 'dev', 'canary'];
export function checkApiLevel(apiLevel: string): void { export function checkApiLevel(apiLevel: string): void {
if (apiLevel.startsWith('UpsideDownCake') || apiLevel === 'TiramisuPrivacySandbox') return;
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) { if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
throw new Error(`Unexpected API level: '${apiLevel}'.`); throw new Error(`Unexpected API level: '${apiLevel}'.`);
} }
+2 -3
View File
@@ -40,9 +40,8 @@ async function run() {
} }
// API level of the platform and system image // API level of the platform and system image
const apiLevelInput = core.getInput('api-level', { required: true }); const apiLevel = core.getInput('api-level', { required: true });
checkApiLevel(apiLevelInput); checkApiLevel(apiLevel);
const apiLevel = Number(apiLevelInput);
console.log(`API level: ${apiLevel}`); console.log(`API level: ${apiLevel}`);
// target of the system image // target of the system image
+2 -2
View File
@@ -12,7 +12,7 @@ const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/comman
* Installs & updates the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator, * Installs & updates the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
* and the system image for the chosen API level, CPU arch, and target. * and the system image for the chosen API level, CPU arch, and target.
*/ */
export async function installAndroidSdk(apiLevel: number, target: string, arch: string, channelId: number, emulatorBuild?: string, ndkVersion?: string, cmakeVersion?: string): Promise<void> { export async function installAndroidSdk(apiLevel: string, target: string, arch: string, channelId: number, emulatorBuild?: string, ndkVersion?: string, cmakeVersion?: string): Promise<void> {
try { try {
console.log(`::group::Install Android SDK`); console.log(`::group::Install Android SDK`);
const isOnMac = process.platform === 'darwin'; const isOnMac = process.platform === 'darwin';
@@ -41,7 +41,7 @@ export async function installAndroidSdk(apiLevel: number, target: string, arch:
console.log('Installing latest build tools, platform tools, and platform.'); console.log('Installing latest build tools, platform tools, and platform.');
await exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`); await exec.exec(`sh -c \\"sdkmanager --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools > /dev/null"`);
console.log('Installing latest emulator.'); console.log('Installing latest emulator.');
await exec.exec(`sh -c \\"sdkmanager --install emulator --channel=${channelId} > /dev/null"`); await exec.exec(`sh -c \\"sdkmanager --install emulator --channel=${channelId} > /dev/null"`);