mirror of
https://github.com/gradle/actions.git
synced 2025-08-18 14:51:28 +08:00
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import * as core from '@actions/core'
|
|
import * as exec from '@actions/exec'
|
|
|
|
import * as provisioner from './provision'
|
|
import * as gradlew from './gradlew'
|
|
|
|
export async function provisionAndMaybeExecute(
|
|
gradleVersion: string,
|
|
buildRootDirectory: string,
|
|
args: string[]
|
|
): Promise<void> {
|
|
// Download and install Gradle if required
|
|
const executable = await provisioner.provisionGradle(gradleVersion)
|
|
|
|
// Only execute if arguments have been provided
|
|
if (args.length > 0) {
|
|
await executeGradleBuild(executable, buildRootDirectory, args)
|
|
}
|
|
}
|
|
|
|
async function executeGradleBuild(executable: string | undefined, root: string, args: string[]): Promise<void> {
|
|
// Use the provided executable, or look for a Gradle wrapper script to run
|
|
const toExecute = executable ?? gradlew.gradleWrapperScript(root)
|
|
|
|
const status: number = await exec.exec(toExecute, args, {
|
|
cwd: root,
|
|
ignoreReturnCode: true
|
|
})
|
|
|
|
if (status !== 0) {
|
|
core.setFailed(`Gradle build failed: see console output for details`)
|
|
}
|
|
}
|