2021-12-08 09:05:04 -07:00
|
|
|
import * as core from '@actions/core'
|
2020-06-13 13:44:30 +02:00
|
|
|
import * as exec from '@actions/exec'
|
2021-09-27 22:54:22 -06:00
|
|
|
import fs from 'fs'
|
2021-12-08 09:05:04 -07:00
|
|
|
import * as gradlew from './gradlew'
|
2019-09-21 16:01:53 +02:00
|
|
|
|
2021-12-08 09:05:04 -07:00
|
|
|
export 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.locateGradleWrapperScript(root)
|
2021-12-30 21:34:15 -07:00
|
|
|
verifyIsExecutableScript(toExecute)
|
2021-12-08 09:05:04 -07:00
|
|
|
const status: number = await exec.exec(toExecute, args, {
|
2019-09-21 16:01:53 +02:00
|
|
|
cwd: root,
|
2021-09-27 22:54:22 -06:00
|
|
|
ignoreReturnCode: true
|
2020-06-13 13:44:30 +02:00
|
|
|
})
|
2019-09-21 16:01:53 +02:00
|
|
|
|
2021-12-08 09:05:04 -07:00
|
|
|
if (status !== 0) {
|
2022-05-24 14:07:36 +02:00
|
|
|
core.setFailed(`Gradle build failed: see console output for details`)
|
2021-12-08 09:05:04 -07:00
|
|
|
}
|
2019-09-21 16:01:53 +02:00
|
|
|
}
|
2021-12-30 21:34:15 -07:00
|
|
|
|
|
|
|
function verifyIsExecutableScript(toExecute: string): void {
|
|
|
|
try {
|
|
|
|
fs.accessSync(toExecute, fs.constants.X_OK)
|
|
|
|
} catch (err) {
|
|
|
|
throw new Error(`Gradle script '${toExecute}' is not executable.`)
|
|
|
|
}
|
|
|
|
}
|