Skip to content

fix(ci): improve changed file detection in linter script - #8968

Open
shivanee-p wants to merge 6 commits into
mainfrom
shivaneep-linter-diff-logic
Open

fix(ci): improve changed file detection in linter script#8968
shivanee-p wants to merge 6 commits into
mainfrom
shivaneep-linter-diff-logic

Conversation

@shivanee-p

@shivanee-p shivanee-p commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fixes an issue where ./bin/linter.mjs skipped TypeScript checks in CI pull request workflows because it's incorrectly detecting no TS file changes.

It looks like the CI was comparing "head" to "head". It was running git diff FETCH_HEAD -- *.ts, but we need to fetch from origin before doing that. Previously, the linter was going in order of the refsToTry array to check which reference existed in order to diff against it:

  1. main, upstream/main, and origin/main failed
  2. 'FETCH_HEAD', existed and pointed to the checked-out PR commit (HEAD).
  3. Running git diff --name-only FETCH_HEAD -- *.ts compared HEAD against itself, which succeeded with an exit code of 0 and returned an empty file list ("")

Fix

  • When running in CI (process.env.GITHUB_BASE_REF is defined), execute git fetch origin ${base} --depth=1 to ensure origin/${base} exists locally.
  • Prioritize triple-dot references (origin/${base}...HEAD, ${base}...HEAD, etc.) to diff from the common ancestor between the target branch and the feature branch.
  • Removed 'FETCH_HEAD' from candidate refs to prevent Git from comparing HEAD to itself in shallow single-ref checkouts.

Verification

Simulated CI environment on branch test-pr-8966 (GITHUB_BASE_REF=main):

@shivanee-p
shivanee-p requested a review from a team as a code owner July 24, 2026 22:13

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the linter script to fetch the base branch when running in a GitHub Actions environment and refactors the list of Git references used to determine changed files. The reviewer suggested using an explicit refspec in the git fetch command to ensure the remote-tracking branch is correctly created and updated in shallow-clone CI environments.

Comment thread bin/linter.mjs Outdated
@shivanee-p
shivanee-p force-pushed the shivaneep-linter-diff-logic branch from a449965 to 2a57889 Compare July 24, 2026 22:18
@shivanee-p

Copy link
Copy Markdown
Contributor Author

/gemini

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Hello! It looks like you've invoked me to help with this pull request. Since you didn't specify a command, I've provided a summary of your changes below.

Pull Request Summary: fix(ci): improve changed file detection in linter script

This PR addresses a critical issue in bin/linter.mjs where the linter was failing to detect changed TypeScript files in CI environments.

Key Changes:

  • Explicit Fetching: Added logic to fetch the base branch (origin/${base}) with --depth=1 when running in CI. This ensures the remote reference is available locally for comparison.
  • Improved Diff Strategy: Updated refsToTry to prioritize triple-dot (...) diffs, which correctly identify the common ancestor between the target branch and the feature branch.
  • Cleanup: Removed FETCH_HEAD from the candidate references to prevent the linter from accidentally comparing HEAD against itself in shallow clones.

These changes should significantly improve the reliability of your CI linter checks. If you would like a detailed code review, please feel free to run /gemini review.

@shivanee-p
shivanee-p requested review from a team as code owners July 27, 2026 17:31
@shivanee-p
shivanee-p removed request for a team July 27, 2026 17:36
@shivanee-p
shivanee-p force-pushed the shivaneep-linter-diff-logic branch from c69d6c6 to d0f8a21 Compare July 27, 2026 17:41
@shivanee-p
shivanee-p force-pushed the shivaneep-linter-diff-logic branch from 88c3e97 to ee44be0 Compare July 27, 2026 17:44
@shivanee-p
shivanee-p requested a review from a team as a code owner July 27, 2026 17:44
@shivanee-p
shivanee-p requested review from a team as code owners July 27, 2026 17:53
@shivanee-p
shivanee-p force-pushed the shivaneep-linter-diff-logic branch from 76b0942 to 480b5d0 Compare July 27, 2026 17:59
@shivanee-p
shivanee-p requested review from danieljbruce and removed request for a team July 27, 2026 18:01
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.

1 participant