From 2c5dfd924077123447286a53a7e8689264044fe6 Mon Sep 17 00:00:00 2001 From: Yang Chen Date: Sun, 15 Dec 2019 17:05:45 +1100 Subject: [PATCH 1/3] Update checkout action to v2. --- .github/workflows/workflow.yml | 4 +--- README.md | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 914fdd39e..d9899ba0a 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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: | diff --git a/README.md b/README.md index 0b78c408c..17c75b778 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 From e756009f0de1bac9a9ce58d2ce1e8d5f5e72d1cb Mon Sep 17 00:00:00 2001 From: Yang Chen Date: Mon, 20 Jan 2020 00:46:38 +1100 Subject: [PATCH 2/3] Force use Java 8 for sdkmanager and avdmanager. --- .github/workflows/workflow.yml | 5 +++ lib/java-version-manager.js | 60 ++++++++++++++++++++++++++++++++++ lib/main.js | 6 ++++ src/java-version-manager.ts | 39 ++++++++++++++++++++++ src/main.ts | 8 +++++ 5 files changed, 118 insertions(+) create mode 100644 lib/java-version-manager.js create mode 100644 src/java-version-manager.ts diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index d9899ba0a..46df2ea05 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -28,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: diff --git a/lib/java-version-manager.js b/lib/java-version-manager.js new file mode 100644 index 000000000..d7c6fdc73 --- /dev/null +++ b/lib/java-version-manager.js @@ -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; diff --git a/lib/main.js b/lib/main.js index 91e9aea5e..9041946ee 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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 { @@ -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 { @@ -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) { diff --git a/src/java-version-manager.ts b/src/java-version-manager.ts new file mode 100644 index 000000000..0998428cf --- /dev/null +++ b/src/java-version-manager.ts @@ -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 { + 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 { + 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); +} diff --git a/src/main.ts b/src/main.ts index 09dc7776a..968925125 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 { @@ -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); @@ -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) { From 1162b6cd2f6febd56985e1ce323d4409a50db123 Mon Sep 17 00:00:00 2001 From: Yang Chen Date: Mon, 20 Jan 2020 03:56:38 +1100 Subject: [PATCH 3/3] Prepare for release 2.3.0. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7db6d0c62..a06822881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.