Skip to content

fix: fetch full history when cognitive complexity is enabled - #535

Merged
marcossevilla merged 4 commits into
mainfrom
fix/cognitive-complexity-fetch-depth
Oct 19, 2026
Merged

marcossevilla merged 4 commits into
mainfrom
fix/cognitive-complexity-fetch-depth

Conversation

@marcossevilla

@marcossevilla marcossevilla commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Status

READY

Description

Closes #532

#533 set the checkout depth with ${{ inputs.run_cognitive_complexity && 0 || 1 }}. GitHub expressions treat 0 as falsy, so true && 0 gives 0, 0 || 1 gives 1, and the clone is always shallow. Because of that, the cognitive complexity step still fails with Failed to resolve merge base for "origin/main" on v2.0.2. See https://github.com/VeryGoodOpenSource/very_good_cli/actions/runs/39242537795: it used 4bee65e with run_cognitive_complexity: true, but the checkout ran with fetch-depth: 1.

This computes the depth once in a job-level FETCH_DEPTH env var and has the single checkout step read it, in both dart_package.yml and flutter_package.yml:

env:
  FETCH_DEPTH: ${{inputs.run_cognitive_complexity && '0' || '1'}}

The values are string literals because the string '0' is truthy in expressions while the number 0 is not, so a full-history clone is used when cognitive complexity is enabled.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

The checkout expression `inputs.run_cognitive_complexity && 0 || 1` always evaluates to `1` because `0` is falsy in GitHub expressions, so the clone stayed shallow and the cognitive complexity step still failed to resolve a merge base. Negate the condition so the truthy branch is non-zero.
@marcossevilla

Copy link
Copy Markdown
Member Author

Validated in VeryGoodOpenSource/very_good_cli#1755 by pointing flutter_package.yml at this branch (e16a65b): https://github.com/VeryGoodOpenSource/very_good_cli/actions/runs/39244068580

  • build (ubuntu-latest) (run_cognitive_complexity: true): checkout ran with fetch-depth: 0, the action fetched origin/main, the scanner ran with --git-diff=origin/main, and it reported "Run is clean" ✅
  • build (windows-latest) (run_cognitive_complexity: false): checkout stayed at fetch-depth: 1 ✅

For comparison, v2.0.2 ran with fetch-depth: 1 and failed to resolve a merge base: https://github.com/VeryGoodOpenSource/very_good_cli/actions/runs/39242537795

Comment thread .github/workflows/dart_package.yml Outdated
Gate full-history and shallow checkouts with step-level `if:` instead of
computing fetch-depth from the toggle, keeping enable/disable logic separate
from clone depth as suggested in review.
Replace the two if-gated checkout steps with a single checkout that reads
a job-level FETCH_DEPTH. String literals keep '0' truthy so the full-history
branch is actually taken.
@marcossevilla
marcossevilla merged commit 92a940e into main Oct 19, 2026
16 checks passed
@marcossevilla
marcossevilla deleted the fix/cognitive-complexity-fetch-depth branch October 19, 2026 13:46
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in VGV Open Source 🦄 🧙🌟 Oct 19, 2026
@vgvbot vgvbot mentioned this pull request Oct 19, 2026
marcossevilla added a commit to VeryGoodOpenSource/very_good_cli that referenced this pull request Oct 19, 2026
v2.0.3 includes the fetch-depth fix (VeryGoodOpenSource/very_good_workflows#535), so the temporary pin to the PR branch is no longer needed.
marcossevilla added a commit to VeryGoodOpenSource/very_good_cli that referenced this pull request Oct 19, 2026
* ci: run cognitive complexity audit from very_good_workflows#520

* ci: temporarily force a full cognitive complexity scan

* ci: run the build matrix without fail-fast

* fix: address review feedback on PR #1755

Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com>

* fix: address review feedback on PR #1755

Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com>

* fix: address review feedback on PR #1755

Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com>

* chore: apply suggestion

* ci: migrate remaining workflows to very_good_workflows@v2

Pin every reusable workflow to @v2, drop run_bloc_lint (false is the v2 default), and remove the HEAD diff base, which diffed the checkout against itself and made the complexity scan a no-op. The scan now runs only on the ubuntu matrix leg so both jobs do not race on the sticky PR comment.

* ci: fail on cognitive complexity increases

Block pull requests that make an existing function more complex relative to the base branch, in addition to the absolute threshold.

* fix: address review feedback on PR #1755

Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com>

* ci: run cognitive complexity through very_good_workflows

very_good_workflows v2.0.2 checks out full history when run_cognitive_complexity is enabled (VeryGoodOpenSource/very_good_workflows#532), so the dedicated job with its own fetch-depth: 0 checkout is no longer needed.

* ci: temporarily validate very_good_workflows#535

Points the build at the PR branch to confirm the fetch-depth fix lets the cognitive complexity step resolve a merge base. Revert to @v2 once the fix is released.

* ci: re-validate very_good_workflows#535

* ci: use very_good_workflows@v2 for cognitive complexity

v2.0.3 includes the fetch-depth fix (VeryGoodOpenSource/very_good_workflows#535), so the temporary pin to the PR branch is no longer needed.

---------

Co-authored-by: unicoderbot[bot] <269805761+unicoderbot[bot]@users.noreply.github.com>
Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix: cognitive complexity fails to resolve merge base due to shallow checkout

2 participants