Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): add cmdlineToolsVersion override #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions emulator-run-cmd/action.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
name: 'Android Emulator Action combined with a cmd execution'
description: 'Starts Android emulator via existing Android SDK installation and executes a shell command in parallel'
author: 'Malinskiy'
name: "Android Emulator Action combined with a cmd execution"
description: "Starts Android emulator via existing Android SDK installation and executes a shell command in parallel"
author: "Malinskiy"
inputs:
api:
description: 'api version of the emulator'
default: '25'
description: "api version of the emulator"
default: "25"
abi:
description: 'abi of the emulator'
default: 'x86'
description: "abi of the emulator"
default: "x86"
tag:
description: 'default or google_apis'
default: 'default'
description: "default or google_apis"
default: "default"
cmd:
description: 'cmd to execute while the emulator is running'
default: ''
description: "cmd to execute while the emulator is running"
default: ""
disableAnimations:
description: ''
default: 'false'
description: ""
default: "false"
cmdOptions:
description: 'additional emulator options passed to the emulator start cmd'
default: '-no-snapshot-save -noaudio -no-boot-anim'
description: "additional emulator options passed to the emulator start cmd"
default: "-no-snapshot-save -noaudio -no-boot-anim"
hardwareProfile:
description: 'device profile to use. see avdmanager list for possible options'
default: ''
description: "device profile to use. see avdmanager list for possible options"
default: ""
bootTimeout:
description: 'Boot emulator timeout (seconds)'
default: '600'
description: "Boot emulator timeout (seconds)"
default: "600"
verbose:
description: 'be verbose'
default: 'false'
description: "be verbose"
default: "false"
cmdlineToolsVersion:
description: "version of cmdline-tools package to use"
default: "latest"
runs:
using: 'node20'
main: 'lib/main.js'
using: "node20"
main: "lib/main.js"
238 changes: 127 additions & 111 deletions emulator-run-cmd/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,131 +1,147 @@
import * as core from '@actions/core';
import {InputOptions} from "@actions/core/lib/core";
import {SdkFactory} from "./sdk";
import * as core from "@actions/core";
import { InputOptions } from "@actions/core/lib/core";
import { SdkFactory } from "./sdk";
import execWithResult from "./exec-with-result";

