diff --git a/setup-bazel-cache/README.md b/setup-bazel-cache/README.md index bbb5938..60b2991 100644 --- a/setup-bazel-cache/README.md +++ b/setup-bazel-cache/README.md @@ -133,10 +133,9 @@ of the same reusable workflow. Reporting does not enable Bazel's test-result cache. - **`report-cache-step-summary`** - - Options: `true` (default), `false`. + - Options: `true`, `false` (default). - Set `false` to keep enabled reports in the job log without writing them to - the GitHub Actions step summary. + Set `true` to also write enabled reports to the GitHub Actions step summary. - **`enable-profiling`** - Options: `auto` (default), `true`, `false`. diff --git a/setup-bazel-cache/REFERENCE.md b/setup-bazel-cache/REFERENCE.md index 5768851..245518a 100644 --- a/setup-bazel-cache/REFERENCE.md +++ b/setup-bazel-cache/REFERENCE.md @@ -109,9 +109,9 @@ test-result cache behavior; it does not enable it. #### `report-cache-step-summary` -Defaults to `true`; accepts `true` or `false`. When enabled, the cache overview -is written to both the job log and the GitHub Actions step summary. When false, -the log report remains enabled according to the two report inputs above. +Defaults to `false`; accepts `true` or `false`. When enabled, the cache overview +is written to both the job log and the GitHub Actions step summary. The log +report remains enabled according to the two report inputs above either way. #### `enable-profiling` diff --git a/setup-bazel-cache/action.yml b/setup-bazel-cache/action.yml index c2ecc5d..ef98fb7 100644 --- a/setup-bazel-cache/action.yml +++ b/setup-bazel-cache/action.yml @@ -60,9 +60,9 @@ inputs: description: > Also write the cache overview enabled by report-cache-hits and report-test-cache-hits to the job's GitHub Actions step summary, not - just the job log. Accepts true or false and defaults to true. + just the job log. Accepts true or false and defaults to false. required: false - default: "true" + default: "false" # cache flags: diff --git a/setup-bazel-cache/src/report.js b/setup-bazel-cache/src/report.js index 173208f..ede77c1 100644 --- a/setup-bazel-cache/src/report.js +++ b/setup-bazel-cache/src/report.js @@ -165,7 +165,7 @@ async function logTestCacheSummary(root = invocationRootPath()) { return { reports, aggregates, notes: summaryNotes }; } -/** Resolve the opt-out step-summary input; the job log is reported regardless. */ +/** Resolve the optional step-summary input; the job log is reported regardless. */ function writeCacheStepSummaryEnabled(value) { const normalized = value.trim().toLowerCase(); if (normalized === 'true') return true; diff --git a/setup-bazel-cache/test/post-reporting.test.js b/setup-bazel-cache/test/post-reporting.test.js index 6354b4c..e58afd3 100644 --- a/setup-bazel-cache/test/post-reporting.test.js +++ b/setup-bazel-cache/test/post-reporting.test.js @@ -34,6 +34,7 @@ function fixture(context) { function runPost( root, enabled, + stepSummaryInput = 'false', summaryPath = path.join(root, 'summary.md'), state = { cacheSaveAllowed: false, invocationRoot: invocationRootPath(root) }, extraEnv = {}, @@ -51,7 +52,7 @@ function runPost( 'STATE_setup-bazel-cache-configuration': JSON.stringify(state), 'INPUT_REPORT-CACHE-HITS': 'true', 'INPUT_REPORT-TEST-CACHE-HITS': String(enabled), - 'INPUT_REPORT-CACHE-STEP-SUMMARY': 'true', + 'INPUT_REPORT-CACHE-STEP-SUMMARY': stepSummaryInput, 'INPUT_ENABLE-PROFILING': 'false', ...extraEnv, }, @@ -107,15 +108,38 @@ test('disabling the step summary keeps the job log but leaves the step summary e const { output, summary } = runPost( root, true, - undefined, - undefined, - { 'INPUT_REPORT-CACHE-STEP-SUMMARY': 'false' }, + 'false', ); assert.match(output, /Cache saving is disabled on this ref/); assert.doesNotMatch(output, /::warning::|::error::/); assert.equal(summary, ''); }); +test('the default keeps cache reports in the job log without writing a step summary', (context) => { + const root = fixture(context); + const invocationRoot = invocationRootPath(root); + initializeInvocationStore(invocationRoot); + const invocation = claimInvocation(invocationRoot, 'test', { + executionLog: false, + testCache: true, + profile: false, + }, ['//:default-summary-test']); + fs.writeFileSync(invocation.files.testCache, [ + JSON.stringify({ id: { testResult: { label: '//:default-summary-test' } }, testResult: { cachedLocally: true } }), + JSON.stringify({ lastMessage: true }), + ].join('\n')); + finishInvocation(invocation, 0); + + const manifest = fs.readFileSync(new URL('../action.yml', import.meta.url), 'utf8'); + const stepSummaryInput = manifest + .split(' report-cache-step-summary:\n')[1] + .split('\n\n # cache flags:')[0]; + assert.match(stepSummaryInput, /default: "false"/); + const { output, summary } = runPost(root, true); + assert.match(output, /000-test: \/\/:default-summary-test/); + assert.equal(summary, ''); +}); + test('test report preserves cache output and renders disabled, partial, and no-attempt states', (context) => { const root = fixture(context); const invocationRoot = invocationRootPath(root); @@ -156,9 +180,9 @@ test('test report preserves cache output and renders disabled, partial, and no-a startedAt: '2026-01-01T00:01:00.000Z', finishedAt: '2026-01-01T00:02:48.000Z', }); - const baseline = runPost(root, false); + const baseline = runPost(root, false, 'true'); fs.writeFileSync(path.join(root, 'summary.md'), ''); - const actual = runPost(root, true, path.join(root, 'summary.md'), { + const actual = runPost(root, true, 'true', path.join(root, 'summary.md'), { cacheSaveAllowed: false, restoreResults: { bazelisk: 'true', @@ -180,7 +204,7 @@ test('test report preserves cache output and renders disabled, partial, and no-a assert.doesNotMatch(actual.summary, /Disk cache/); assert.doesNotMatch(actual.summary, /\| External cache \|/); fs.writeFileSync(path.join(root, 'summary.md'), ''); - const withExternal = runPost(root, true, path.join(root, 'summary.md'), { + const withExternal = runPost(root, true, 'true', path.join(root, 'summary.md'), { cacheSaveAllowed: false, restoreResults: { external: 'false' }, externalManifestRestoreResult: 'true', @@ -238,7 +262,7 @@ test('summary groups repeated invocations with their target patterns', (context) }); } - const { output, summary } = runPost(root, true); + const { output, summary } = runPost(root, true, 'true'); assert.match(summary, /\| Cache \| Reused \/ total \| Hit rate \| Status \|/); for (let sequence = 0; sequence < 3; sequence += 1) { const elapsed = ['12\\.4 s', '1\\.8 min', '0\\.4 s'][sequence]; @@ -283,7 +307,7 @@ test('summary uses n/a for incomplete or invalid invocation timestamps', (contex finishInvocation(invalidStart, 0); updateInvocationMetadata(invalidStart, { startedAt: 'not-a-timestamp' }); - const { summary } = runPost(root, false); + const { summary } = runPost(root, false, 'true'); assert.match(summary, /

build · 000 · n\/a<\/h3>[\s\S]*?\| Build cache \| — \| n\/a \| Unavailable \|/); assert.match(summary, /

build · 001 · n\/a<\/h3>[\s\S]*?\| Build cache \| — \| n\/a \| Unavailable \|/); }); @@ -291,7 +315,7 @@ test('summary uses n/a for incomplete or invalid invocation timestamps', (contex test('summary write failures do not stop post-step processing', (context) => { const root = fixture(context); // A directory is accessible but cannot receive summary text. - const { output } = runPost(root, true, root); + const { output } = runPost(root, true, 'true', root); assert.match(output, /Bazel cache summary unavailable/); assert.match(output, /Cache saving is disabled on this ref/); assert.doesNotMatch(output, /::error::/);