2020-06-13 13:44:30 +02:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import * as path from 'path'
|
|
|
|
import {parseArgsStringToArgv} from 'string-argv'
|
2019-09-21 16:01:53 +02:00
|
|
|
|
2021-08-20 13:01:43 -06:00
|
|
|
import * as caches from './caches'
|
2020-06-13 13:44:30 +02:00
|
|
|
import * as execution from './execution'
|
|
|
|
import * as gradlew from './gradlew'
|
|
|
|
import * as provision from './provision'
|
2019-09-21 16:01:53 +02:00
|
|
|
|
2021-11-28 10:19:56 -07:00
|
|
|
/**
|
|
|
|
* The main entry point for the action, called by Github Actions for the step.
|
|
|
|
*/
|
2020-06-13 13:54:27 +02:00
|
|
|
export async function run(): Promise<void> {
|
2021-09-14 05:33:50 -06:00
|
|
|
try {
|
|
|
|
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
|
|
|
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
|
2021-08-22 20:14:47 -06:00
|
|
|
|
2021-09-14 05:33:50 -06:00
|
|
|
await caches.restore(buildRootDirectory)
|
2019-09-21 16:01:53 +02:00
|
|
|
|
2021-08-27 06:56:16 -06:00
|
|
|
const args: string[] = parseCommandLineArguments()
|
|
|
|
|
2020-06-13 13:54:27 +02:00
|
|
|
const result = await execution.execute(
|
2021-10-29 07:34:44 -06:00
|
|
|
await resolveGradleExecutable(workspaceDirectory, buildRootDirectory),
|
2021-06-24 10:45:43 -07:00
|
|
|
buildRootDirectory,
|
2021-08-27 06:56:16 -06:00
|
|
|
args
|
2020-06-13 13:44:30 +02:00
|
|
|
)
|
2019-09-21 16:01:53 +02:00
|
|
|
|
2020-06-13 13:54:27 +02:00
|
|
|
if (result.status !== 0) {
|
2021-10-21 12:02:52 -06:00
|
|
|
if (result.buildScanUrl) {
|
|
|
|
core.setFailed(`Gradle build failed: ${result.buildScanUrl}`)
|
|
|
|
} else {
|
2021-10-29 07:34:44 -06:00
|
|
|
core.setFailed(`Gradle build failed: process exited with status ${result.status}`)
|
2021-10-21 12:02:52 -06:00
|
|
|
}
|
2019-09-23 12:11:18 +02:00
|
|
|
}
|
2019-09-21 16:01:53 +02:00
|
|
|
} catch (error) {
|
2021-09-14 05:33:50 -06:00
|
|
|
core.setFailed(String(error))
|
|
|
|
if (error instanceof Error && error.stack) {
|
|
|
|
core.info(error.stack)
|
2021-09-06 11:16:08 -06:00
|
|
|
}
|
2019-09-21 16:01:53 +02:00
|
|
|
}
|
2019-09-20 23:06:59 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 13:44:30 +02:00
|
|
|
run()
|
2019-09-21 16:01:53 +02:00
|
|
|
|
2021-10-29 07:34:44 -06:00
|
|
|
async function resolveGradleExecutable(workspaceDirectory: string, buildRootDirectory: string): Promise<string> {
|
2021-07-20 11:44:56 -06:00
|
|
|
const gradleVersion = core.getInput('gradle-version')
|
|
|
|
if (gradleVersion !== '' && gradleVersion !== 'wrapper') {
|
2019-10-28 13:30:27 +01:00
|
|
|
return path.resolve(await provision.gradleVersion(gradleVersion))
|
2019-09-21 16:01:53 +02:00
|
|
|
}
|
|
|
|
|
2021-07-20 11:44:56 -06:00
|
|
|
const gradleExecutable = core.getInput('gradle-executable')
|
|
|
|
if (gradleExecutable !== '') {
|
2021-06-24 10:45:43 -07:00
|
|
|
return path.resolve(workspaceDirectory, gradleExecutable)
|
2019-09-21 16:01:53 +02:00
|
|
|
}
|
|
|
|
|
2021-09-07 14:38:41 -06:00
|
|
|
return gradlew.locateGradleWrapperScript(buildRootDirectory)
|
2019-09-21 16:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resolveBuildRootDirectory(baseDirectory: string): string {
|
2021-07-20 11:44:56 -06:00
|
|
|
const buildRootDirectory = core.getInput('build-root-directory')
|
2020-06-13 16:02:48 +02:00
|
|
|
const resolvedBuildRootDirectory =
|
2021-10-29 07:34:44 -06:00
|
|
|
buildRootDirectory === '' ? path.resolve(baseDirectory) : path.resolve(baseDirectory, buildRootDirectory)
|
2020-06-13 16:02:48 +02:00
|
|
|
return resolvedBuildRootDirectory
|
2019-09-21 16:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseCommandLineArguments(): string[] {
|
2021-07-20 11:44:56 -06:00
|
|
|
const input = core.getInput('arguments')
|
|
|
|
return parseArgsStringToArgv(input)
|
2019-09-21 16:01:53 +02:00
|
|
|
}
|