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'
|
|
|
|
import {writeInitScript} from './gradle-init'
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2020-06-13 11:44:30 +00:00
|
|
|
export async function execute(
|
|
|
|
executable: string,
|
|
|
|
root: string,
|
2021-09-28 04:54:22 +00:00
|
|
|
args: string[]
|
2020-06-13 11:44:30 +00:00
|
|
|
): Promise<BuildResult> {
|
|
|
|
let buildScanUrl: string | undefined
|
2019-09-21 14:01:53 +00:00
|
|
|
|
2021-09-28 04:54:22 +00:00
|
|
|
// TODO: instead of running with no-daemon, run `--stop` in post action.
|
|
|
|
args.push('--no-daemon')
|
|
|
|
|
|
|
|
const initScript = writeInitScript()
|
|
|
|
args.push('--init-script')
|
|
|
|
args.push(initScript)
|
|
|
|
|
|
|
|
const buildScanFile = path.resolve(root, 'gradle-build-scan.txt')
|
|
|
|
if (fs.existsSync(buildScanFile)) {
|
|
|
|
fs.unlinkSync(buildScanFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
const status: number = await exec.exec(executable, 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')
|
|
|
|
}
|
|
|
|
|
2020-06-13 11:44:30 +00:00
|
|
|
return new BuildResultImpl(status, buildScanUrl)
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface BuildResult {
|
2019-09-23 10:11:18 +00:00
|
|
|
readonly status: number
|
|
|
|
readonly buildScanUrl?: string
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BuildResultImpl implements BuildResult {
|
2020-06-13 11:44:30 +00:00
|
|
|
constructor(readonly status: number, readonly buildScanUrl?: string) {}
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|