Skip to content

Commit

Permalink
Merge branch 'master' into release/v2
Browse files Browse the repository at this point in the history
* master:
  Prepare for release 2.3.0.
  Force use Java 8 for sdkmanager and avdmanager.
  Update checkout action to v2.
  • Loading branch information
ychescale9 committed Jan 19, 2020
2 parents 3f52989 + 1162b6c commit d27f7ec
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 9 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ jobs:
api-level: [21, 23, 29]
steps:
- name: checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
uses: actions/checkout@v2

- name: build, test and lint
run: |
Expand All @@ -30,6 +28,11 @@ jobs:
- name: Prepare test fixture
run: cp -a ./test-fixture/* ./

- name: Java 13
uses: actions/setup-java@v1
with:
java-version: 13

- name: run action
uses: ./
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## v2.3.0

* Added support for running the action with Java 9+ by forcing SDK manager and AVD manager to use Java 8.

## v2.2.0

* Fixed an issue where emulator is killed prematurely.
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ jobs:
runs-on: macOS-latest
steps:
- name: checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
uses: actions/checkout@v2
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
Expand All @@ -55,9 +53,7 @@ jobs:
target: [default, google_apis]
steps:
- name: checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
uses: actions/checkout@v2
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
Expand Down
60 changes: 60 additions & 0 deletions lib/java-version-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
/**
* Returns the current $JAVA_HOME path.
*/
function getCurrentJavaHome() {
return __awaiter(this, void 0, void 0, function* () {
let defaultJavaHome = '';
yield exec.exec(`sh -c \\"echo $JAVA_HOME"`, [], {
listeners: {
stdout: (data) => {
defaultJavaHome += data.toString();
}
}
});
return defaultJavaHome.trim();
});
}
exports.getCurrentJavaHome = getCurrentJavaHome;
/**
* Returns the Java 8 $JAVA_HOME path.
*/
function getJavaHomeV8() {
return __awaiter(this, void 0, void 0, function* () {
let javaHomeV8 = '';
yield exec.exec(`/usr/libexec/java_home -v 1.8`, [], {
listeners: {
stdout: (data) => {
javaHomeV8 += data.toString();
}
}
});
return javaHomeV8.trim();
});
}
exports.getJavaHomeV8 = getJavaHomeV8;
/**
* Sets $JAVA_HOME to the specified path.
*/
function setJavaHome(path) {
core.exportVariable('JAVA_HOME', path);
}
exports.setJavaHome = setJavaHome;
6 changes: 6 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const input_validator_1 = require("./input-validator");
const emulator_manager_1 = require("./emulator-manager");
const exec = __importStar(require("@actions/exec"));
const script_parser_1 = require("./script-parser");
const java_version_manager_1 = require("./java-version-manager");
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -66,6 +67,9 @@ function run() {
scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
console.log(`${script}`);
}));
// use Java 8 for sdkmanager and avdmanager
const defaultJavaHome = yield java_version_manager_1.getCurrentJavaHome();
java_version_manager_1.setJavaHome(yield java_version_manager_1.getJavaHomeV8());
// install SDK
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild);
try {
Expand All @@ -75,6 +79,8 @@ function run() {
catch (error) {
core.setFailed(error.message);
}
// use default JAVA_HOME for running custom script
java_version_manager_1.setJavaHome(defaultJavaHome);
// execute the custom script
try {
for (const script of scripts) {
Expand Down
39 changes: 39 additions & 0 deletions src/java-version-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';

/**
* Returns the current $JAVA_HOME path.
*/
export async function getCurrentJavaHome(): Promise<string> {
let defaultJavaHome = '';
await exec.exec(`sh -c \\"echo $JAVA_HOME"`, [], {
listeners: {
stdout: (data: Buffer) => {
defaultJavaHome += data.toString();
}
}
});
return defaultJavaHome.trim();
}

/**
* Returns the Java 8 $JAVA_HOME path.
*/
export async function getJavaHomeV8(): Promise<string> {
let javaHomeV8 = '';
await exec.exec(`/usr/libexec/java_home -v 1.8`, [], {
listeners: {
stdout: (data: Buffer) => {
javaHomeV8 += data.toString();
}
}
});
return javaHomeV8.trim();
}

/**
* Sets $JAVA_HOME to the specified path.
*/
export function setJavaHome(path: string) {
core.exportVariable('JAVA_HOME', path);
}
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmu
import { launchEmulator, killEmulator } from './emulator-manager';
import * as exec from '@actions/exec';
import { parseScript } from './script-parser';
import { getCurrentJavaHome, getJavaHomeV8, setJavaHome } from './java-version-manager';

async function run() {
try {
Expand Down Expand Up @@ -58,6 +59,10 @@ async function run() {
console.log(`${script}`);
});

// use Java 8 for sdkmanager and avdmanager
const defaultJavaHome = await getCurrentJavaHome();
setJavaHome(await getJavaHomeV8());

// install SDK
await installAndroidSdk(apiLevel, target, arch, emulatorBuild);

Expand All @@ -68,6 +73,9 @@ async function run() {
core.setFailed(error.message);
}

// use default JAVA_HOME for running custom script
setJavaHome(defaultJavaHome);

// execute the custom script
try {
for (const script of scripts) {
Expand Down

0 comments on commit d27f7ec

Please sign in to comment.