You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2025-06-17] [$500] package.json scripts: lint-changed runs on extraneous files #62656
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Version Number: NA Reproducible in staging?: NA Reproducible in production?: NA If this was caught during regression testing, add the test name, ID and link from TestRail: NA Email or phone of affected tester (no customers): NA Logs: NA Expensify/Expensify Issue URL: NA Issue reported by: Slack conversation (hyperlinked to channel name): NA
The inner git diff that runs computes what files that the lint will be performed on. $(git diff --diff-filter=AM --name-only origin/main HEAD -- "*.ts" "*.tsx")
This computes the typescript files that were added or modified that differ on the HEAD of the main
branch and current branch (we call dev).
This is not a problem when the main branch is behind the dev branch, i.e.
at the point of branch main does not have any new commits added to it.
But as other branches get merged into main the HEAD of main moves forward,
so this diff will return the files that have been changed on the dev branch and on the main branch since the branching point. At the time of writing I saw
298 different files.
This finds the common ancestor of origin/main and our current development branch.
So only changes that were made on the development branch will be considered when
performing the lint-changed script.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
N/A
What alternative solutions did you explore? (Optional)
Because this issue affects the workflow.
You could create a merge commit with origin/main like:
- name: Run ESLint to check for deprecation warnings
run: |
# This will just fetch the latest commit from main
git fetch origin main --no-tags --depth=1
# Merge and commit a dummy commit.
git merge origin/main --no-commit
git commit -m "github actions: workflow merge main to run lint."
# shellcheck disable=SC2046
npm run lint-changed
This may address the issue of long lint-jobs, but only for the GitHub Action and wouldn't
affect local development.
Rather than undertaking a coordinated migration of all our withOnyx usages to its successor useOnyx, let's instead introduce a new PR check in our CI such that if you modify a file that uses withOnyx, the CI will fail on your PR, regardless of whether you introduced that usage. This way, we'll force an incremental migration as files are changed without putting in a large upfront investment. This low-urgency incremental migration matches the urgency of the problem.
The intention was only on files you changed in the PR, not all files that have
been changed on main since the PR was last merged with main.
@sonialiap Apologies for opening an issue directly on GitHub, but I don't have access to slack channel so I wanted to bring this issue to the Expensify team's attention.
Thank you for your contribution. You have the right idea here and have correctly identified the bug, but your suggested fix will not work. Because we only do a shallow clone of main, there is almost certainly not enough history to identify the merge base, so git merge-base origin/main HEAD will return nothing. To fix this, we need to either remove the --depth flag on fetching main or change the value to some arbitrarily-large number. GH insights say there have been ~2500 commits in the last month so let's set depth to 30000. That should be more than enough to get the relevant history for a PR without getting the entire history.
@MacroLens I'm going to assign you, and provide some guidance here regarding what I am looking to see in the PR:
You'll have to go back a few commits when you check out your branch so there are relevant files changed in main, that you did not touch in your branch, that are failing lint checks. You should then edit a relevant file on your branch so that it has failing lint checks and submit a PR with your changes.
Then make the change to the script here. We should still see your file failing checks but the others from main should now be excluded.
We need to ensure that if git merge-base ever returns empty string, that causes the check to fail. Similarly, if git diff returns an error, that must also cause the check to fail. I'm not sure how easy it will be to do this directly in package.json and keep it readable, so it may be necessary to move the check to its own script.
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Activity
melvin-bot commentedon May 23, 2025
📣 @MacroLens! 📣
Please report bugs or suggest features in the #expensify-open-source Slack channel, don't directly open issues in this repo!
Instructions here to join the channel 📖
melvin-bot commentedon May 23, 2025
Triggered auto assignment to @sonialiap (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.MacroLens commentedon May 23, 2025
I haven't been added to the slack channel, so I posted this here to give visibility to the issue.
MacroLens commentedon May 23, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
npm run lint-changedlints extraneous files leading to long lint workflowruntimes and lint errors for unchanged files.
What is the root cause of that problem?
In the package.json
is the
lint-changed scriptApp/package.json
Line 49 in d17b700
The inner
git diffthat runs computes what files that the lint will be performed on.$(git diff --diff-filter=AM --name-only origin/main HEAD -- "*.ts" "*.tsx")This computes the typescript files that were added or modified that differ on the HEAD of the main
branch and current branch (we call dev).
This is not a problem when the main branch is behind the dev branch, i.e.
at the point of branch main does not have any new commits added to it.
But as other branches get merged into main the HEAD of main moves forward,
so this diff will return the files that have been changed on the dev branch
and on the main branch since the branching point. At the time of writing I saw
298 different files.
So the lint-changed script will run on multiple files that were not changed
on the dev branch.
This affects the workflow:
App/.github/workflows/lint-changed.yml
Lines 29 to 35 in d17b700
Running the steps for reproduction on my local resulting in a lint job taking:
and 65 lint errors (at time of writing, may change as HEAD moves in main).
If you apply the workaround by merging to main first:
What changes do you think we should make in order to solve the problem?
Rather than running:
in the package.json.
We should be running:
This finds the common ancestor of origin/main and our current development branch.
So only changes that were made on the development branch will be considered when
performing the
lint-changedscript.What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
N/A
What alternative solutions did you explore? (Optional)
Because this issue affects the workflow.
You could create a merge commit with origin/main like:
This may address the issue of long lint-jobs, but only for the GitHub Action and wouldn't
affect local development.
This bug was introduced in #49102
with its corresponding PR #49165 (review).
The intention was given in the issue:
The intention was only on files you changed in the PR, not all files that have
been changed on main since the PR was last merged with main.
MacroLens commentedon May 23, 2025
@sonialiap Apologies for opening an issue directly on GitHub, but I don't have access to slack channel so I wanted to bring this issue to the Expensify team's attention.
sonialiap commentedon May 26, 2025
Thanks @MacroLens!
sonialiap commentedon May 26, 2025
Brought up to the team
rafecolton commentedon May 27, 2025
Looking
rafecolton commentedon May 27, 2025
Thank you for your contribution. You have the right idea here and have correctly identified the bug, but your suggested fix will not work. Because we only do a shallow clone of main, there is almost certainly not enough history to identify the merge base, so
git merge-base origin/main HEADwill return nothing. To fix this, we need to either remove the--depthflag on fetching main or change the value to some arbitrarily-large number. GH insights say there have been ~2500 commits in the last month so let's set depth to 30000. That should be more than enough to get the relevant history for a PR without getting the entire history.@MacroLens I'm going to assign you, and provide some guidance here regarding what I am looking to see in the PR:
git merge-baseever returns empty string, that causes the check to fail. Similarly, ifgit diffreturns an error, that must also cause the check to fail. I'm not sure how easy it will be to do this directly inpackage.jsonand keep it readable, so it may be necessary to move the check to its own script.Let me know if you have any questions.
53 remaining items
melvin-bot commentedon Jun 17, 2025
Payment Summary
Upwork Job
BugZero Checklist (@garrettmknight)
sonialiap commentedon Jun 17, 2025
@rafecolton looks like you and Rory reviewed the PR, no C+ on this one, is that correct? (Asking for payment processing)
sonialiap commentedon Jun 17, 2025
Payment summary:
sonialiap commentedon Jun 17, 2025
Noting that we don't need a regression test #62656 (comment)
rafecolton commentedon Jun 17, 2025
Correct
sonialiap commentedon Jun 20, 2025
Closing as paid