-
Notifications
You must be signed in to change notification settings - Fork 697
fix(ci): improve changed file detection in linter script #8968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ import {existsSync} from 'fs'; | |
| import path from 'path'; | ||
| import {promisify} from 'util'; | ||
| import {ESLint} from 'eslint'; | ||
| import ts from 'typescript'; | ||
| import * as ts from 'typescript'; | ||
|
|
||
| // --- Globals & Promisified API Wrappers --- | ||
| const execFileAsync = promisify(execFile); | ||
|
|
@@ -68,11 +68,28 @@ function runGit(args, options = {}) { | |
| */ | ||
| function getChangedFiles() { | ||
| const base = process.env.GITHUB_BASE_REF || 'main'; | ||
|
|
||
| // Attempt to fetch the base branch and set origin/${base} so it doesn't compare against itself | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to make the script hermetic and have our CI configuration produce the right environment for it to be effective. Can we avoid mutation in the script and have the workflow use |
||
| if (process.env.GITHUB_BASE_REF) { | ||
| try { | ||
| runGit([ | ||
| 'fetch', | ||
| 'origin', | ||
| `+refs/heads/${base}:refs/remotes/origin/${base}`, | ||
| '--depth=1', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
| ]); | ||
| } catch { | ||
| // Continue if network fetch fails or remote does not exist | ||
| } | ||
| } | ||
|
|
||
| const refsToTry = [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be simpler to say:
|
||
| `origin/${base}...HEAD`, | ||
| `${base}...HEAD`, | ||
| `upstream/${base}...HEAD`, | ||
| `origin/${base}`, | ||
| base, | ||
| `upstream/${base}`, | ||
| `origin/${base}`, | ||
| 'FETCH_HEAD', | ||
| 'HEAD~1', | ||
| 'HEAD^', | ||
| ]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if the script is running in CI, it should fail here if GITHUB_BASE_REF isn't set.