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
|
|
|
|
2021-08-20 15:01:43 -04:00
|
|
|
import * as caches from './caches'
|
2020-06-13 07:44:30 -04:00
|
|
|
import * as execution from './execution'
|
|
|
|
import * as gradlew from './gradlew'
|
|
|
|
import * as provision from './provision'
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2020-02-14 00:46:51 -05:00
|
|
|
// Invoked by GitHub Actions
|
2020-06-13 07:54:27 -04:00
|
|
|
export async function run(): Promise<void> {
|
2021-08-20 15:01:43 -04:00
|
|
|
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
|
|
|
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
|
2021-08-22 22:14:47 -04:00
|
|
|
|
2021-08-20 15:01:43 -04:00
|
|
|
await caches.restore(buildRootDirectory)
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2021-08-20 15:01:43 -04:00
|
|
|
try {
|
2021-08-27 08:56:16 -04:00
|
|
|
const args: string[] = parseCommandLineArguments()
|
2021-09-07 17:13:16 -04:00
|
|
|
// TODO: instead of running with no-daemon, run `--stop` in post action.
|
2021-08-27 08:56:16 -04:00
|
|
|
args.push('--no-daemon')
|
|
|
|
|
2020-06-13 07:54:27 -04:00
|
|
|
const result = await execution.execute(
|
2021-06-24 13:45:43 -04:00
|
|
|
await resolveGradleExecutable(
|
|
|
|
workspaceDirectory,
|
|
|
|
buildRootDirectory
|
|
|
|
),
|
|
|
|
buildRootDirectory,
|
2021-08-27 08:56:16 -04:00
|
|
|
args
|
2020-06-13 07:44:30 -04:00
|
|
|
)
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2019-09-23 06:11:18 -04:00
|
|
|
if (result.buildScanUrl) {
|
2020-06-13 07:44:30 -04:00
|
|
|
core.setOutput('build-scan-url', result.buildScanUrl)
|
2021-09-05 21:15:31 -04:00
|
|
|
core.notice(`Gradle build scan: ${result.buildScanUrl}`)
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
2020-06-13 07:54:27 -04:00
|
|
|
if (result.status !== 0) {
|
2019-09-23 06:11:18 -04:00
|
|
|
core.setFailed(`Gradle process exited with status ${result.status}`)
|
|
|
|
}
|
2019-09-21 10:01:53 -04:00
|
|
|
} catch (error) {
|
2021-09-06 13:16:08 -04:00
|
|
|
if (!(error instanceof Error)) {
|
|
|
|
throw error
|
|
|
|
}
|
2020-06-13 07:44:30 -04:00
|
|
|
core.setFailed(error.message)
|
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-06-24 13:45:43 -04:00
|
|
|
async function resolveGradleExecutable(
|
|
|
|
workspaceDirectory: string,
|
|
|
|
buildRootDirectory: string
|
|
|
|
): Promise<string> {
|
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-09-07 16:38:41 -04:00
|
|
|
return gradlew.locateGradleWrapperScript(buildRootDirectory)
|
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-07-20 13:44:56 -04:00
|
|
|
buildRootDirectory === ''
|
2020-06-13 10:02:48 -04:00
|
|
|
? path.resolve(baseDirectory)
|
|
|
|
: path.resolve(baseDirectory, buildRootDirectory)
|
|
|
|
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
|
|
|
}
|