Skip to content

Commit 08bb824

Browse files
committed
chore(release): 0.1.2
1 parent 500ef13 commit 08bb824

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+4005
-0
lines changed

emulator-run-cmd/lib/emulator.js

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
Object.defineProperty(exports, "__esModule", { value: true });
12+
const exec_with_result_1 = require("./exec-with-result");
13+
class Emulator {
14+
constructor(sdk, name, api, abi, tag, adbPort, telnetPort) {
15+
this.sdk = sdk;
16+
this.name = name;
17+
this.api = api;
18+
this.abi = abi;
19+
this.tag = tag;
20+
this.adbPort = adbPort;
21+
this.telnetPort = telnetPort;
22+
}
23+
start(cmdOptions, bootTimeout) {
24+
return __awaiter(this, void 0, void 0, function* () {
25+
yield exec_with_result_1.execIgnoreFailure(`bash -c \\\"${this.sdk.emulatorCmd()} @${this.name} ${cmdOptions} &\"`);
26+
let booted = yield this.waitForBoot(bootTimeout);
27+
console.log(`booted=${booted}`);
28+
return booted;
29+
});
30+
}
31+
stop() {
32+
return __awaiter(this, void 0, void 0, function* () {
33+
yield exec_with_result_1.execIgnoreFailure(`bash -c \\\"${this.sdk.androidHome()}/platform-tools/adb -s emulator-${this.adbPort} emu kill\"`);
34+
console.log("emu kill finished");
35+
return;
36+
});
37+
}
38+
waitForBoot(timeout) {
39+
return __awaiter(this, void 0, void 0, function* () {
40+
for (let countdown = timeout; countdown > 0; countdown--) {
41+
if (countdown == 0) {
42+
console.error("Timeout waiting for the emulator");
43+
return false;
44+
}
45+
try {
46+
let output = yield this.execAdbCommand("shell getprop sys.boot_completed");
47+
if (output.trim() == '1') {
48+
countdown = 0;
49+
console.log("Emulator booted");
50+
return true;
51+
}
52+
}
53+
catch (e) {
54+
console.error(e.message);
55+
}
56+
console.log("Sleeping for 1s");
57+
yield sleep(1000);
58+
countdown--;
59+
}
60+
console.log("Timeout waiting for emulator to boot. Exiting");
61+
return false;
62+
});
63+
}
64+
unlock() {
65+
return __awaiter(this, void 0, void 0, function* () {
66+
yield this.execAdbCommand("shell input keyevent 82");
67+
});
68+
}
69+
disableAnimations() {
70+
return __awaiter(this, void 0, void 0, function* () {
71+
console.log('Disabling animations');
72+
try {
73+
yield this.execAdbCommand("shell settings put global window_animation_scale 0.0");
74+
yield this.execAdbCommand("shell settings put global transition_animation_scale 0.0");
75+
yield this.execAdbCommand("shell settings put global animator_duration_scale 0.0");
76+
}
77+
catch (e) {
78+
console.warn("error disabling animations. skipping");
79+
}
80+
});
81+
}
82+
execAdbCommand(args) {
83+
return __awaiter(this, void 0, void 0, function* () {
84+
return yield exec_with_result_1.execIgnoreFailure(`${this.sdk.androidHome()}/platform-tools/adb -s emulator-${this.adbPort} ${args}`);
85+
});
86+
}
87+
startLogcat() {
88+
return __awaiter(this, void 0, void 0, function* () {
89+
console.log('Starting logcat read process');
90+
try {
91+
yield exec_with_result_1.execIgnoreFailure(`mkdir -p artifacts`);
92+
yield exec_with_result_1.execIgnoreFailure(`bash -c \\\"${this.sdk.androidHome()}/platform-tools/adb -s emulator-${this.adbPort} logcat -dv time > artifacts/logcat.log &\"`);
93+
}
94+
catch (e) {
95+
console.warn("can't start logcat read process. skipping");
96+
}
97+
});
98+
}
99+
stopLogcat() {
100+
return __awaiter(this, void 0, void 0, function* () {
101+
console.log('Stopping logcat read process');
102+
try {
103+
yield exec_with_result_1.execIgnoreFailure(`kill $(jobs -p)`);
104+
}
105+
catch (e) {
106+
console.warn("can't stop logcat read process. skipping");
107+
}
108+
});
109+
}
110+
}
111+
exports.Emulator = Emulator;
112+
function sleep(ms) {
113+
return new Promise(resolve => setTimeout(resolve, ms));
114+
}
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
Object.defineProperty(exports, "__esModule", { value: true });
12+
const exec_1 = require("@actions/exec");
13+
function execWithResult(commandLine, args, options) {
14+
return __awaiter(this, void 0, void 0, function* () {
15+
let result = new Result();
16+
let exitCode = yield exec_1.exec(commandLine, args, Object.assign(Object.assign({}, options), { listeners: {
17+
stdout: (data) => {
18+
result.stdout += data.toString();
19+
},
20+
stderr: (data) => {
21+
result.stderr += data.toString();
22+
}
23+
} }));
24+
result.stdout = result.stdout.trim();
25+
result.stderr = result.stderr.trim();
26+
result.exitCode = exitCode;
27+
return result;
28+
});
29+
}
30+
exports.default = execWithResult;
31+
function execIgnoreFailure(commandLine, args, options) {
32+
return __awaiter(this, void 0, void 0, function* () {
33+
let result = yield execWithResult(commandLine, args, options);
34+
return result.stdout;
35+
});
36+
}
37+
exports.execIgnoreFailure = execIgnoreFailure;
38+
class Result {
39+
constructor() {
40+
this.exitCode = 0;
41+
this.stdout = '';
42+
this.stderr = '';
43+
}
44+
}
45+
exports.Result = Result;

emulator-run-cmd/lib/main.js

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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

Comments
 (0)