mirror of
https://github.com/gradle/actions.git
synced 2025-08-26 11:51:27 +08:00
On long-lived machines, it's possible that the `.build-results` directory isn't cleared between invocations. This will result in the job summary including results from previous jobs. By marking each build-results file as 'processed' at the end of the job, we can avoid this scenario.
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import * as fs from 'fs'
|
|
import * as path from 'path'
|
|
|
|
export interface BuildResult {
|
|
get rootProjectName(): string
|
|
get rootProjectDir(): string
|
|
get requestedTasks(): string
|
|
get gradleVersion(): string
|
|
get gradleHomeDir(): string
|
|
get buildFailed(): boolean
|
|
get buildScanUri(): string
|
|
get buildScanFailed(): boolean
|
|
}
|
|
|
|
export function loadBuildResults(): BuildResult[] {
|
|
return getUnprocessedResults().map(filePath => {
|
|
const content = fs.readFileSync(filePath, 'utf8')
|
|
return JSON.parse(content) as BuildResult
|
|
})
|
|
}
|
|
|
|
export function markBuildResultsProcessed(): void {
|
|
getUnprocessedResults().forEach(markProcessed)
|
|
}
|
|
|
|
function getUnprocessedResults(): string[] {
|
|
const buildResultsDir = path.resolve(process.env['RUNNER_TEMP']!, '.build-results')
|
|
if (!fs.existsSync(buildResultsDir)) {
|
|
return []
|
|
}
|
|
|
|
return fs
|
|
.readdirSync(buildResultsDir)
|
|
.map(file => {
|
|
return path.resolve(buildResultsDir, file)
|
|
})
|
|
.filter(filePath => {
|
|
return path.extname(filePath) === '.json' && !isProcessed(filePath)
|
|
})
|
|
}
|
|
|
|
function isProcessed(resultFile: string): boolean {
|
|
const markerFile = `${resultFile}.processed`
|
|
return fs.existsSync(markerFile)
|
|
}
|
|
|
|
function markProcessed(resultFile: string): void {
|
|
const markerFile = `${resultFile}.processed`
|
|
fs.writeFileSync(markerFile, '')
|
|
}
|