-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
Only run the pre-commit hook on changed files #3145
Only run the pre-commit hook on changed files #3145
Conversation
9f49185
to
4d6bb71
Compare
167c928
to
8264e7c
Compare
8264e7c
to
a8d928d
Compare
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.
Nice! Thank you!
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.
Does --from-ref origin/master
(or similar using github.base_ref
) work? If so, I think it might be better to use that for pr, and for merged commit, we can use HEAD^
.
I believe the current 3rd party GitHub action does a simple compare to the branch we are merging to. I guess it could just get tricky with all possible enumerations of which commit to count towards the change list. Pre-commit itself even suggested the following: Really what I was going for is anything new, we want to make sure we try to keep formatted. And didn't want to try to cover everything. |
I mean, if pre-commit supports target branch names like origin/master for
IMO, if pre-commit already supports the feature, it'd be better not to introduce more dependency (which will be maintenance burden). |
The docs I was reading, didn't use a specific ref like
Definitely agree, I will try some other experiments when I can |
Using an external action to grab all changed files, and pass that to the pre-commit check to reduce false-negatives.
NOTES:
Alternatively, could pass the arguments:
pre-commit ... --from-ref HEAD^ --to-ref HEAD
to run the action on the last commit. However, will only capture a single commit, even if the branch received multiple commits on a push.I'm not even sure this
get-diff-action
will even do what I expect.TESTING NOTES:
get-diff
action compares the PR to main branch so this will always be the case)GIT_DIFF
variable to pass files appropriately to pre-commit - doneThis seems to work as expected I refactored a bit to skip the pre-commit hook if there are no hs files in the changelog. (not that it saves any time).
This should enable us to be green for pre-commit check