|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 12 | + if (mod && mod.__esModule) return mod; |
| 13 | + var result = {}; |
| 14 | + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
| 15 | + result["default"] = mod; |
| 16 | + return result; |
| 17 | +}; |
| 18 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 19 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 20 | +}; |
| 21 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 22 | +const core = __importStar(require("@actions/core")); |
| 23 | +const sdk_1 = require("./sdk"); |
| 24 | +const exec_with_result_1 = __importDefault(require("./exec-with-result")); |
| 25 | +function run() { |
| 26 | + return __awaiter(this, void 0, void 0, function* () { |
| 27 | + try { |
| 28 | + let api = core.getInput('api', { required: false }); |
| 29 | + if (api == null || api == "") { |
| 30 | + console.log(`API not set. Using 25`); |
| 31 | + api = '25'; |
| 32 | + } |
| 33 | + let abi = core.getInput('abi', { required: false }); |
| 34 | + if (abi == null || abi == "") { |
| 35 | + console.log(`ABI not set. Using armeabi-v7a`); |
| 36 | + abi = 'armeabi-v7a'; |
| 37 | + } |
| 38 | + let tag = core.getInput('tag', { required: false }); |
| 39 | + if (tag !== "default" && tag !== "google_apis") { |
| 40 | + console.log(`Unknown tag ${tag}. Using default`); |
| 41 | + tag = 'default'; |
| 42 | + } |
| 43 | + let verbose = false; |
| 44 | + if (core.getInput('verbose') == "true") { |
| 45 | + verbose = true; |
| 46 | + } |
| 47 | + let cmd = core.getInput('cmd', { required: true }); |
| 48 | + if (cmd === "") { |
| 49 | + console.error("Please specify cmd to execute in parallel with emulator"); |
| 50 | + return; |
| 51 | + } |
| 52 | + let cmdOptions = core.getInput('cmdOptions'); |
| 53 | + if (cmdOptions == null) { |
| 54 | + cmdOptions = "-no-snapshot-save -noaudio -no-boot-anim"; |
| 55 | + } |
| 56 | + let hardwareProfile = core.getInput('hardwareProfile'); |
| 57 | + if (hardwareProfile == null) { |
| 58 | + hardwareProfile = ""; |
| 59 | + } |
| 60 | + let disableAnimations = false; |
| 61 | + if (core.getInput('disableAnimations') == "true") { |
| 62 | + disableAnimations = true; |
| 63 | + } |
| 64 | + let bootTimeout = core.getInput('bootTimeout'); |
| 65 | + if (bootTimeout == null) { |
| 66 | + bootTimeout = '600'; |
| 67 | + } |
| 68 | + console.log(`Starting emulator with API=${api}, TAG=${tag} and ABI=${abi}...`); |
| 69 | + const androidHome = process.env.ANDROID_HOME; |
| 70 | + console.log(`ANDROID_HOME is ${androidHome}`); |
| 71 | + console.log(`PATH is ${process.env.PATH}`); |
| 72 | + let sdk = new sdk_1.SdkFactory().getAndroidSdk(); |
| 73 | + try { |
| 74 | + yield sdk.installEmulatorPackage(api, tag, abi, verbose); |
| 75 | + yield sdk.installPlatform(api, verbose); |
| 76 | + let supportsHardwareAcceleration = yield sdk.verifyHardwareAcceleration(); |
| 77 | + if (!supportsHardwareAcceleration && abi == "x86") { |
| 78 | + core.setFailed('Hardware acceleration is not supported'); |
| 79 | + return; |
| 80 | + } |
| 81 | + let emulator = yield sdk.createEmulator("emulator", api, tag, abi, hardwareProfile); |
| 82 | + console.log("starting adb server"); |
| 83 | + yield sdk.startAdbServer(); |
| 84 | + let booted = yield emulator.start(cmdOptions, +bootTimeout); |
| 85 | + if (!booted) { |
| 86 | + core.setFailed("emulator boot failed"); |
| 87 | + yield emulator.stop(); |
| 88 | + return; |
| 89 | + } |
| 90 | + //Pre-setup |
| 91 | + yield emulator.unlock(); |
| 92 | + if (disableAnimations) { |
| 93 | + yield emulator.disableAnimations(); |
| 94 | + } |
| 95 | + yield emulator.startLogcat(); |
| 96 | + console.log("emulator started and booted"); |
| 97 | + try { |
| 98 | + let result = yield exec_with_result_1.default(`${cmd}`); |
| 99 | + let code = result.exitCode; |
| 100 | + if (code != 0) { |
| 101 | + core.setFailed(`process exited with code ${code}`); |
| 102 | + } |
| 103 | + } |
| 104 | + catch (e) { |
| 105 | + core.setFailed(e.message); |
| 106 | + } |
| 107 | + console.log("stopping emulator"); |
| 108 | + yield emulator.stop(); |
| 109 | + yield emulator.stopLogcat(); |
| 110 | + console.log("emulator is stopped"); |
| 111 | + } |
| 112 | + catch (error) { |
| 113 | + console.error(error); |
| 114 | + core.setFailed(error.message); |
| 115 | + return; |
| 116 | + } |
| 117 | + } |
| 118 | + catch (error) { |
| 119 | + core.setFailed(error.message); |
| 120 | + return; |
| 121 | + } |
| 122 | + }); |
| 123 | +} |
| 124 | +run(); |
0 commit comments