From d6a711f140ee7878ada2098fd7c4dd3bc2fc75e9 Mon Sep 17 00:00:00 2001 From: Tero Saarni Date: Sat, 26 Oct 2024 22:12:05 +0300 Subject: [PATCH] Replace golangci-lint action --- .github/actions/golangci-lint/action.yaml | 18 ++++++++++++++++++ .github/actions/golangci-lint/matcher.json | 17 +++++++++++++++++ .github/workflows/unit-test.yml | 12 +----------- .gitignore | 2 +- .golangci.yaml | 14 ++++++++++++++ Makefile | 11 ++++------- 6 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 .github/actions/golangci-lint/action.yaml create mode 100644 .github/actions/golangci-lint/matcher.json create mode 100644 .golangci.yaml diff --git a/.github/actions/golangci-lint/action.yaml b/.github/actions/golangci-lint/action.yaml new file mode 100644 index 0000000..9afbb68 --- /dev/null +++ b/.github/actions/golangci-lint/action.yaml @@ -0,0 +1,18 @@ +# This action runs golangci-lint using Makefile. +# It ensures the same version of golangci-lint is used in CI as in local development. +name: golangci-lint +description: 'Run golangci-lint' +inputs: + working-directory: + description: 'Working directory' + required: false + default: '.' +runs: + using: 'composite' + steps: + - name: Run golangci-lint + run: | + echo "::add-matcher::${{ inputs.working-directory }}/.github/actions/golangci-lint/matcher.json" + make lint + echo "::remove-matcher owner=golangci-lint::" + shell: bash diff --git a/.github/actions/golangci-lint/matcher.json b/.github/actions/golangci-lint/matcher.json new file mode 100644 index 0000000..e6c5ac7 --- /dev/null +++ b/.github/actions/golangci-lint/matcher.json @@ -0,0 +1,17 @@ +{ + "problemMatcher": [ + { + "owner": "golangci-lint-colored-line-number", + "severity": "error", + "pattern": [ + { + "regexp": "^([^:]+):(\\d+):(?:(\\d+):)?\\s+(.+ \\(.+\\))$", + "file": 1, + "line": 2, + "column": 3, + "message": 4 + } + ] + } + ] +} diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 674aa16..908e48a 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -21,18 +21,8 @@ jobs: go-version: "stable" id: go - - name: Get dependencies - run: | - go get -v -t -d ./... - - # https://github.com/golangci/golangci-lint-action - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.61.0 - # Workaround for "file exists" errors while running tar. - # golangci-lint-action conflicts with caching in setup-go - skip-pkg-cache: true + uses: ./.github/actions/golangci-lint - name: Build run: make build diff --git a/.gitignore b/.gitignore index 8839b2a..63f02cc 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ # Local History for Visual Studio Code .history/ -./certyaml +certyaml diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..2bdfa9b --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,14 @@ +linters: +# https://golangci-lint.run/usage/linters/#enabled-by-default + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + - gosec + - gofmt + - goimports + - misspell + - revive diff --git a/Makefile b/Makefile index 36f9941..2d317c3 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ all: check build +check: test lint + test: go test --race -v ./... -check: test - golangci-lint run - gosec -quiet ./... +lint: + go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 run build: go build -v ./cmd/certyaml @@ -13,9 +14,5 @@ build: install: go install -v ./cmd/certyaml -install-tools: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 - go install github.com/securego/gosec/v2/cmd/gosec@v2.18.2 - update-modules: go get -u -t ./... && go mod tidy