From 43a799e958d47ad6d22279a31bd8cb59df8baa15 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Tue, 1 Oct 2024 00:51:49 -0400 Subject: [PATCH] fix: pre-commit hook --- .pre-commit-config.yaml | 10 ++++++---- Makefile | 5 ++++- README.md | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 01432ca..f28e4da 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,10 +14,6 @@ repos: rev: 0.2.3 hooks: - id: yamlfmt - - repo: https://github.com/Bahjat/pre-commit-golang - rev: v1.0.3 - hooks: - - id: gofumpt - repo: https://github.com/dnephin/pre-commit-golang rev: v0.5.1 hooks: @@ -31,7 +27,13 @@ repos: name: make build entry: make build language: system + always_run: true + stages: [commit] + pass_filenames: false - id: make-test name: make test entry: make test language: system + always_run: true + stages: [commit] + pass_filenames: false diff --git a/Makefile b/Makefile index f54d3c0..34513ee 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,13 @@ BUILD_DIR = ./build TMP_DIR = ./tmp APPS := $(notdir $(wildcard ./cmd/*)) -FLAGS := "-s -w" +VERSION := $(shell git rev-parse --short HEAD) +FLAGS := "-s -w -X main.Version=$(VERSION)" all: build build: + echo 'make build' $(foreach APP,$(APPS), go build -ldflags=$(FLAGS) -o $(BUILD_DIR)/$(APP) ./cmd/$(APP);) clean: @@ -22,6 +24,7 @@ prepare-test: git submodule update --init --remote test: + echo 'make test' ./scripts/prepare_test_repos.sh $(TMP_DIR) go test -coverprofile cover.out -v ./... diff --git a/README.md b/README.md index d532d4b..940de84 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ ok github.com/joint-online-judge/JOJ3/cmd/joj3 2.290s coverage: 74.0% of ### For developers -1. Install [`pre-commit`](https://pre-commit.com/), [`golangci-lint`](https://golangci-lint.run), [`goimports`](https://golang.org/x/tools/cmd/goimports), [`gofumpt`](https://github.com/mvdan/gofumpt). +1. Install [`pre-commit`](https://pre-commit.com/), [`golangci-lint`](https://golangci-lint.run). 2. Install the pre-commit hooks. It will run some checks before you commit.