Skip to content
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
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ format: format-web format-go ## Format all source code
# Setup
# ====================================================================================

.PHONY: setup
setup: setup-hooks
cd web && npm install
make build-web
make build-go

.PHONY: setup-hooks
setup-hooks: ## Set up git hooks
cp ./scripts/pre-commit .git/hooks/
chmod +x .git/hooks/pre-commit
@HOOK_DIR=$$(git rev-parse --git-path hooks); \
PRE_COMMIT_HOOK="$$HOOK_DIR/pre-commit"; \
mkdir -p "$$HOOK_DIR"; \
printf '%s\n' '#!/bin/sh' 'cd "$$(git rev-parse --show-toplevel)"' 'exec make pre-commit' > "$$PRE_COMMIT_HOOK"; \
chmod +x "$$PRE_COMMIT_HOOK"

# ====================================================================================
# Utils
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ For more details, try [Getting started](/docs/en/tutorial/getting-started.md).
e.g. `git clone https://github.com/GoogleCloudPlatform/khi.git`
1. Move to the project root
e.g. `cd khi`
1. Run `cd ./web && npm install` from the project root
1. Run `make setup` from the project root
(This make target install npm packages, generate some auto generated code and setup git hooks)

#### Build KHI from source and run

1. [Authorize yourself with `gcloud`](https://cloud.google.com/docs/authentication/gcloud)
e.g. `gcloud auth login` if you use your user account credentials
1. Run `make build-web && KHI_FRONTEND_ASSET_FOLDER=./pkg/server/dist go run cmd/kubernetes-history-inspector/main.go` from the project root
Open `localhost:8080` and start working with KHI!
1. Run `make build`
1. Run the generated executable with `./khi`
1. Open `localhost:8080` and start working with KHI!

</details>

Expand Down
8 changes: 2 additions & 6 deletions docs/en/development-contribution/development-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ You can't create a new branch our repository directly. Please fork our repositor
Please check [this document](https://docs.github.com/en/authentication/managing-commit-signature-verification) to make sure your commits are signed.
Our repository can't accept unsigned commits.

### Setup Git hook
## About the Git hooks

Run the following shell command to setup Git hook. It runs format or lint codes before commiting changes.

```shell
make setup-hooks
```
The `make setup` make target installs git hooks to your local repository. This hook automatically checks license header existence, formats code, and runs linters before your commit. It will reduce the possibility for you to face CI failure with simple format errors.

### Setup VSCode config

Expand Down
8 changes: 2 additions & 6 deletions docs/ja/development-contribution/development-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ READMEの[ソースから実行](/README.ja.md#ソースから実行) の手順

[こちらのドキュメント](https://docs.github.com/en/authentication/managing-commit-signature-verification) の手順に沿って、コミットに署名を付与するように設定してください。コミット署名なしのコミットは受付できません。

### Git hookの設定
### Git フックについて

下記のシェルコマンドを実行してGit hookを設定してください。下記の設定が完了すると、コミットする前にフォーマットやリントをチェックするコードが実行されます。

```shell
make setup-hooks
```
`make setup`によって実行されるMakeターゲットにより、gitのフックをインストールします。このフックはライセンスヘッダの有無、コードの自動フォーマット、linterの実行をコミット前に自動的に行います。これにより、PRのレビュー申請後に簡単なフォーマット等のミスでCIの失敗を引き起こす可能性が低くなります。

### VSCodeの設定

Expand Down
2 changes: 1 addition & 1 deletion scripts/make/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build-go-debug: generate-backend ## Build backend for debugging
CGO_ENABLED=0 go build -gcflags="all=-N -l" -ldflags="-X github.com/GoogleCloudPlatform/khi/pkg/common/constants.VERSION=$(shell cat ./VERSION)" -o ./khi-debug ./cmd/kubernetes-history-inspector/...

.PHONY: build
build: build-go build-web ## Build all source code
build: build-web build-go ## Build all source code

define build_binary
CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -ldflags="-s -w -X github.com/GoogleCloudPlatform/khi/pkg/common/constants.VERSION=$(shell cat ./VERSION)" -o ./bin/khi-$(1)-$(2)$(3) ./cmd/kubernetes-history-inspector/...
Expand Down
12 changes: 12 additions & 0 deletions scripts/make/hooks.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

.PHONY: pre-commit
pre-commit: ## Run pre-commit checks (internal)
@scripts_files=$$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g'); \
if [ -n "$$scripts_files" ]; then \
$(MAKE) add-licenses && \
$(MAKE) format && \
$(MAKE) lint && \
$(MAKE) lint-markdown-fix && \
$(MAKE) lint-markdown && \
echo "$$scripts_files" | xargs git add; \
fi
Comment thread
kyasbal marked this conversation as resolved.
17 changes: 0 additions & 17 deletions scripts/pre-commit

This file was deleted.