Skip to content

fix(ci): ensure PR base commit before secrets diff; avoid full-scan fallback#38482

Closed
mwfj wants to merge 3 commits intoopenclaw:mainfrom
mwfj:fix/secrets-pr-base-fetch
Closed

fix(ci): ensure PR base commit before secrets diff; avoid full-scan fallback#38482
mwfj wants to merge 3 commits intoopenclaw:mainfrom
mwfj:fix/secrets-pr-base-fetch

Conversation

@mwfj
Copy link
Copy Markdown

@mwfj mwfj commented Mar 7, 2026

Summary

  • add ensure-base-commit to the secrets job for pull_request events before changed-file diffing
  • move GitHub context values used by shell into env vars (PR_BASE_SHA, PUSH_BEFORE_SHA)

Why

PR runs with shallow checkout (fetch-depth: 1) can miss the base SHA and trigger:

  • Falling back to full detect-secrets scan.

That creates unrelated failures against repository-wide baseline noise.

Scope

  • only .github/workflows/ci.yml
  • no baseline widening and no detect-secrets allowlist behavior change

Linked

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR fixes a shallow-checkout race condition in the secrets CI job where a missing base commit caused the detect-secrets step to silently fall back to a full-repository scan instead of a targeted diff. It also hardens all inline GitHub context expressions against shell injection by moving them into env: variables.

Key changes:

  • Adds a new ensure-base-commit composite action step (runs only on pull_request events) that progressively deepens the shallow clone (25 → 100 → 300 commits, then full ref) until the PR base SHA is reachable — preventing the fallback to --all-files in the common case.
  • Replaces inline ${{ github.event.pull_request.base.sha }} and ${{ github.event.before }} shell interpolations with env: variables (PR_BASE_SHA, PUSH_BEFORE_SHA), following GitHub Actions security best practices.
  • Replaces ${{ github.ref }} / ${{ github.event_name }} with the already-available default environment variables $GITHUB_REF / $GITHUB_EVENT_NAME, which is correct and removes unnecessary expression interpolation inside run: blocks.
  • Note: The composite action exits 0 even when all fetch attempts fail, so in extreme edge cases the full-scan fallback in detect-secrets can still be triggered. This is graceful degradation rather than a hard failure, but the PR title "avoid full-scan fallback" slightly overstates the guarantee.

Confidence Score: 4/5

  • Safe to merge — changes are scoped entirely to the secrets CI job with no production code impact.
  • The logic is correct: the ensure-base-commit step runs before both diff-dependent steps, the env: variable approach is a strict improvement over inline expression interpolation, and default GitHub Actions vars ($GITHUB_REF, $GITHUB_EVENT_NAME) are used correctly. The only minor concern is that the composite action silently exits 0 on complete failure, meaning the full-scan fallback it aims to prevent can still occur in rare edge cases — but this is intentional graceful degradation and not a regression.
  • .github/actions/ensure-base-commit/action.yml — review whether the silent exit 0 on unresolvable base SHA matches the intended failure policy.

Comments Outside Diff (1)

  1. .github/workflows/ci.yml, line 349-355 (link)

    Full-scan fallback still reachable if ensure-base-commit can't resolve the SHA

    The ensure-base-commit action exits 0 even when all fetch attempts fail (the composite action's last code path — line 47 of action.yml — has no exit 1). In that edge case PR_BASE_SHA is still set but git rev-parse --verify "$BASE^{commit}" fails here, changed_files stays empty, and execution drops into the else branch — running a --all-files scan.

    This is likely acceptable as graceful degradation, but the PR title "avoid full-scan fallback" overstates the guarantee slightly. If stricter avoidance is desired, the composite action could exit 1 on complete failure so the job fails loudly rather than silently widening the scan scope.

Last reviewed commit: ec7cb66

@mwfj
Copy link
Copy Markdown
Author

mwfj commented Mar 7, 2026

Code is ready to review

@mwfj
Copy link
Copy Markdown
Author

mwfj commented Mar 9, 2026

Closing this PR because the fix has already landed upstream in main (CI workflow now includes the base-commit fetch + scoped detect-secrets behavior). Keeping this open would duplicate the existing upstream change. Thanks!

@mwfj
Copy link
Copy Markdown
Author

mwfj commented Mar 9, 2026

Closing as already fixed upstream in main.

@mwfj mwfj closed this Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI secrets PR fast-path can fallback to full scan when base SHA missing in shallow checkout

1 participant