diff --git a/Makefile b/Makefile index 2c31d5cde..5b84e976a 100644 --- a/Makefile +++ b/Makefile @@ -113,6 +113,9 @@ generate-kiota: go run ./hack/validate-imports pkg/util/graph/graphsdk go run ./hack/licenses -dirs ./pkg/util/graph/graphsdk +init-contrib: + cp -R hack/git/hooks/* .git/hooks/ + image-aro-multistage: docker build --platform=linux/amd64 --network=host --no-cache -f Dockerfile.aro-multistage -t $(ARO_IMAGE) --build-arg REGISTRY=$(REGISTRY) . @@ -270,4 +273,4 @@ vendor: install-go-tools: go install ${GOTESTSUM} -.PHONY: admin.kubeconfig aks.kubeconfig aro az ci-portal clean client deploy dev-config.yaml discoverycache generate image-aro-multistage image-fluentbit image-proxy lint-go runlocal-rp proxy publish-image-aro-multistage publish-image-fluentbit publish-image-proxy secrets secrets-update e2e.test tunnel test-e2e test-go test-python vendor build-all validate-go unit-test-go coverage-go validate-fips install-go-tools \ No newline at end of file +.PHONY: admin.kubeconfig aks.kubeconfig aro az ci-portal clean client deploy dev-config.yaml discoverycache generate image-aro-multistage image-fluentbit image-proxy init-contrib lint-go runlocal-rp proxy publish-image-aro-multistage publish-image-fluentbit publish-image-proxy secrets secrets-update e2e.test tunnel test-e2e test-go test-python vendor build-all validate-go unit-test-go coverage-go validate-fips install-go-tools \ No newline at end of file diff --git a/README.md b/README.md index 5b0a959e9..901ac516a 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,13 @@ you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. +Before you start development, please set up your local git hooks to conform to our +development standards: + +```bash +make init-contrib +``` + When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need diff --git a/docs/prepare-your-dev-environment.md b/docs/prepare-your-dev-environment.md index 68b3ef9d2..cba63ee6d 100644 --- a/docs/prepare-your-dev-environment.md +++ b/docs/prepare-your-dev-environment.md @@ -138,3 +138,9 @@ Make sure that `PKG_CONFIG_PATH` contains the pkgconfig files of the above packa ```bash cd ${GOPATH:-$HOME/go}/src/github.com/Azure/ARO-RP ``` + +1. Add standard git hooks + + ```bash + make init-contrib + ``` diff --git a/hack/git/hooks/pre-commit b/hack/git/hooks/pre-commit new file mode 100644 index 000000000..1b5751697 --- /dev/null +++ b/hack/git/hooks/pre-commit @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -e +LC_ALL=C + +git_username_lower="$(git config github.user | tr '[:upper:]' '[:lower:]')" +if [[ -z "${git_username_lower}" ]] +then + echo "Please set github.user (git config github.user) locally or globally before issuing commits to this repo." + exit 1 +fi + +# e.g. "USERNAME/ARO-1234", "USERNAME/hotfix-v20240321.00", or "USERNAME/gh-issue-123" +valid_branch_regex="^${git_username_lower}\/(ARO-[0-9]{4}[a-z0-9._-]*|hotfix-[a-z0-9._-]+|gh-issue-[0-9]+[a-z0-9._-]*)$" + +local_branch="$(git rev-parse --abbrev-ref HEAD)" + +if [[ ! $local_branch =~ $valid_branch_regex ]] +then + echo "There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. Please rename your branch (git branch --move) to a valid name and try again." + exit 1 +fi + +exit 0 \ No newline at end of file