Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions setup-bazel-cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
6 changes: 3 additions & 3 deletions setup-bazel-cache/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
4 changes: 2 additions & 2 deletions setup-bazel-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion setup-bazel-cache/src/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 34 additions & 10 deletions setup-bazel-cache/test/post-reporting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand All @@ -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,
},
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -283,15 +307,15 @@ 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, /<h3>build · 000 · n\/a<\/h3>[\s\S]*?\| Build cache \| — \| n\/a \| Unavailable \|/);
assert.match(summary, /<h3>build · 001 · n\/a<\/h3>[\s\S]*?\| Build cache \| — \| n\/a \| Unavailable \|/);
});

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::/);
Expand Down
Loading