mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-06 16:26:12 +02:00
Initial impl
This commit is contained in:
parent
f4a8f7a81b
commit
bc921df1ec
11 changed files with 1296 additions and 1055 deletions
76
src/main.ts
76
src/main.ts
|
@ -1,12 +1,74 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as core from "@actions/core";
|
||||
import * as path from "path";
|
||||
import {parseArgsStringToArgv} from "string-argv";
|
||||
|
||||
import * as execution from "./execution";
|
||||
import * as gradlew from "./gradlew";
|
||||
import * as provision from "./provision";
|
||||
|
||||
|
||||
// Invoked by Github Actions
|
||||
async function run() {
|
||||
try {
|
||||
const myInput = core.getInput('myInput');
|
||||
core.debug(`Hello ${myInput}`);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
try {
|
||||
|
||||
const baseDirectory = process.env[`GITHUB_WORKSPACE`] || "";
|
||||
|
||||
let result = await execution.execute(
|
||||
await resolveGradleExecutable(baseDirectory),
|
||||
resolveBuildRootDirectory(baseDirectory),
|
||||
parseCommandLineArguments()
|
||||
);
|
||||
|
||||
if (result.buildScanUrl != null) {
|
||||
core.setOutput("build-scan-url", result.buildScanUrl);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
run();
|
||||
|
||||
|
||||
async function resolveGradleExecutable(baseDirectory: string): Promise<string> {
|
||||
|
||||
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: string): string {
|
||||
let buildRootDirectory = inputOrNull("build-root-directory");
|
||||
return buildRootDirectory == null ? baseDirectory : path.join(baseDirectory, buildRootDirectory);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue