gradle-build-action/src/execution.ts

38 lines
998 B
TypeScript
Raw Normal View History

2020-06-13 07:44:30 -04:00
import * as exec from '@actions/exec'
2019-09-21 10:01:53 -04:00
2020-06-13 07:44:30 -04:00
export async function execute(
executable: string,
root: string,
argv: string[]
): Promise<BuildResult> {
let publishing = false
let buildScanUrl: string | undefined
2019-09-21 10:01:53 -04:00
2019-09-23 06:11:18 -04:00
const status: number = await exec.exec(executable, argv, {
2019-09-21 10:01:53 -04:00
cwd: root,
2019-09-23 06:11:18 -04:00
ignoreReturnCode: true,
2019-09-21 10:01:53 -04:00
listeners: {
stdline: (line: string) => {
2020-09-13 07:09:14 -04:00
if (line.includes('Publishing build scan...')) {
2020-06-13 07:44:30 -04:00
publishing = true
2019-09-21 10:01:53 -04:00
}
2020-06-13 07:44:30 -04:00
if (publishing && line.startsWith('http')) {
buildScanUrl = line.trim()
2019-09-21 10:01:53 -04:00
publishing = false
}
}
}
2020-06-13 07:44:30 -04:00
})
2019-09-21 10:01:53 -04:00
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
}