gradle-build-action/lib/main.js

73 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2019-09-21 10:11:55 -04:00
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(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 path = __importStar(require("path"));
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) {
core.setOutput("build-scan-url", result.buildScanUrl);
}
}
catch (error) {
core.setFailed(error.message);
}
});
}
run();
function resolveGradleExecutable(baseDirectory) {
return __awaiter(this, void 0, void 0, function* () {
const gradleVersion = inputOrNull("gradle-version");
if (gradleVersion != null) {
return provision.gradleVersion(gradleVersion);
}
const gradleExecutable = inputOrNull("gradle-executable");
if (gradleExecutable != null) {
return path.join(baseDirectory, gradleExecutable);
}
const wrapperDirectory = inputOrNull("wrapper-directory");
const executableDirectory = wrapperDirectory != null
? path.join(baseDirectory, wrapperDirectory)
: baseDirectory;
return path.join(executableDirectory, gradlew.wrapperFilename());
});
}
function resolveBuildRootDirectory(baseDirectory) {
let buildRootDirectory = inputOrNull("build-root-directory");
return buildRootDirectory == null ? baseDirectory : path.join(baseDirectory, buildRootDirectory);
}
function parseCommandLineArguments() {
const input = inputOrNull("arguments");
return input == null ? [] : string_argv_1.parseArgsStringToArgv(input);
}
function inputOrNull(name) {
const inputString = core.getInput(name);
if (inputString.length == 0) {
return null;
}
return inputString;
}