PREQ-6373: Fix regression with build-number cache path#296
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the build-number caching strategy for the get-build-number composite action by moving the cached build_number.txt from ${RUNNER_TEMP} to a path relative to the workspace, aiming to avoid cache misses across different runner types in the same workflow.
Changes:
- Switch the build-number cache file location to
../build_number.txt. - Simplify
get_build_number.shby writing directly toBUILD_NUMBER_FILE(removing theCACHE_FILEalias). - Update ShellSpec coverage to assert against
BUILD_NUMBER_FILEdirectly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
spec/get_build_number_spec.sh |
Updates the test to use the new BUILD_NUMBER_FILE path and validate the written cache file. |
get-build-number/get_build_number.sh |
Changes the default build-number cache file location and writes the incremented build number to it. |
get-build-number/action.yml |
Exports the new cache file path via GITHUB_ENV so cache restore/save and subsequent steps use it. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
julien-carsique-sonarsource
left a comment
There was a problem hiding this comment.
Initially, it was build_number.txt. Replacing with ../build_number.txt should work as well.
cceb6a1 to
522fb18
Compare
522fb18 to
24647af
Compare
24647af to
9435549
Compare
9435549 to
c802611
Compare
c802611 to
173266b
Compare
Use .build_number.txt (workspace-relative) instead of ${RUNNER_TEMP}/build_number.txt.
RUNNER_TEMP differs between runner types; ../ paths are rejected by actions/cache.
Export BUILD_NUMBER, save the cache, then remove the file so the checkout stays clean.
Document .build_number.txt as a reserved filename.
Assert git status is clean after get-build-number.
173266b to
0768895
Compare
|
Code Review ✅ Approved 3 resolved / 3 findingsRestores cross-runner cache persistence by relocating the build number file to the workspace root and cleaning it up post-execution. Ensure the unconditional workspace cleanup does not inadvertently delete pre-existing user files matching the .build_number.txt naming convention. ✅ 3 resolved✅ Edge Case: rm -f may delete a user's existing build_number.txt
✅ Quality: mktemp temp dir is never cleaned up in spec
✅ Edge Case: Cleanup rm -f deletes a pre-existing workspace .build_number.txt
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |



Summary
Fixes the regression introduced in #287 (BUILD-11553), where moving the build-number cache file to
${RUNNER_TEMP}/build_number.txtbroke cache restore across jobs on different runner types and OSes..build_number.txt(workspace-relative) instead of${RUNNER_TEMP}/build_number.txt, which differs between GitHub-hosted and ARC runners and breaksactions/cacherestore across jobsactions/cacherejects..in paths, so parent-directory locations cannot be cached; a workspace-relative file withenableCrossOsArchive: trueworks across Linux and Windows runnersBUILD_NUMBERtoGITHUB_ENV/ outputs and saving the cache, remove the file from the workspace so calling workflows are not polluted (preserving the intent of BUILD-11553: Avoid workspace pollution in CI actions #287).build_number.txtrather thanbuild_number.txtto avoid colliding with a tracked file in consuming repositories; document the reserved filename in the READMEget_build_number.shby usingBUILD_NUMBER_FILEdirectly instead of a separateCACHE_FILEaliastest-build-number-generation(git status --porcelainmust be empty afterget-build-number); drop/build_number.txtfrom.gitignoreso a leftover cache file is visible to git statusNote
test-build-number-reuse-from-cachejobs fail the workflow when the build number does not match, due to the flakyness of GitHub hosted cacheTest plan
shellspec spec/get_build_number_spec.shpasses locallyTest Build Numberworkflow passes on the PR (cross-runner and cross-OS cache reuse, workspace not polluted)sonar-dotnet-a3s