gradle-build-action/src/execution.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-06-13 11:44:30 +00:00
import * as exec from '@actions/exec'
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,
args: string[]
2020-06-13 11:44:30 +00:00
): Promise<BuildResult> {
let buildScanUrl: string | undefined
2019-09-21 14:01:53 +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,
ignoreReturnCode: true
2020-06-13 11:44:30 +00:00
})
2019-09-21 14:01:53 +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
}