-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add pre-commit hooks script #43656
Merged
Merged
Add pre-commit hooks script #43656
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aab2c85
Update core version to trigger precommit hook
srnagar e8ebd69
Add pre-commit script
srnagar e2cdad6
include cspell checks
srnagar ec43156
include cspell checks
srnagar 04277bc
testing credscanner
srnagar 81f38da
testing pre-commit hooks
srnagar 5ca9ec7
testing pre-commit hooks
srnagar 9244bfe
test pre-commit hook
srnagar 87b4033
test pre-commit hook
srnagar b8e7f88
test pre-commit hook
srnagar 20a7175
test pre-commit hook
srnagar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/sh | ||
|
||
# Fail on first error | ||
set -e | ||
|
||
# Get the list of changed files | ||
changed_files=$(git diff --cached --name-only) | ||
|
||
# Cred Scanner | ||
|
||
# Setting up Cred Scanner Pre-Commit Git Hook locally requires installing Guardian and running the | ||
# initialization first before the pre-commit hook can actually be used. | ||
# https://eng.ms/docs/products/credential-risk-exposure-defense/solutions/credentials_in_code/precommit-git-hook | ||
srnagar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if [[ "${CredScanBinDirPosix}" ]]; then | ||
echo "########### Running credential scanner ###########" | ||
"${CredScanBinDirPosix}/CredScanGitHook" -r "${PWD}" | ||
else | ||
echo "To enable credential scanner pre-commit hook, follow the instructions here - https://eng.ms/docs/products/credential-risk-exposure-defense/solutions/credentials_in_code/precommit-git-hook" | ||
fi | ||
|
||
# Spell Check | ||
echo "########### Running spell check ###########" | ||
exec echo $changed_files | npx cspell --no-summary --no-progress --no-must-find-files --file-list stdin | ||
echo "Spell check completed successfully" | ||
|
||
# Validate library versions | ||
echo "########### Validating package versions ###########" | ||
pwsh eng/versioning/pom_file_version_scanner.ps1 | ||
echo "Package versions validation completed successfully" | ||
|
||
# Verify links | ||
echo "########### Validating links ###########" | ||
for file in $changed_files; do | ||
pwsh eng/common/scripts/Verify-Links.ps1 $file | ||
done |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@srnagar can you give more context on this? In general we have avoided git hooks because they are very fragile and cannot be relied on. From all our other trials they have caused more problems than they have helped.
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.
This was a MQ task. More details on this can be found in this issue - #41715
The main reason was to ensure we did some basic validation like cred scanner and spell checks done before the changes are committed as these are more sensitive and don't want it to be part of commit history. This PR only contains a script and doesn't automatically enable pre-commit hooks for everyone. It is an opt-in feature.
Could you please let me know what were some of the problems this caused in the past?
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.
There are a number of issues:
We have tried to use these in .NET and JS repos in the past and they both decided to revert using them because of a lot of issues. I also have had nothing but issues with these in my past teams as well which is why I don't recommend them.
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.
Just to close the loop on this, we discussed this in the Java team meeting and will keep the script (with some improvements) in the
eng/scripts
directory. This will not automatically be used and will allow users of the repo to opt in to using this, if needed. If we run into issues, it's easy to opt out.