gradle-build-action/src/execution.ts

33 lines
892 B
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'
2019-09-21 14:01:53 +00:00
export async function execute(executable: string, root: string, args: string[]): Promise<BuildResult> {
2020-06-13 11:44:30 +00:00
let buildScanUrl: string | undefined
2019-09-21 14:01:53 +00:00
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
}