Skip to content

Commit b704469

Browse files
committed
chore(release): 0.1.3
1 parent 7709345 commit b704469

File tree

154 files changed

+12837
-0
lines changed

Some content is hidden

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

154 files changed

+12837
-0
lines changed

emulator-run-cmd/lib/emulator.js

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

emulator-run-cmd/lib/main.js

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

0 commit comments

Comments
 (0)