Skip to content
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

[V2] chore: add pre-commit and pre-push validation #1487

Merged
merged 5 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[codespell]
skip=./.git,./.github/workflows/codespell.yml,.git,*.png,*.jpg,*.svg,*.sum,./vendor,go.sum,crd-csi-snapshot-ga.yaml,crd-csi-snapshot.yaml
ignore-words-list=AKS,aks,ro
check-filenames=
4 changes: 0 additions & 4 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: codespell-project/actions-codespell@master
with:
check_filenames: true
skip: ./.git,./.github/workflows/codespell.yml,.git,*.png,*.jpg,*.svg,*.sum,./vendor,go.sum,crd-csi-snapshot-ga.yaml,crd-csi-snapshot.yaml
ignore_words_list: "AKS,aks,ro"
107 changes: 107 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "vendor/"
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.32.1
hooks:
- id: commitizen
stages: [ commit-msg ]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.1
hooks:
- id: codespell
stages: [ commit ]
- repo: local
hooks:
- id: verify-gofmt
name: Verify Go Formatting
entry: ./hack/verify-gofmt.sh
types: [ go ]
exclude: '^vendor/'
pass_filenames: false
language: system
stages: [ commit ]
- id: verify-govet
name: Vet Go Code
entry: ./hack/verify-govet.sh
types: [ go ]
exclude: '^vendor/'
pass_filenames: false
language: system
stages: [ commit ]
- id: verify-gomod
name: Verify Go Modules
entry: ./hack/verify-gomod.sh
types: [ file ]
files: '(^vendor/)|(^go.mod)|(^go.sum)|\.go'
pass_filenames: false
require_serial: true
fail_fast: true
language: system
stages: [ commit ]
- id: verify-codegen
name: Verify Go Code Generation
entry: ./hack/verify-codegen.sh
types: [ file ]
files: '^pkg/api/'
pass_filenames: false
require_serial: true
fail_fast: true
language: system
stages: [ commit ]
- id: verify-crd
name: Verify Custom Resource Generation
entry: ./hack/verify-gocrd.sh
types: [ file ]
files: '^pkg/api/(azuredisk|config)/'
pass_filenames: false
require_serial: true
fail_fast: true
language: system
stages: [ commit ]
- id: verify-yamllint
name: Lint YAML Files
entry: ./hack/verify-yamllint.sh
types: [ yaml ]
exclude: '^vendor/'
pass_filenames: false
fail_fast: true
language: system
stages: [ commit ]
- id: verify-boilerplate
name: Verify File Boilerplate
entry: ./hack/verify-boilerplate.sh
types: [ go, makefile, python, shell ]
exclude: '^vendor/'
pass_filenames: false
language: system
stages: [ commit ]
- id: verify-helm-chart-files
name: Verify Helm Chart Files
entry: ./hack/verify-helm-chart-files.sh
types: [ file ]
files: '^charts/'
pass_filenames: false
require_serial: true
language: system
stages: [ commit ]
- id: verify-helm-chart
name: Verify Helm Chart
entry: ./hack/verify-helm-chart.sh
types: [ file ]
files: '^charts/'
pass_filenames: false
require_serial: true
language: system
stages: [ commit ]
- id: unit-test
name: Run Unit Tests
entry: "make unit-test"
types: [go]
files: '^pkg/|^test/utils/credentials'
pass_filenames: false
fail_fast: true
require_serial: true
language: system
stages: [ push ]
11 changes: 11 additions & 0 deletions docs/csi-dev.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# Azure disk CSI driver development guide

## Prerequisites

- [Install Python 3](https://www.python.org/about/gettingstarted/)
- [Install pip](https://pip.pypa.io/en/stable/installation/)
- [Install pre-commit](https://pre-commit.com/#install)

## How to build this project
- Clone repo
```console
$ mkdir -p $GOPATH/src/sigs.k8s.io/
$ git clone https://github.com/kubernetes-sigs/azuredisk-csi-driver $GOPATH/src/sigs.k8s.io/azuredisk-csi-driver
```

- Setup repo
```console
$ pre-commit install -t pre-commit -t commit-msg -t pre-push
```

- Build CSI driver
Expand Down
46 changes: 35 additions & 11 deletions hack/verify-helm-chart-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,52 @@

set -euo pipefail

# Returns true iff the current user is root.
is_root_user() {
[ "${EUID:-$(id -u)}" -eq 0 ];
}

# Installs Helm (must be run as root)
install_helm() {
local install_helm_script

install_helm_script=$(cat <<EOF
apt-key add hack/helm-signing.asc
apt-get install apt-transport-https --yes
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | tee /etc/apt/sources.list.d/helm-stable-debian.list
apt-get update
apt-get install helm
EOF
)

if is_root_user; then
bash -c "$install_helm_script"
else
sudo -E -H bash -c "$install_helm_script"
fi
}

echo "begin to verify chart tgz files ..."
git config core.filemode false

# verify whether chart config has changed
diff=`git diff`
diff=$(git diff)
if [[ -n "${diff}" ]]; then
echo "${diff}"
exit 1
fi

for dir in charts/*
do
if [ -d $dir ]; then
if [ -f $dir/*.tgz ]; then
if [ -d "$dir" ]; then
if [ -f "$dir/*.tgz" ]; then
echo "verify $dir ..."
tar -xvf $dir/*.tgz -C $dir/
tar -xvf "$dir/*.tgz" -C "$dir/"
fi
fi
done

diff=`git diff`
diff=$(git diff)
if [[ -n "${diff}" ]]; then
echo
echo
Expand All @@ -49,12 +74,11 @@ fi
echo "chart tgz files verified."

echo "verify helm chart index ..."
echo "install helm ..."
apt-key add hack/helm-signing.asc
apt-get install apt-transport-https --yes
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | tee /etc/apt/sources.list.d/helm-stable-debian.list
apt-get update
apt-get install helm

if [[ -z "$(command -v helm)" ]]; then
echo "install helm ..."
install_helm
fi

helm repo add azuredisk-csi-driver https://raw.githubusercontent.com/kubernetes-sigs/azuredisk-csi-driver/master/charts
helm search repo -l azuredisk-csi-driver
Expand Down