mirror of
https://github.com/gradle/actions.git
synced 2025-04-21 18:29:18 +08:00
Mark build-result files as processed to avoid double-dipping
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', we can avoid this scenario.
This commit is contained in:
parent
6232a3f503
commit
b09c7e669a
4
.github/workflows/demo-job-summary.yml
vendored
4
.github/workflows/demo-job-summary.yml
vendored
@ -16,6 +16,10 @@ jobs:
|
||||
npm install
|
||||
npm run build
|
||||
working-directory: sources
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
- name: Setup Gradle
|
||||
uses: ./setup-gradle
|
||||
- name: Build kotlin-dsl project
|
||||
|
@ -13,15 +13,38 @@ export interface BuildResult {
|
||||
}
|
||||
|
||||
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 => {
|
||||
// Every file in the .build-results dir should be a BuildResults JSON
|
||||
const filePath = path.join(buildResultsDir, file)
|
||||
const content = fs.readFileSync(filePath, 'utf8')
|
||||
return JSON.parse(content) as BuildResult
|
||||
})
|
||||
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, '')
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import * as caches from './caching/caches'
|
||||
import * as jobSummary from './job-summary'
|
||||
import * as buildScan from './build-scan'
|
||||
|
||||
import {loadBuildResults} from './build-results'
|
||||
import {loadBuildResults, markBuildResultsProcessed} from './build-results'
|
||||
import {CacheListener, generateCachingReport} from './caching/cache-reporting'
|
||||
import {DaemonController} from './daemon-controller'
|
||||
import {BuildScanConfig, CacheConfig, SummaryConfig, getWorkspaceDirectory} from './input-params'
|
||||
@ -63,6 +63,8 @@ export async function complete(cacheConfig: CacheConfig, summaryConfig: SummaryC
|
||||
const cachingReport = generateCachingReport(cacheListener)
|
||||
await jobSummary.generateJobSummary(buildResults, cachingReport, summaryConfig)
|
||||
|
||||
markBuildResultsProcessed()
|
||||
|
||||
core.info('Completed post-action step')
|
||||
|
||||
return true
|
||||
|
Loading…
x
Reference in New Issue
Block a user