diff --git a/lib/execution.js b/lib/execution.js index d67bb2f..b379297 100644 --- a/lib/execution.js +++ b/lib/execution.js @@ -20,9 +20,10 @@ const exec = __importStar(require("@actions/exec")); function execute(executable, root, argv) { return __awaiter(this, void 0, void 0, function* () { let publishing = false; - let buildScanLink = null; - yield exec.exec(executable, argv, { + let buildScanUrl; + const status = yield exec.exec(executable, argv, { cwd: root, + ignoreReturnCode: true, listeners: { stdline: (line) => { if (line.startsWith("Publishing build scan...")) { @@ -32,21 +33,19 @@ function execute(executable, root, argv) { publishing = false; } if (publishing && line.startsWith("http")) { - buildScanLink = line.trim(); + buildScanUrl = line.trim(); publishing = false; } } } }); - if (buildScanLink != null) { - return new BuildResultImpl(buildScanLink.toString()); - } - return new BuildResultImpl(null); + return new BuildResultImpl(status, buildScanUrl); }); } exports.execute = execute; class BuildResultImpl { - constructor(buildScanUrl) { + constructor(status, buildScanUrl) { + this.status = status; this.buildScanUrl = buildScanUrl; } } diff --git a/lib/gradlew.js b/lib/gradlew.js index db4695a..88d27cd 100644 --- a/lib/gradlew.js +++ b/lib/gradlew.js @@ -1,12 +1,11 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +const IS_WINDOWS = process.platform === "win32"; function wrapperFilename() { - const isWindows = process.platform === "win32"; - return isWindows ? "gradlew.bat" : "gradlew"; + return IS_WINDOWS ? "gradlew.bat" : "gradlew"; } exports.wrapperFilename = wrapperFilename; function installScriptFilename() { - const isWindows = process.platform === "win32"; - return isWindows ? "gradle.bat" : "gradle"; + return IS_WINDOWS ? "gradle.bat" : "gradle"; } exports.installScriptFilename = installScriptFilename; diff --git a/lib/main.js b/lib/main.js index 6573d32..0907e11 100644 --- a/lib/main.js +++ b/lib/main.js @@ -22,21 +22,24 @@ const string_argv_1 = require("string-argv"); const execution = __importStar(require("./execution")); const gradlew = __importStar(require("./gradlew")); const provision = __importStar(require("./provision")); -// Invoked by Github Actions function run() { return __awaiter(this, void 0, void 0, function* () { try { const baseDirectory = process.env[`GITHUB_WORKSPACE`] || ""; let result = yield execution.execute(yield resolveGradleExecutable(baseDirectory), resolveBuildRootDirectory(baseDirectory), parseCommandLineArguments()); - if (result.buildScanUrl != null) { + if (result.buildScanUrl) { core.setOutput("build-scan-url", result.buildScanUrl); } + if (result.status != 0) { + core.setFailed(`Gradle process exited with status ${result.status}`); + } } catch (error) { core.setFailed(error.message); } }); } +exports.run = run; run(); function resolveGradleExecutable(baseDirectory) { return __awaiter(this, void 0, void 0, function* () { diff --git a/lib/provision.js b/lib/provision.js index 14df4e9..160f56d 100644 --- a/lib/provision.js +++ b/lib/provision.js @@ -24,9 +24,8 @@ const core = __importStar(require("@actions/core")); const io = __importStar(require("@actions/io")); const toolCache = __importStar(require("@actions/tool-cache")); const gradlew = __importStar(require("./gradlew")); -/** - * @return Gradle executable - */ +const httpc = new httpm.HttpClient("eskatos/gradle-command-action"); +const gradleVersionsBaseUrl = "https://services.gradle.org/versions"; function gradleVersion(gradleVersion) { return __awaiter(this, void 0, void 0, function* () { switch (gradleVersion) { @@ -44,7 +43,6 @@ function gradleVersion(gradleVersion) { }); } exports.gradleVersion = gradleVersion; -const gradleVersionsBaseUrl = "https://services.gradle.org/versions"; function gradleCurrent() { return __awaiter(this, void 0, void 0, function* () { const json = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`); @@ -54,7 +52,7 @@ function gradleCurrent() { function gradleReleaseCandidate() { return __awaiter(this, void 0, void 0, function* () { const json = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`); - if (json != null) { + if (json) { return provisionGradle(json.version, json.downloadUrl); } return gradleCurrent(); @@ -75,7 +73,7 @@ function gradleReleaseNightly() { function gradle(version) { return __awaiter(this, void 0, void 0, function* () { const declaration = yield findGradleVersionDeclaration(version); - if (declaration == null) { + if (!declaration) { throw new Error(`Gradle version ${version} does not exists`); } return provisionGradle(declaration.version, declaration.downloadUrl); @@ -83,31 +81,23 @@ function gradle(version) { } function gradleVersionDeclaration(url) { return __awaiter(this, void 0, void 0, function* () { - const httpc = new httpm.HttpClient("gradle-github-action"); - const response = yield httpc.get(url); - const body = yield response.readBody(); - const json = JSON.parse(body); - return (json == null || json.version == null || json.version.length <= 0) - ? null - : json; + const json = yield httpGetJson(url); + return (json.version && json.version.length > 0) ? json : undefined; }); } function findGradleVersionDeclaration(version) { return __awaiter(this, void 0, void 0, function* () { - const httpc = new httpm.HttpClient("gradle-github-action"); - const response = yield httpc.get(`${gradleVersionsBaseUrl}/all`); - const body = yield response.readBody(); - const json = JSON.parse(body); - const found = json.find(entry => { - return entry.version == version; + const json = yield httpGetJson(`${gradleVersionsBaseUrl}/all`); + const found = json.find((entry) => { + return entry.version === version; }); - return found != undefined ? found : null; + return found ? found : undefined; }); } function provisionGradle(version, url) { return __awaiter(this, void 0, void 0, function* () { const cachedInstall = toolCache.find("gradle", version); - if (cachedInstall != null && cachedInstall.length > 0) { + if (cachedInstall.length > 0) { const cachedExecutable = executableFrom(cachedInstall); core.info(`Provisioned Gradle executable ${cachedExecutable}`); return cachedExecutable; @@ -135,10 +125,16 @@ function provisionGradle(version, url) { function executableFrom(installDir) { return path.join(installDir, "bin", `${gradlew.installScriptFilename()}`); } +function httpGetJson(url) { + return __awaiter(this, void 0, void 0, function* () { + const response = yield httpc.get(url); + const body = yield response.readBody(); + return JSON.parse(body); + }); +} function httpDownload(url, path) { return __awaiter(this, void 0, void 0, function* () { return new Promise(function (resolve, reject) { - const httpc = new httpm.HttpClient("gradle-github-action"); const writeStream = fs.createWriteStream(path); httpc.get(url).then(response => { response.message.pipe(writeStream)