2019-09-21 10:01:53 -04:00
|
|
|
import * as core from "@actions/core";
|
|
|
|
import * as path from "path";
|
|
|
|
import {parseArgsStringToArgv} from "string-argv";
|
2019-09-20 17:06:59 -04:00
|
|
|
|
2019-09-21 10:01:53 -04:00
|
|
|
import * as execution from "./execution";
|
|
|
|
import * as gradlew from "./gradlew";
|
|
|
|
import * as provision from "./provision";
|
|
|
|
|
|
|
|
|
2020-02-14 00:46:51 -05:00
|
|
|
// Invoked by GitHub Actions
|
2019-09-23 06:11:18 -04:00
|
|
|
export async function run() {
|
2019-09-21 10:01:53 -04:00
|
|
|
try {
|
|
|
|
|
|
|
|
const baseDirectory = process.env[`GITHUB_WORKSPACE`] || "";
|
|
|
|
|
|
|
|
let result = await execution.execute(
|
|
|
|
await resolveGradleExecutable(baseDirectory),
|
|
|
|
resolveBuildRootDirectory(baseDirectory),
|
|
|
|
parseCommandLineArguments()
|
|
|
|
);
|
|
|
|
|
2019-09-23 06:11:18 -04:00
|
|
|
if (result.buildScanUrl) {
|
2019-09-21 10:01:53 -04:00
|
|
|
core.setOutput("build-scan-url", result.buildScanUrl);
|
|
|
|
}
|
|
|
|
|
2019-09-23 06:11:18 -04:00
|
|
|
if (result.status != 0) {
|
|
|
|
core.setFailed(`Gradle process exited with status ${result.status}`)
|
|
|
|
}
|
|
|
|
|
2019-09-21 10:01:53 -04:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
2019-09-20 17:06:59 -04:00
|
|
|
}
|
|
|
|
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2019-09-20 17:06:59 -04:00
|
|
|
run();
|
2019-09-21 10:01:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
async function resolveGradleExecutable(baseDirectory: string): Promise<string> {
|
|
|
|
|
|
|
|
const gradleVersion = inputOrNull("gradle-version");
|
2019-12-09 04:44:21 -05:00
|
|
|
if (gradleVersion != null && gradleVersion != "wrapper") {
|
2019-10-28 08:30:27 -04:00
|
|
|
return path.resolve(await provision.gradleVersion(gradleVersion))
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const gradleExecutable = inputOrNull("gradle-executable");
|
|
|
|
if (gradleExecutable != null) {
|
2019-10-28 08:26:37 -04:00
|
|
|
return path.resolve(baseDirectory, gradleExecutable)
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const wrapperDirectory = inputOrNull("wrapper-directory");
|
|
|
|
const executableDirectory = wrapperDirectory != null
|
|
|
|
? path.join(baseDirectory, wrapperDirectory)
|
|
|
|
: baseDirectory;
|
|
|
|
|
2019-10-28 08:26:37 -04:00
|
|
|
return path.resolve(executableDirectory, gradlew.wrapperFilename());
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function resolveBuildRootDirectory(baseDirectory: string): string {
|
|
|
|
let buildRootDirectory = inputOrNull("build-root-directory");
|
2019-10-28 08:26:37 -04:00
|
|
|
return buildRootDirectory == null
|
|
|
|
? path.resolve(baseDirectory)
|
|
|
|
: path.resolve(baseDirectory, buildRootDirectory);
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function parseCommandLineArguments(): string[] {
|
|
|
|
const input = inputOrNull("arguments");
|
|
|
|
return input == null ? [] : parseArgsStringToArgv(input)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function inputOrNull(name: string): string | null {
|
|
|
|
const inputString = core.getInput(name);
|
|
|
|
if (inputString.length == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return inputString
|
|
|
|
}
|