Unverified Commit e8866c8b authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[ci] Skip passed-tests cache steps for jobs that never run tests (#96001)

CI jobs in `build_and_test` printed a "Cache save failed." warning from
the "Save passed-tests cache" step even when they never run tests. The
step ran for every job with an `afterBuild` command, but
`.next-test-passed.txt` is only ever written by `run-tests.js`, so jobs
like lint, rust-check, or types-and-precompiled warned on every run
because the path never existed.

`run-tests.js` already owns the decision of whether result caching is
active (`profile.cachingEnabled`), so it now signals the workflow
itself: when it opens the passed-tests file (which happens before any
test runs, and only when result caching is enabled), it writes the path
to the `passed_tests_file` step output. The "Save passed-tests cache"
step in `build_reusable.yml` only runs when that output is present and
takes its `path` from it. Jobs that never run `run-tests.js`, and
flake-detection runs (where `NEXT_FLAKE_DETECTION` disables the result
cache), never emit the output and skip the save silently. A job that
fails midway through its tests has already emitted the output, so its
partial file still saves and a genuine warning is still possible.
parent 044ef6dc
...@@ -413,6 +413,7 @@ jobs: ...@@ -413,6 +413,7 @@ jobs:
next-test-passed-${{ steps.var.outputs.input_step_key }}-${{ github.run_id }}- next-test-passed-${{ steps.var.outputs.input_step_key }}-${{ github.run_id }}-
- run: ${{ inputs.afterBuild }} - run: ${{ inputs.afterBuild }}
id: after-build
# defaults.run.shell sets a stronger options (`-leo pipefail`) # defaults.run.shell sets a stronger options (`-leo pipefail`)
# Set this back to github action's weaker defaults: # Set this back to github action's weaker defaults:
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell # https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
...@@ -423,11 +424,15 @@ jobs: ...@@ -423,11 +424,15 @@ jobs:
# Save the passed-tests file so the next attempt (if any) can skip # Save the passed-tests file so the next attempt (if any) can skip
# them. `always()` makes this run on success, failure, or cancellation. # them. `always()` makes this run on success, failure, or cancellation.
# run-tests.js emits the `passed_tests_file` step output when it creates
# the file (before running any test), so this step is skipped for jobs
# that never run run-tests.js or that disable the result cache (e.g.
# flake detection) instead of warning about a missing path.
- name: Save passed-tests cache - name: Save passed-tests cache
if: ${{ always() && inputs.afterBuild }} if: ${{ always() && steps.after-build.outputs.passed_tests_file != '' }}
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with: with:
path: ${{ env.NEXT_TEST_PASSED_FILE }} path: ${{ steps.after-build.outputs.passed_tests_file }}
key: next-test-passed-${{ steps.var.outputs.input_step_key }}-${{ github.run_id }}-attempt${{ github.run_attempt }} key: next-test-passed-${{ steps.var.outputs.input_step_key }}-${{ github.run_id }}-attempt${{ github.run_attempt }}
- name: Upload test result artifacts - name: Upload test result artifacts
......
...@@ -132,6 +132,12 @@ class TestProfile { ...@@ -132,6 +132,12 @@ class TestProfile {
if (!file) return new Set() if (!file) return new Set()
try { try {
const data = fs.readFileSync(file, 'utf8') const data = fs.readFileSync(file, 'utf8')
// The file is created (in append mode) before any test runs, so it's
// empty when no test passed (or none ran at all) in the earlier
// attempt.
if (data === '') {
return new Set()
}
// Tolerate a partial trailing line from a hard kill mid-append by // Tolerate a partial trailing line from a hard kill mid-append by
// requiring an explicit '\0' terminator. Lines without it are // requiring an explicit '\0' terminator. Lines without it are
// dropped. // dropped.
...@@ -875,6 +881,17 @@ ${ENDGROUP}`) ...@@ -875,6 +881,17 @@ ${ENDGROUP}`)
if (profile.cachingEnabled) { if (profile.cachingEnabled) {
try { try {
passedTestsFd = fs.openSync(process.env.NEXT_TEST_PASSED_FILE, 'a') passedTestsFd = fs.openSync(process.env.NEXT_TEST_PASSED_FILE, 'a')
// Tell the workflow that the file exists. Its "Save passed-tests
// cache" step (see `.github/workflows/build_reusable.yml`) only runs
// when this output is present, so jobs that never get here (no
// run-tests.js, or result caching disabled) skip the save instead of
// warning about a missing path.
if (process.env.GITHUB_OUTPUT) {
fs.appendFileSync(
process.env.GITHUB_OUTPUT,
`passed_tests_file=${process.env.NEXT_TEST_PASSED_FILE}\n`
)
}
} catch (err) { } catch (err) {
console.log(`Test result cache: open failed (${err.message})`) console.log(`Test result cache: open failed (${err.message})`)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment