Skip to content

BUILD-10699: Adds fallback-to-default-branch option for setting restore-keys#42

Merged
bwalsh434 merged 1 commit intomasterfrom
BUILD-10699-default-restore-keys-to-default-branch
Mar 19, 2026
Merged

BUILD-10699: Adds fallback-to-default-branch option for setting restore-keys#42
bwalsh434 merged 1 commit intomasterfrom
BUILD-10699-default-restore-keys-to-default-branch

Conversation

@bwalsh434
Copy link
Contributor

@bwalsh434 bwalsh434 commented Mar 17, 2026

What Changed?

  • Adds the fallback-to-default-branch option, which is enabled by default, for setting the restore-keys value to the same exact cache path, but on the repo's default branch
    • If a repo consuming the action explicitly sets the restore-keys: node-linux- and fallback-to-default-branch: true, then the final branch-restore-keys passed to runs-on/cache would be:
feature/my-branch/node-linux-        ← user's restore key (branch-scoped), tried first
refs/heads/main/node-linux-     
  • Updates README to reflect this new option

First Test

[Edit 19/03 1:16pm CET] Tested Successfully using latest commit:

  • ✅ cache successfully restored from master branch cache on first run in new PR - link
    • Cache restored from key: refs/heads/master/maven-Linux-Build-b50b0c779ede66991f6393f3b8e901d98462992773465df71c125f902ada551f
  • ✅ cache successfully restored from feature branch cache on second run in new PR - link
    • Cache restored from key: BUILD-10699-test-fallback-to-default-branch-v2/maven-Linux-Build-b50b0c779ede66991f6393f3b8e901d98462992773465df71c125f902ada551f

@bwalsh434 bwalsh434 force-pushed the BUILD-10699-default-restore-keys-to-default-branch branch from 3121756 to 3c1a973 Compare March 17, 2026 20:47
@bwalsh434 bwalsh434 marked this pull request as ready for review March 17, 2026 21:03
@bwalsh434 bwalsh434 requested a review from a team as a code owner March 17, 2026 21:03
@sonar-review-alpha
Copy link

sonar-review-alpha bot commented Mar 17, 2026

Summary

Adds a new fallback-to-default-branch input (enabled by default) that automatically provides a fallback restore key pointing to the repository's default branch cache on the S3 backend. The feature works with or without explicit restore-keys — if none are provided, it falls back to the exact cache key on the default branch. A safeguard prevents attempting fallback when already on the default branch itself.

What reviewers should know

Where to start: Check scripts/prepare-keys.sh for the core logic changes. The script now decouples branch-specific restore keys from default branch fallback, applying the latter conditionally based on the new toggle.

Key decisions to review:

  • When no restore-keys are provided and fallback is enabled, the script now uses the primary INPUT_KEY for the default branch fallback (exact match), extending the feature beyond prefix matching
  • The script skips default branch fallback if the current branch matches the fallback branch, avoiding unnecessary restore key duplication
  • Default of true makes this a backward-compatible quality-of-life improvement

Test coverage: The author links to real-world testing in sonarlint-core showing the feature works on both cold and warm caches. Worth verifying the behavior matches the README examples.


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

Conclusion: Solid implementation. The feature logic is correct, fits the existing patterns, and the on-default-branch guard is a nice touch. One dead-code path to clean up, but it doesn't affect runtime behavior.

🗣️ Give feedback

@julien-carsique-sonarsource julien-carsique-sonarsource force-pushed the BUILD-10699-default-restore-keys-to-default-branch branch from 3c1a973 to 289e59d Compare March 18, 2026 08:21
Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

LGTM! ✅

🗣️ Give feedback

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a bug to resolve (dead code).

Clarify the validation and setup of default values at the top, or first use. Not on every call (i.e. "${INPUT_RESTORE_KEYS:-}").
Use the simplified syntax (i.e. in [[ ]], there is no need for double quotes on the left side of the condition).

@bwalsh434 bwalsh434 force-pushed the BUILD-10699-default-restore-keys-to-default-branch branch from 289e59d to 00e1a5d Compare March 18, 2026 21:22
Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

The dead-code branch flagged in the previous review is still present — the if [[ -n "$RESTORE_KEYS" ]] guard inside the no-restore-keys path is unreachable and the simplification to a direct assignment was not applied.

🗣️ Give feedback

Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

Conclusion: The PR needs one fix before merge — the dead-code branch flagged in the previous review is still there.

🗣️ Give feedback

Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

Conclusion: The previously flagged dead code is still present, and the new commit introduced a new bash correctness issue.

🗣️ Give feedback

Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

Conclusion: The dead-code simplification is clean. One previous review comment remains unaddressed.

🗣️ Give feedback

@bwalsh434 bwalsh434 force-pushed the BUILD-10699-default-restore-keys-to-default-branch branch 2 times, most recently from 5ab0f5f to e5a09e6 Compare March 18, 2026 21:39
Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

Conclusion: The feature logic is sound and the new fallback-to-default-branch behaviour is correctly implemented. However, the previously requested fix (quoting $INPUT_RESTORE_KEYS in the [[ -n ]] tests) has not been applied — it still appears unquoted at both lines 46 and 79.

🗣️ Give feedback

@mikolaj-matuszny-ext-sonarsource mikolaj-matuszny-ext-sonarsource force-pushed the BUILD-10699-default-restore-keys-to-default-branch branch from e5a09e6 to 46c99b0 Compare March 19, 2026 15:47
Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

Conclusion: The new fallback-to-default-branch feature works correctly for the common cases, but there is a semantic conflict between the two related inputs that will silently misbehave for users who have both configured.

🗣️ Give feedback

Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

Conclusion: The fallback-branch / fallback-to-default-branch interaction is now correctly handled. The quoting inconsistency from the previous review round is still present.

🗣️ Give feedback

@bwalsh434 bwalsh434 force-pushed the BUILD-10699-default-restore-keys-to-default-branch branch from 556e203 to 5f49da5 Compare March 19, 2026 18:02
@sonarqube-cloud-us
Copy link

@sonarqubecloud
Copy link

Copy link

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

LGTM! ✅

🗣️ Give feedback

@bwalsh434 bwalsh434 merged commit 59847de into master Mar 19, 2026
14 checks passed
@bwalsh434 bwalsh434 deleted the BUILD-10699-default-restore-keys-to-default-branch branch March 19, 2026 18:42
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.

2 participants