2020-06-13 11:44:30 +00:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import * as path from 'path'
|
|
|
|
import {parseArgsStringToArgv} from 'string-argv'
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2020-06-14 17:05:03 +00:00
|
|
|
import * as github from './github-utils'
|
2020-06-14 16:46:49 +00:00
|
|
|
import * as cacheWrapper from './cache-wrapper'
|
2020-06-13 11:44:30 +00:00
|
|
|
import * as execution from './execution'
|
|
|
|
import * as gradlew from './gradlew'
|
|
|
|
import * as provision from './provision'
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2020-02-14 05:46:51 +00:00
|
|
|
// Invoked by GitHub Actions
|
2020-06-13 11:54:27 +00:00
|
|
|
export async function run(): Promise<void> {
|
2019-09-21 14:01:53 +00:00
|
|
|
try {
|
2021-06-24 17:45:43 +00:00
|
|
|
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
|
|
|
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2020-06-13 11:54:27 +00:00
|
|
|
const result = await execution.execute(
|
2021-06-24 17:45:43 +00:00
|
|
|
await resolveGradleExecutable(
|
|
|
|
workspaceDirectory,
|
|
|
|
buildRootDirectory
|
|
|
|
),
|
|
|
|
buildRootDirectory,
|
2019-09-21 14:01:53 +00:00
|
|
|
parseCommandLineArguments()
|
2020-06-13 11:44:30 +00:00
|
|
|
)
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2019-09-23 10:11:18 +00:00
|
|
|
if (result.buildScanUrl) {
|
2020-06-13 11:44:30 +00:00
|
|
|
core.setOutput('build-scan-url', result.buildScanUrl)
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 11:54:27 +00:00
|
|
|
if (result.status !== 0) {
|
2019-09-23 10:11:18 +00:00
|
|
|
core.setFailed(`Gradle process exited with status ${result.status}`)
|
|
|
|
}
|
2019-09-21 14:01:53 +00:00
|
|
|
} catch (error) {
|
2020-06-13 11:44:30 +00:00
|
|
|
core.setFailed(error.message)
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
2019-09-20 21:06:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 11:44:30 +00:00
|
|
|
run()
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2021-06-24 17:45:43 +00:00
|
|
|
async function resolveGradleExecutable(
|
|
|
|
workspaceDirectory: string,
|
|
|
|
buildRootDirectory: string
|
|
|
|
): Promise<string> {
|
2020-06-14 17:05:03 +00:00
|
|
|
const gradleVersion = github.inputOrNull('gradle-version')
|
2020-06-13 11:54:27 +00:00
|
|
|
if (gradleVersion !== null && gradleVersion !== 'wrapper') {
|
2019-10-28 12:30:27 +00:00
|
|
|
return path.resolve(await provision.gradleVersion(gradleVersion))
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 17:05:03 +00:00
|
|
|
const gradleExecutable = github.inputOrNull('gradle-executable')
|
2020-06-13 11:54:27 +00:00
|
|
|
if (gradleExecutable !== null) {
|
2020-06-13 16:47:57 +00:00
|
|
|
if (gradleExecutable.endsWith(gradlew.wrapperFilename())) {
|
2020-06-14 16:46:49 +00:00
|
|
|
await cacheWrapper.restoreCachedWrapperDist(
|
2020-06-13 16:47:57 +00:00
|
|
|
path.resolve(gradleExecutable, '..')
|
|
|
|
)
|
|
|
|
}
|
2021-06-24 17:45:43 +00:00
|
|
|
return path.resolve(workspaceDirectory, gradleExecutable)
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 17:05:03 +00:00
|
|
|
const wrapperDirectory = github.inputOrNull('wrapper-directory')
|
2020-06-13 16:47:57 +00:00
|
|
|
const gradlewDirectory =
|
2020-06-13 11:54:27 +00:00
|
|
|
wrapperDirectory !== null
|
2021-06-24 17:45:43 +00:00
|
|
|
? path.resolve(workspaceDirectory, wrapperDirectory)
|
|
|
|
: buildRootDirectory
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2021-06-24 19:13:54 +00:00
|
|
|
gradlew.validateGradleWrapper(gradlewDirectory)
|
2020-06-14 16:46:49 +00:00
|
|
|
await cacheWrapper.restoreCachedWrapperDist(gradlewDirectory)
|
2020-06-13 12:48:54 +00:00
|
|
|
|
2020-06-13 16:47:57 +00:00
|
|
|
return path.resolve(gradlewDirectory, gradlew.wrapperFilename())
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function resolveBuildRootDirectory(baseDirectory: string): string {
|
2020-06-14 17:05:03 +00:00
|
|
|
const buildRootDirectory = github.inputOrNull('build-root-directory')
|
2020-06-13 14:02:48 +00:00
|
|
|
const resolvedBuildRootDirectory =
|
|
|
|
buildRootDirectory === null
|
|
|
|
? path.resolve(baseDirectory)
|
|
|
|
: path.resolve(baseDirectory, buildRootDirectory)
|
|
|
|
return resolvedBuildRootDirectory
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseCommandLineArguments(): string[] {
|
2020-06-14 17:05:03 +00:00
|
|
|
const input = github.inputOrNull('arguments')
|
2020-06-13 11:54:27 +00:00
|
|
|
return input === null ? [] : parseArgsStringToArgv(input)
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|