gradle-build-action/src/execution.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-06-13 07:44:30 -04:00
import * as exec from '@actions/exec'
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
export async function execute(executable: string, root: string, args: string[]): Promise<BuildResult> {
2020-06-13 07:44:30 -04:00
let buildScanUrl: string | undefined
2019-09-21 10:01:53 -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,
ignoreReturnCode: true
2020-06-13 07:44:30 -04:00
})
2019-09-21 10:01:53 -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
}