From 0d53c086292b5aede7615a7df57f246d751c49af Mon Sep 17 00:00:00 2001 From: Oleg Bespalov Date: Tue, 17 Oct 2023 07:45:57 +0200 Subject: [PATCH 1/2] Update a golangci-lint --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index bbfc0677cf0..b139f507235 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,4 @@ -# v1.54.1 +# v1.54.2 # Please don't remove the first line. It uses in CI to determine the golangci version run: deadline: 5m From 75fb1534733cbad73547cc724d5f9b0818cc8f33 Mon Sep 17 00:00:00 2001 From: Oleg Bespalov Date: Tue, 17 Oct 2023 08:08:46 +0200 Subject: [PATCH 2/2] Removing Makefile's ci-like-lint target --- .github/pull_request_template.md | 2 +- CONTRIBUTING.md | 6 ---- Makefile | 48 ++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index af09dd4b486..72ac5ad3816 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -15,7 +15,7 @@ and code of conduct https://github.com/grafana/k6/blob/master/CODE_OF_CONDUCT.md - [ ] I have performed a self-review of my code. - [ ] I have added tests for my changes. -- [ ] I have run linter locally (`make ci-like-lint`) and all checks pass. +- [ ] I have run linter locally (`make lint`) and all checks pass. - [ ] I have run tests locally (`make tests`) and all tests pass. - [ ] I have commented on my code, particularly in hard-to-understand areas. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ff55ca9e4da..9f9721a4cee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,12 +53,6 @@ We make use of the [golangci-lint](https://github.com/golangci/golangci-lint) to make lint ``` -You can also run the linter inside the docker container, which will benefit from the version of the linter being the same as it will be in CI. - -```bash -make ci-like-lint -``` - #### Running the test suite To exercise the entire test suite, please run the following command diff --git a/Makefile b/Makefile index 03f61b0c4a9..f701f701ccc 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,45 @@ +MAKEFLAGS += --silent GOLANGCI_LINT_VERSION = $(shell head -n 1 .golangci.yml | tr -d '\# ') -TMPDIR ?= /tmp -all: build +all: clean format test build -build : +## build: Builds the 'k6' binary. +build: go build -format : +## format: Applies Go formatting to code. +format: find . -name '*.go' -exec gofmt -s -w {} + -ci-like-lint : - @docker run --rm -t -v $(shell pwd):/app \ - -v $(TMPDIR)/golangci-cache-$(GOLANGCI_LINT_VERSION):/golangci-cache \ - --env "GOLANGCI_LINT_CACHE=/golangci-cache" \ - -w /app golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) \ - make lint +## check-linter-version: Checks if the linter version is the same as the one specified in the linter config. +check-linter-version: + (golangci-lint version | grep "version $(shell head -n 1 .golangci.yml | tr -d '\# ')") || echo "Your installation of golangci-lint is different from the one that is specified in k6's linter config (there it's $(shell head -n 1 .golangci.yml | tr -d '\# ')). Results could be different in the CI." -lint : +## lint: Runs the linters. +lint: check-linter-version + echo "Running linters..." golangci-lint run --out-format=tab --new-from-rev master ./... -tests : +## tests: Executes any unit tests. +tests: go test -race -timeout 210s ./... -check : ci-like-lint tests - -.PHONY: build format ci-like-lint lint tests check +## check: Runs the linters and tests. +check: lint tests + +## help: Prints a list of available build targets. +help: + echo "Usage: make ... " + echo "" + echo "Available targets are:" + echo '' + sed -n 's/^##//p' ${PWD}/Makefile | column -t -s ':' | sed -e 's/^/ /' + echo + echo "Targets run by default are: `sed -n 's/^all: //p' ./Makefile | sed -e 's/ /, /g' | sed -e 's/\(.*\), /\1, and /'`" + +## clean: Removes any previously created build artifacts. +clean: + @echo "cleaning" + rm -f ./k6 + +.PHONY: build format lint tests check check-linter-version help