async function run() {
try {
let api = core.getInput('api', <InputOptions>{required: false});
if (api == null || api == "") {
console.log(`API not set. Using 25`)
api = '25'
}
try {
let api = core.getInput("api", <InputOptions>{ required: false });
if (api == null || api == "") {
console.log(`API not set. Using 25`);
api = "25";
}

let abi = core.getInput('abi', <InputOptions>{required: false});
if (abi == null || abi == "") {
console.log(`ABI not set. Using armeabi-v7a`)
abi = 'armeabi-v7a'
}
let abi = core.getInput("abi", <InputOptions>{ required: false });
if (abi == null || abi == "") {
console.log(`ABI not set. Using armeabi-v7a`);
abi = "armeabi-v7a";
}

let tag = core.getInput('tag', <InputOptions>{required: false})
if (tag !== "default" && tag !== "google_apis") {
console.log(`Unknown tag ${tag}. Using default`)
tag = 'default'
}
let tag = core.getInput("tag", <InputOptions>{ required: false });
if (tag !== "default" && tag !== "google_apis") {
console.log(`Unknown tag ${tag}. Using default`);
tag = "default";
}

let verbose = false
if (core.getInput('verbose') == "true") {
verbose = true
}
let verbose = false;
if (core.getInput("verbose") == "true") {
verbose = true;
}

let cmd = core.getInput('cmd', <InputOptions>{required: true})
if (cmd === "") {
console.error("Please specify cmd to execute in parallel with emulator")
return
}
let cmd = core.getInput("cmd", <InputOptions>{ required: true });
if (cmd === "") {
console.error("Please specify cmd to execute in parallel with emulator");
return;
}

let cmdOptions = core.getInput('cmdOptions')
if (cmdOptions == null) {
cmdOptions = "-no-snapshot-save -noaudio -no-boot-anim"
}
let cmdOptions = core.getInput("cmdOptions");
if (cmdOptions == null) {
cmdOptions = "-no-snapshot-save -noaudio -no-boot-anim";
}

let hardwareProfile = core.getInput('hardwareProfile')
if (hardwareProfile == null) {
hardwareProfile = ""
}
let hardwareProfile = core.getInput("hardwareProfile");
if (hardwareProfile == null) {
hardwareProfile = "";
}

let disableAnimations = false
if (core.getInput('disableAnimations') == "true") {
disableAnimations = true
}
let disableAnimations = false;
if (core.getInput("disableAnimations") == "true") {
disableAnimations = true;
}

let bootTimeout = core.getInput('bootTimeout')
if (bootTimeout == null) {
bootTimeout = '600'
}
let bootTimeout = core.getInput("bootTimeout");
if (bootTimeout == null) {
bootTimeout = "600";
}

let cmdlineToolsVersion = core.getInput("cmdlineToolsVersion");

console.log(
`Starting emulator with API=${api}, TAG=${tag} and ABI=${abi}...`,
);

console.log(`Starting emulator with API=${api}, TAG=${tag} and ABI=${abi}...`)

const androidHome = process.env.ANDROID_HOME
console.log(`ANDROID_HOME is ${androidHome}`)
console.log(`PATH is ${process.env.PATH}`)

let sdk = new SdkFactory().getAndroidSdk();

try {
await sdk.installEmulatorPackage(api, tag, abi, verbose)
await sdk.installPlatform(api, verbose)

let supportsHardwareAcceleration = await sdk.verifyHardwareAcceleration();
if (!supportsHardwareAcceleration && abi == "x86") {
core.setFailed('Hardware acceleration is not supported')
return
}

let emulator = await sdk.createEmulator("emulator", api, tag, abi, hardwareProfile);
console.log("starting adb server")
await sdk.startAdbServer()
let booted = await emulator.start(cmdOptions, +bootTimeout);
if (!booted) {
core.setFailed("emulator boot failed")
await emulator.stop()
return
}

//Pre-setup
await emulator.unlock()
if (disableAnimations) {
await emulator.disableAnimations()
}
await emulator.startLogcat()

console.log("emulator started and booted")
try {
let result = await execWithResult(`${cmd}`);
let code = result.exitCode;
if (code != 0) {
core.setFailed(`process exited with code ${code}`)
}
} catch (e) {
if(e !instanceof Error) {
core.setFailed(e.message);
} else {
core.setFailed("unknown (error !instanceof Error) occurred")
}
}

console.log("stopping emulator")
await emulator.stop()
await emulator.stopLogcat()
console.log("emulator is stopped")
} catch (error) {
console.error(error)
if(error !instanceof Error) {
core.setFailed(error.message);
} else {
core.setFailed("unknown (error !instanceof Error) occurred")
}
return
const androidHome = process.env.ANDROID_HOME;
console.log(`ANDROID_HOME is ${androidHome}`);
console.log(`PATH is ${process.env.PATH}`);

let sdk = new SdkFactory().getAndroidSdk();

try {
await sdk.installEmulatorPackage(
api,
tag,
abi,
verbose,
cmdlineToolsVersion,
);
await sdk.installPlatform(api, verbose);

let supportsHardwareAcceleration = await sdk.verifyHardwareAcceleration();
if (!supportsHardwareAcceleration && abi == "x86") {
core.setFailed("Hardware acceleration is not supported");
return;
}

let emulator = await sdk.createEmulator(
"emulator",
api,
tag,
abi,
hardwareProfile,
);
console.log("starting adb server");
await sdk.startAdbServer();
let booted = await emulator.start(cmdOptions, +bootTimeout);
if (!booted) {
core.setFailed("emulator boot failed");
await emulator.stop();
return;
}

//Pre-setup
await emulator.unlock();
if (disableAnimations) {
await emulator.disableAnimations();
}
await emulator.startLogcat();

console.log("emulator started and booted");
try {
let result = await execWithResult(`${cmd}`);
let code = result.exitCode;
if (code != 0) {
core.setFailed(`process exited with code ${code}`);
}
} catch (error) {
if(error !instanceof Error) {
core.setFailed(error.message);
} catch (e) {
if (e! instanceof Error) {
core.setFailed(e.message);
} else {
core.setFailed("unknown (error !instanceof Error) occurred")
core.setFailed("unknown (error !instanceof Error) occurred");
}
}

return
console.log("stopping emulator");
await emulator.stop();
await emulator.stopLogcat();
console.log("emulator is stopped");
} catch (error) {
console.error(error);
if (error! instanceof Error) {
core.setFailed(error.message);
} else {
core.setFailed("unknown (error !instanceof Error) occurred");
}
return;
}
} catch (error) {
if (error! instanceof Error) {
core.setFailed(error.message);
} else {
core.setFailed("unknown (error !instanceof Error) occurred");
}

return;
}
}

run();
Loading