gradle-build-action/src/execution.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-06-13 07:44:30 -04:00
import * as exec from '@actions/exec'
import * as cacheDependencies from './cache-dependencies'
import * as cacheConfiguration from './cache-configuration'
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> {
await cacheDependencies.restoreCachedDependencies(root)
await cacheConfiguration.restoreCachedConfiguration(root)
2020-06-13 07:44:30 -04:00
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-06-13 07:44:30 -04:00
if (line.startsWith('Publishing build scan...')) {
publishing = true
2019-09-21 10:01:53 -04:00
}
2020-06-13 07:54:27 -04:00
if (publishing && line.length === 0) {
2019-09-21 10:01:53 -04:00
publishing = false
}
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
}