From 865226822c113dbfa808a0e68146f357d34acfaf Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Wed, 19 May 2021 10:19:19 -0700 Subject: [PATCH] Improve makefile --- .github/workflows/on_push.yml | 12 ++++++------ CONTRIBUTING.md | 8 +++----- Makefile | 23 +++++++++++++++-------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml index 70ad9f37..33d41285 100644 --- a/.github/workflows/on_push.yml +++ b/.github/workflows/on_push.yml @@ -20,7 +20,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: "Pull dependencies" - run: go mod vendor + run: make install-go-modules - name: "Unit tests" run: make test @@ -46,7 +46,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: "Pull dependencies" - run: go mod vendor + run: make install-go-modules - name: "Build binary" env: @@ -70,7 +70,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: "Pull dependencies" - run: go mod vendor + run: make install-go-modules - name: "Unit tests" run: make test @@ -88,7 +88,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: "Pull dependencies" - run: go mod vendor + run: make install-go-modules - name: "Build binary" env: @@ -111,7 +111,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: "Pull dependencies" - run: go mod vendor + run: make install-go-modules - name: "Unit tests" run: make test @@ -129,7 +129,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: "Pull dependencies" - run: go mod vendor + run: make install-go-modules - name: "Build binary" env: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9e7e7039..d2dad85e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,14 +6,12 @@ To contribute to this project please carefully read this document. `wakatime-cli` is written in [Go](https://golang.org/). -**Note:** wakatime-cli uses [Go Modules](https://github.com/golang/go/wiki/Modules) to manage dependencies. - Prerequisites: -- `make` - We use make to build and run tests. +- We use `make` to build and run tests. - [Go 1.16](https://golang.org/doc/install) -After cloning it first run `make test` to make sure everything is properly set. +After cloning, install dependencies with `make install`. ## Branches @@ -24,7 +22,7 @@ This project currently has two branches ## Testing and Linting -Before any commit make sure to always run `make lint` and `make test` consecutively. It guarantees there's no linting error and all tests pass. +Run `make test-all` before creating any pull requests, or your PR won’t pass the automated checks. ## Branching Stratgegy diff --git a/Makefile b/Makefile index 955a2ac4..c02842cb 100644 --- a/Makefile +++ b/Makefile @@ -33,9 +33,9 @@ else endif # targets -build-all: build-all-darwin build-all-freebsd build-all-linux build-all-netbsd build-all-openbsd build-all-windows +build-all: build-darwin build-freebsd build-linux build-netbsd build-openbsd build-windows -build-all-darwin: build-darwin-amd64 build-darwin-arm64 +build-darwin-all: build-darwin-amd64 build-darwin-arm64 build-darwin-amd64: GOOS=darwin GOARCH=amd64 make build-binary @@ -43,7 +43,7 @@ build-darwin-amd64: build-darwin-arm64: GOOS=darwin GOARCH=arm64 make build-binary -build-all-freebsd: build-freebsd-386 build-freebsd-amd64 build-freebsd-arm +build-freebsd: build-freebsd-386 build-freebsd-amd64 build-freebsd-arm build-freebsd-386: GOOS=freebsd GOARCH=386 make build-binary @@ -54,7 +54,7 @@ build-freebsd-amd64: build-freebsd-arm: GOOS=freebsd GOARCH=arm make build-binary -build-all-linux: build-linux-386 build-linux-amd64 build-linux-arm build-linux-arm64 +build-linux: build-linux-386 build-linux-amd64 build-linux-arm build-linux-arm64 build-linux-386: GOOS=linux GOARCH=386 make build-binary @@ -68,7 +68,7 @@ build-linux-arm: build-linux-arm64: GOOS=linux GOARCH=arm64 make build-binary -build-all-netbsd: build-netbsd-386 build-netbsd-amd64 build-netbsd-arm +build-netbsd: build-netbsd-386 build-netbsd-amd64 build-netbsd-arm build-netbsd-386: GOOS=netbsd GOARCH=386 make build-binary @@ -79,7 +79,7 @@ build-netbsd-amd64: build-netbsd-arm: GOOS=netbsd GOARCH=arm make build-binary -build-all-openbsd: build-openbsd-386 build-openbsd-amd64 build-openbsd-arm build-openbsd-arm64 +build-openbsd: build-openbsd-386 build-openbsd-amd64 build-openbsd-arm build-openbsd-arm64 build-openbsd-386: GOOS=openbsd GOARCH=386 make build-binary @@ -93,7 +93,7 @@ build-openbsd-arm: build-openbsd-arm64: GOOS=openbsd GOARCH=arm64 make build-binary -build-all-windows: build-windows-386 build-windows-amd64 +build-windows: build-windows-386 build-windows-amd64 build-windows-386: GOOS=windows GOARCH=386 make build-binary-windows @@ -111,7 +111,8 @@ build-binary-windows: -ldflags "${LD_FLAGS} -X ${REPO}/pkg/version.OS=$(GOOS) -X ${REPO}/pkg/version.Arch=$(GOARCH)" \ -o ${BUILD_DIR}/$(BINARY_NAME)-$(GOOS)-$(GOARCH).exe -# install linter +install: install-go-modules install-linter + .PHONY: install-linter install-linter: ifneq "$(INSTALLED_LINT_VERSION)" "$(LATEST_LINT_VERSION)" @@ -119,6 +120,10 @@ ifneq "$(INSTALLED_LINT_VERSION)" "$(LATEST_LINT_VERSION)" curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin latest endif +.PHONY: install-go-modules +install-go-modules: + go mod vendor + # run static analysis tools, configuration in ./.golangci.yml file .PHONY: lint lint: install-linter @@ -131,3 +136,5 @@ test: .PHONY: test-integration test-integration: go test -race -tags=integration ./main_test.go + +test-all: lint test test-integration