2021-12-08 16:05:04 +00:00
|
|
|
import * as core from '@actions/core'
|
2020-06-13 11:44:30 +00:00
|
|
|
import * as exec from '@actions/exec'
|
2021-09-28 04:54:22 +00:00
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
2021-12-08 16:05:04 +00:00
|
|
|
import * as gradlew from './gradlew'
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2021-12-08 16:05:04 +00:00
|
|
|
export async function executeGradleBuild(executable: string | undefined, root: string, args: string[]): Promise<void> {
|
2020-06-13 11:44:30 +00:00
|
|
|
let buildScanUrl: string | undefined
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2021-09-28 04:54:22 +00:00
|
|
|
const buildScanFile = path.resolve(root, 'gradle-build-scan.txt')
|
|
|
|
if (fs.existsSync(buildScanFile)) {
|
|
|
|
fs.unlinkSync(buildScanFile)
|
|
|
|
}
|
|
|
|
|
2021-12-08 16:05:04 +00:00
|
|
|
// Use the provided executable, or look for a Gradle wrapper script to run
|
|
|
|
const toExecute = executable ?? gradlew.locateGradleWrapperScript(root)
|
|
|
|
const status: number = await exec.exec(toExecute, args, {
|
2019-09-21 14:01:53 +00:00
|
|
|
cwd: root,
|
2021-09-28 04:54:22 +00:00
|
|
|
ignoreReturnCode: true
|
2020-06-13 11:44:30 +00:00
|
|
|
})
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2021-09-28 04:54:22 +00:00
|
|
|
if (fs.existsSync(buildScanFile)) {
|
|
|
|
buildScanUrl = fs.readFileSync(buildScanFile, 'utf-8')
|
|
|
|
}
|
|
|
|
|
2021-12-08 16:05:04 +00:00
|
|
|
if (status !== 0) {
|
|
|
|
if (buildScanUrl) {
|
|
|
|
core.setFailed(`Gradle build failed: ${buildScanUrl}`)
|
|
|
|
} else {
|
|
|
|
core.setFailed(`Gradle build failed: process exited with status ${status}`)
|
|
|
|
}
|
|
|
|
}
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|