Skip to content

PREQ-6373: Fix regression with build-number cache path#296

Merged
matemoln merged 1 commit into
masterfrom
fix/mmolnar/PREQ-6373-buildNumberCachePath
Jun 12, 2026
Merged

PREQ-6373: Fix regression with build-number cache path#296
matemoln merged 1 commit into
masterfrom
fix/mmolnar/PREQ-6373-buildNumberCachePath

Conversation

@matemoln

@matemoln matemoln commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the regression introduced in #287 (BUILD-11553), where moving the build-number cache file to ${RUNNER_TEMP}/build_number.txt broke cache restore across jobs on different runner types and OSes.

  • Store the build-number cache at .build_number.txt (workspace-relative) instead of ${RUNNER_TEMP}/build_number.txt, which differs between GitHub-hosted and ARC runners and breaks actions/cache restore across jobs
  • actions/cache rejects .. in paths, so parent-directory locations cannot be cached; a workspace-relative file with enableCrossOsArchive: true works across Linux and Windows runners
  • After exporting BUILD_NUMBER to GITHUB_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)
  • Use .build_number.txt rather than build_number.txt to avoid colliding with a tracked file in consuming repositories; document the reserved filename in the README
  • Simplify get_build_number.sh by using BUILD_NUMBER_FILE directly instead of a separate CACHE_FILE alias
  • Add a workspace cleanliness check to test-build-number-generation (git status --porcelain must be empty after get-build-number); drop /build_number.txt from .gitignore so a leftover cache file is visible to git status

Note

  • We can not make test-build-number-reuse-from-cache jobs fail the workflow when the build number does not match, due to the flakyness of GitHub hosted cache

Test plan

  • shellspec spec/get_build_number_spec.sh passes locally
  • CI Test Build Number workflow passes on the PR (cross-runner and cross-OS cache reuse, workspace not polluted)
  • Verify cache restore works across jobs on different ARC runners in sonar-dotnet-a3s

Copilot AI review requested due to automatic review settings June 12, 2026 09:59
@matemoln matemoln requested a review from a team as a code owner June 12, 2026 09:59
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Jun 12, 2026

Copy link
Copy Markdown

PREQ-6373

Comment thread spec/get_build_number_spec.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sh by writing directly to BUILD_NUMBER_FILE (removing the CACHE_FILE alias).
  • Update ShellSpec coverage to assert against BUILD_NUMBER_FILE directly.

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.

Comment thread get-build-number/action.yml Outdated
Comment thread get-build-number/get_build_number.sh Outdated
Comment thread spec/get_build_number_spec.sh Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, it was build_number.txt. Replacing with ../build_number.txt should work as well.

@matemoln matemoln force-pushed the fix/mmolnar/PREQ-6373-buildNumberCachePath branch from cceb6a1 to 522fb18 Compare June 12, 2026 13:21
@matemoln matemoln force-pushed the fix/mmolnar/PREQ-6373-buildNumberCachePath branch from 522fb18 to 24647af Compare June 12, 2026 13:57
@matemoln matemoln changed the title PREQ-6373: Use relative path for build-number cache file PREQ-6373: Fix build-number cache path and workspace cleanup Jun 12, 2026
Comment thread get-build-number/action.yml Outdated
@matemoln matemoln force-pushed the fix/mmolnar/PREQ-6373-buildNumberCachePath branch from 24647af to 9435549 Compare June 12, 2026 16:28
Comment thread get-build-number/action.yml
@matemoln matemoln force-pushed the fix/mmolnar/PREQ-6373-buildNumberCachePath branch from 9435549 to c802611 Compare June 12, 2026 16:34
@matemoln matemoln force-pushed the fix/mmolnar/PREQ-6373-buildNumberCachePath branch from c802611 to 173266b Compare June 12, 2026 16:46
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.
@matemoln matemoln force-pushed the fix/mmolnar/PREQ-6373-buildNumberCachePath branch from 173266b to 0768895 Compare June 12, 2026 17:04
@sonarqubecloud

Copy link
Copy Markdown

@matemoln matemoln changed the title PREQ-6373: Fix build-number cache path and workspace cleanup PREQ-6373: Fix regression with build-number cache path Jun 12, 2026
@matemoln matemoln merged commit a1c666e into master Jun 12, 2026
17 checks passed
@matemoln matemoln deleted the fix/mmolnar/PREQ-6373-buildNumberCachePath branch June 12, 2026 17:20
@gitar-bot

gitar-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 3 resolved / 3 findings

Restores 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

📄 get-build-number/action.yml:32 📄 get-build-number/action.yml:86-89
BUILD_NUMBER_FILE is now a workspace-relative path (build_number.txt). The action both writes to this path and unconditionally removes it via rm -f "$BUILD_NUMBER_FILE" with if: always(). The action's default working directory is GITHUB_WORKSPACE, which is the checked-out repository. If a consuming repository happens to track a file named build_number.txt at its root, this action will overwrite it and then delete it, causing silent data loss / a dirty working tree for the caller. Consider using a less collision-prone name (e.g. .build_number.txt or a dedicated subdir) or only removing the file if the action created it. At minimum, document the reserved filename.

Quality: mktemp temp dir is never cleaned up in spec

📄 spec/get_build_number_spec.sh:5-6
The spec now creates a temp directory via TEMP_DIR=$(mktemp -d) and points BUILD_NUMBER_FILE at it, but nothing ever removes TEMP_DIR. The previous approach used ${SHELLSPEC_TMPBASE:-/tmp}, where SHELLSPEC_TMPBASE is managed and cleaned up by shellspec automatically. Each run of this spec now leaks a temp directory under the system temp location. Consider reusing the shellspec-managed temp base (e.g. TEMP_DIR="${SHELLSPEC_TMPBASE:-$(mktemp -d)}") or register a cleanup hook (AfterAll 'rm -rf "$TEMP_DIR"') so the directory is removed after the suite.

Edge Case: Cleanup rm -f deletes a pre-existing workspace .build_number.txt

📄 get-build-number/action.yml:86-89
The new 'Remove build number file from workspace' step runs rm -f "$BUILD_NUMBER_FILE" with if: always(), where BUILD_NUMBER_FILE resolves to the workspace-relative .build_number.txt. If a consuming repository already has a file named .build_number.txt checked out (tracked or untracked), this step deletes it from the workspace whenever the action runs — including on the from-env path. This is now documented in the README as a reserved filename, which mitigates the risk, so severity is minor. If you want to be safer, only remove the file when the action itself created it (e.g. record a marker before writing) so a user's file is never silently removed.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants