2020-06-13 07:44:30 -04:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import * as path from 'path'
|
|
|
|
import {parseArgsStringToArgv} from 'string-argv'
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2022-06-02 14:17:56 -04:00
|
|
|
import * as setupGradle from './setup-gradle'
|
2020-06-13 07:44:30 -04:00
|
|
|
import * as execution from './execution'
|
|
|
|
import * as provision from './provision'
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2021-11-28 12:19:56 -05:00
|
|
|
/**
|
|
|
|
* The main entry point for the action, called by Github Actions for the step.
|
|
|
|
*/
|
2020-06-13 07:54:27 -04:00
|
|
|
export async function run(): Promise<void> {
|
2021-09-14 07:33:50 -04:00
|
|
|
try {
|
|
|
|
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
|
|
|
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
|
2021-08-22 22:14:47 -04:00
|
|
|
|
2022-06-02 14:17:56 -04:00
|
|
|
await setupGradle.setup(buildRootDirectory)
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2021-12-08 11:05:04 -05:00
|
|
|
const executable = await provisionGradle(workspaceDirectory)
|
|
|
|
// executable will be undefined if using Gradle wrapper
|
|
|
|
if (executable !== undefined) {
|
|
|
|
core.addPath(path.dirname(executable))
|
|
|
|
}
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2021-12-08 11:05:04 -05:00
|
|
|
// Only execute if arguments have been provided
|
|
|
|
const args: string[] = parseCommandLineArguments()
|
|
|
|
if (args.length > 0) {
|
|
|
|
await execution.executeGradleBuild(executable, buildRootDirectory, args)
|
2019-09-23 06:11:18 -04:00
|
|
|
}
|
2019-09-21 10:01:53 -04:00
|
|
|
} catch (error) {
|
2021-09-14 07:33:50 -04:00
|
|
|
core.setFailed(String(error))
|
|
|
|
if (error instanceof Error && error.stack) {
|
|
|
|
core.info(error.stack)
|
2021-09-06 13:16:08 -04:00
|
|
|
}
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
2019-09-20 17:06:59 -04:00
|
|
|
}
|
|
|
|
|
2020-06-13 07:44:30 -04:00
|
|
|
run()
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2021-12-08 11:05:04 -05:00
|
|
|
async function provisionGradle(workspaceDirectory: string): Promise<string | undefined> {
|
2021-07-20 13:44:56 -04:00
|
|
|
const gradleVersion = core.getInput('gradle-version')
|
|
|
|
if (gradleVersion !== '' && 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
|
|
|
}
|
|
|
|
|
2021-07-20 13:44:56 -04:00
|
|
|
const gradleExecutable = core.getInput('gradle-executable')
|
|
|
|
if (gradleExecutable !== '') {
|
2021-06-24 13:45:43 -04:00
|
|
|
return path.resolve(workspaceDirectory, gradleExecutable)
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:05:04 -05:00
|
|
|
return undefined
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function resolveBuildRootDirectory(baseDirectory: string): string {
|
2021-07-20 13:44:56 -04:00
|
|
|
const buildRootDirectory = core.getInput('build-root-directory')
|
2020-06-13 10:02:48 -04:00
|
|
|
const resolvedBuildRootDirectory =
|
2021-10-29 09:34:44 -04:00
|
|
|
buildRootDirectory === '' ? path.resolve(baseDirectory) : path.resolve(baseDirectory, buildRootDirectory)
|
2020-06-13 10:02:48 -04:00
|
|
|
return resolvedBuildRootDirectory
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseCommandLineArguments(): string[] {
|
2021-07-20 13:44:56 -04:00
|
|
|
const input = core.getInput('arguments')
|
|
|
|
return parseArgsStringToArgv(input)
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|