From 74b69581ed36217e3702b080496f1e0979b6c012 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Wed, 27 Sep 2023 20:14:32 +0100 Subject: [PATCH] (chore): Add linter improvements Signed-off-by: Camila Macedo --- .github/workflows/lint.yml | 20 ++++++++++++++++++++ .golangci.yml | 3 +++ .jobserv.yml | 8 -------- Makefile | 23 ++++++++++++++++++----- 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..3f6e468e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,20 @@ +name: Lint +on: + push: + pull_request: + +jobs: + lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '~1.19' + - name: Clone the code + uses: actions/checkout@v4 + - name: Run linter + uses: golangci/golangci-lint-action@v3 + with: + version: v1.51.2 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..eb4ff13e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,3 @@ +run: + deadline: 5m + allow-parallel-runners: true diff --git a/.jobserv.yml b/.jobserv.yml index f4952541..5d8df7c0 100644 --- a/.jobserv.yml +++ b/.jobserv.yml @@ -1,13 +1,5 @@ timeout: 30 triggers: - - name: pull-request - type: github_pr - runs: - - name: unit-test - container: golangci/golangci-lint:v1.51.2 - host-tag: amd64 - script: unit-test - - name: create-release type: git_poller params: diff --git a/Makefile b/Makefile index 8ba1a593..0b39c703 100644 --- a/Makefile +++ b/Makefile @@ -24,13 +24,26 @@ fioctl-%: go build $(LDFLAGS) -o bin/$@ main.go @if [ "$@" = "fioctl-windows-amd64" ]; then mv bin/$@ bin/$@.exe; fi -format: - @gofmt -l -w ./ -check: - @test -z $(shell gofmt -l ./ | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make format'" - @test -x $(linter) || (echo "Please install linter from https://github.com/golangci/golangci-lint/releases/tag/v1.51.2 to $(HOME)/go/bin") +install-linter: + echo "[WARN] Installing golangci binary version v1.51.2 at $(HOME)/go/bin/golangci-lint" + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(linter)) v1.51.2 + +has-linter: + @test -x $(linter) || (echo '[ERROR] Please install go linter using "make install-linter"' && exit 1) + +linter-check: has-linter $(linter) run +linter-fix: has-linter + echo "[WARN] Attempting to automatically fix some linter issues." + $(linter) run --fix + +format-check: + @test -z $(shell gofmt -l ./ | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make format-check'" + +check: format-check linter-check + @true + # Use the image for Dockerfile.build to build and install the tool. container-init: docker build -t fioctl-build -f Dockerfile.build .