Skip to content

Commit

Permalink
Add pre-commit hooks script (#43656)
Browse files Browse the repository at this point in the history
* Add pre-commit script
  • Loading branch information
srnagar authored Jan 13, 2025
1 parent a0d5a20 commit a596a57
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Thank you for your interest in contributing to Azure SDK for Java.

- To make code changes, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the repo, make the change and propose it back by submitting a pull request.

- After cloning the repo, copy the [pre-commit hooks file](https://github.com/Azure/azure-sdk-for-java/tree/main/eng/scripts/pre-commit) (located at `eng/scripts/pre-commit`) to your local `.git/hooks/` directory. This will run some validations before your changes are committed.

- Refer to the [wiki](https://github.com/Azure/azure-sdk-for-java/wiki/Building#testing-for-spotbugs-and-checkstyle-issues) to learn about how Azure SDK for java generates CheckStyle, SpotBugs, Jacoco, and JavaDoc reports.

- There are two Maven projects in the repo. Refer to the [wiki](https://github.com/Azure/azure-sdk-for-java/wiki/Building#pomclientxml-vs-pomdataxml) to learn about project structure for each.
Expand Down
36 changes: 36 additions & 0 deletions eng/scripts/pre-commit
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

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

0 comments on commit a596a57

Please sign in to comment.