diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cc5805df3efd..329fd846eddf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/eng/scripts/pre-commit b/eng/scripts/pre-commit new file mode 100644 index 000000000000..adfb445ed95e --- /dev/null +++ b/eng/scripts/pre-commit @@ -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