gradle-build-action/src/execution.ts

27 lines
906 B
TypeScript
Raw Normal View History

import * as core from '@actions/core'
2020-06-13 13:44:30 +02:00
import * as exec from '@actions/exec'
import fs from 'fs'
import * as gradlew from './gradlew'
2019-09-21 16:01:53 +02: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)
verifyIsExecutableScript(toExecute)
const status: number = await exec.exec(toExecute, args, {
2019-09-21 16:01:53 +02:00
cwd: root,
ignoreReturnCode: true
2020-06-13 13:44:30 +02:00
})
2019-09-21 16:01:53 +02:00
if (status !== 0) {
core.setFailed(`Gradle build failed: see console output for details`)
}
2019-09-21 16:01:53 +02: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.`)
}
}