Unverified Commit e235596c authored by Daz DeBoer's avatar Daz DeBoer Committed by GitHub
Browse files

Only process build results once (#133)

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.
parent 6232a3f5
Loading
Loading
Loading
Loading
+4
Changes for .github/workflows/demo-job-summary.yml: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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
+28 −6
Changes for dist/dependency-submission/main/index.js: 28 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -139677,21 +139677,42 @@ var __importStar = (this && this.__importStar) || function (mod) {
    return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.loadBuildResults = void 0;
exports.markBuildResultsProcessed = exports.loadBuildResults = void 0;
const fs = __importStar(__nccwpck_require__(57147));
const path = __importStar(__nccwpck_require__(71017));
function loadBuildResults() {
    return getUnprocessedResults().map(filePath => {
        const content = fs.readFileSync(filePath, 'utf8');
        return JSON.parse(content);
    });
}
exports.loadBuildResults = loadBuildResults;
function markBuildResultsProcessed() {
    getUnprocessedResults().forEach(markProcessed);
}
exports.markBuildResultsProcessed = markBuildResultsProcessed;
function getUnprocessedResults() {
    const buildResultsDir = path.resolve(process.env['RUNNER_TEMP'], '.build-results');
    if (!fs.existsSync(buildResultsDir)) {
        return [];
    }
    return fs.readdirSync(buildResultsDir).map(file => {
        const filePath = path.join(buildResultsDir, file);
        const content = fs.readFileSync(filePath, 'utf8');
        return JSON.parse(content);
    return fs
        .readdirSync(buildResultsDir)
        .map(file => {
        return path.resolve(buildResultsDir, file);
    })
        .filter(filePath => {
        return path.extname(filePath) === '.json' && !isProcessed(filePath);
    });
}
exports.loadBuildResults = loadBuildResults;
function isProcessed(resultFile) {
    const markerFile = `${resultFile}.processed`;
    return fs.existsSync(markerFile);
}
function markProcessed(resultFile) {
    const markerFile = `${resultFile}.processed`;
    fs.writeFileSync(markerFile, '');
}
/***/ }),
@@ -142420,6 +142441,7 @@ function complete(cacheConfig, summaryConfig) {
        yield caches.save(userHome, gradleUserHome, cacheListener, daemonController, cacheConfig);
        const cachingReport = (0, cache_reporting_1.generateCachingReport)(cacheListener);
        yield jobSummary.generateJobSummary(buildResults, cachingReport, summaryConfig);
        (0, build_results_1.markBuildResultsProcessed)();
        core.info('Completed post-action step');
        return true;
    });
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+28 −6
Changes for dist/dependency-submission/post/index.js: 28 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -91105,21 +91105,42 @@ var __importStar = (this && this.__importStar) || function (mod) {
    return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.loadBuildResults = void 0;
exports.markBuildResultsProcessed = exports.loadBuildResults = void 0;
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
function loadBuildResults() {
    return getUnprocessedResults().map(filePath => {
        const content = fs.readFileSync(filePath, 'utf8');
        return JSON.parse(content);
    });
}
exports.loadBuildResults = loadBuildResults;
function markBuildResultsProcessed() {
    getUnprocessedResults().forEach(markProcessed);
}
exports.markBuildResultsProcessed = markBuildResultsProcessed;
function getUnprocessedResults() {
    const buildResultsDir = path.resolve(process.env['RUNNER_TEMP'], '.build-results');
    if (!fs.existsSync(buildResultsDir)) {
        return [];
    }
    return fs.readdirSync(buildResultsDir).map(file => {
        const filePath = path.join(buildResultsDir, file);
        const content = fs.readFileSync(filePath, 'utf8');
        return JSON.parse(content);
    return fs
        .readdirSync(buildResultsDir)
        .map(file => {
        return path.resolve(buildResultsDir, file);
    })
        .filter(filePath => {
        return path.extname(filePath) === '.json' && !isProcessed(filePath);
    });
}
exports.loadBuildResults = loadBuildResults;
function isProcessed(resultFile) {
    const markerFile = `${resultFile}.processed`;
    return fs.existsSync(markerFile);
}
function markProcessed(resultFile) {
    const markerFile = `${resultFile}.processed`;
    fs.writeFileSync(markerFile, '');
}
/***/ }),
@@ -93188,6 +93209,7 @@ function complete(cacheConfig, summaryConfig) {
        yield caches.save(userHome, gradleUserHome, cacheListener, daemonController, cacheConfig);
        const cachingReport = (0, cache_reporting_1.generateCachingReport)(cacheListener);
        yield jobSummary.generateJobSummary(buildResults, cachingReport, summaryConfig);
        (0, build_results_1.markBuildResultsProcessed)();
        core.info('Completed post-action step');
        return true;
    });
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

Loading