2020-06-13 07:44:30 -04:00
|
|
|
import * as exec from '@actions/exec'
|
2021-09-28 00:54:22 -04:00
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
2021-09-28 02:04:03 -04:00
|
|
|
import {writeInitScript} from './build-scan-capture'
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2020-06-13 07:44:30 -04:00
|
|
|
export async function execute(
|
|
|
|
executable: string,
|
|
|
|
root: string,
|
2021-09-28 00:54:22 -04:00
|
|
|
args: string[]
|
2020-06-13 07:44:30 -04:00
|
|
|
): Promise<BuildResult> {
|
|
|
|
let buildScanUrl: string | undefined
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2021-09-28 00:54:22 -04: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 10:01:53 -04:00
|
|
|
cwd: root,
|
2021-09-28 00:54:22 -04:00
|
|
|
ignoreReturnCode: true
|
2020-06-13 07:44:30 -04:00
|
|
|
})
|
2019-09-21 10:01:53 -04:00
|
|
|
|
2021-09-28 00:54:22 -04:00
|
|
|
if (fs.existsSync(buildScanFile)) {
|
|
|
|
buildScanUrl = fs.readFileSync(buildScanFile, 'utf-8')
|
|
|
|
}
|
|
|
|
|
2020-06-13 07:44:30 -04:00
|
|
|
return new BuildResultImpl(status, buildScanUrl)
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface BuildResult {
|
2019-09-23 06:11:18 -04:00
|
|
|
readonly status: number
|
|
|
|
readonly buildScanUrl?: string
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class BuildResultImpl implements BuildResult {
|
2020-06-13 07:44:30 -04:00
|
|
|
constructor(readonly status: number, readonly buildScanUrl?: string) {}
|
2019-09-21 10:01:53 -04:00
|
|
|
}
|