Skip to content

Commit 06c14b8

Browse files
committed
chore(release): 0.0.8
1 parent ca4e6b0 commit 06c14b8

62 files changed

Lines changed: 3995 additions & 0 deletions

Some content is hidden

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

emulator-run-cmd/lib/emulator.js

Lines changed: 114 additions & 0 deletions
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) {
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();
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() {
39+
return __awaiter(this, void 0, void 0, function* () {
40+
for (let countdown = 300; 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 -v long > 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+
}
Lines changed: 45 additions & 0 deletions
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

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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 = 'google_apis';
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+
console.log(`Starting emulator with API=${api}, TAG=${tag} and ABI=${abi}...`);
65+
const androidHome = process.env.ANDROID_HOME;
66+
console.log(`ANDROID_HOME is ${androidHome}`);
67+
console.log(`PATH is ${process.env.PATH}`);
68+
let sdk = new sdk_1.SdkFactory().getAndroidSdk();
69+
try {
70+
yield sdk.installEmulatorPackage(api, tag, abi, verbose);
71+
yield sdk.installPlatform(api, verbose);
72+
let supportsHardwareAcceleration = yield sdk.verifyHardwareAcceleration();
73+
if (!supportsHardwareAcceleration && abi == "x86") {
74+
core.setFailed('Hardware acceleration is not supported');
75+
return;
76+
}
77+
let emulator = yield sdk.createEmulator("emulator", api, tag, abi, hardwareProfile);
78+
console.log("starting adb server");
79+
yield sdk.startAdbServer();
80+
let booted = yield emulator.start(cmdOptions);
81+
if (!booted) {
82+
core.setFailed("emulator boot failed");
83+
yield emulator.stop();
84+
return;
85+
}
86+
//Pre-setup
87+
yield emulator.unlock();
88+
if (disableAnimations) {
89+
yield emulator.disableAnimations();
90+
}
91+
yield emulator.startLogcat();
92+
console.log("emulator started and booted");
93+
try {
94+
let result = yield exec_with_result_1.default(`${cmd}`);
95+
let code = result.exitCode;
96+
if (code != 0) {
97+
core.setFailed(`process exited with code ${code}`);
98+
}
99+
}
100+
catch (e) {
101+
core.setFailed(e.message);
102+
}
103+
console.log("stopping emulator");
104+
yield emulator.stop();
105+
yield emulator.stopLogcat();
106+
console.log("emulator is stopped");
107+
}
108+
catch (error) {
109+
console.error(error);
110+
core.setFailed(error.message);
111+
return;
112+
}
113+
}
114+
catch (error) {
115+
core.setFailed(error.message);
116+
return;
117+
}
118+
});
119+
}
120+
run();

0 commit comments

Comments
 (0)