Skip to content

Commit 70637cf

Browse files
schuellerfmvo5
authored andcommitted
Makefile,github: implement make lint and centralize GOLANGCI_LINT_VERSION
1 parent ecaaa37 commit 70637cf

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ on:
1313

1414
env:
1515
GO_VERSION: 1.22
16-
# see https://golangci-lint.run/product/changelog
17-
# to select a version that supports the GO_VERSION given above
18-
GOLANGCI_LINT_VERSION: v2.0.2
1916

2017
concurrency:
2118
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -44,10 +41,14 @@ jobs:
4441
- name: Install libgpgme devel package
4542
run: sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
4643

44+
- name: Extract golangci-lint version from Makefile
45+
id: golangci_lint_version
46+
run: echo "GOLANGCI_LINT_VERSION=$(awk -F '=' '/^GOLANGCI_LINT_VERSION *=/{print $2}' Makefile)" >> "$GITHUB_OUTPUT"
47+
4748
- name: Run golangci-lint
4849
uses: golangci/golangci-lint-action@v7
4950
with:
50-
version: ${{ env.GOLANGCI_LINT_VERSION }}
51+
version: ${{ steps.golangci_lint_version.outputs.GOLANGCI_LINT_VERSION }}
5152
args: --timeout 5m0s
5253
working-directory: bib
5354

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
.PHONY: all
22
all: build-binary build-container
33

4+
GOLANGCI_LINT_VERSION=v2.0.2
5+
GO_BINARY?=go
6+
7+
# the fallback '|| echo "golangci-lint' really expects this file
8+
# NOT to exist! This is just a trigger to help installing golangci-lint
9+
GOLANGCI_LINT_BIN=$(shell which golangci-lint 2>/dev/null || echo "golangci-lint")
10+
411
.PHONY: help
512
help:
613
@echo 'Usage:'
@@ -45,3 +52,14 @@ push-check: build-binary build-container test ## run all checks and tests befor
4552
exit 1; \
4653
fi
4754
@echo "All looks good - congratulations"
55+
56+
$(GOLANGCI_LINT_BIN):
57+
@echo "golangci-lint does not seem to be installed"
58+
@read -p "Press <ENTER> to install it or <CTRL>-c to abort"
59+
$(GO_BINARY) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) || \
60+
( echo "if the go version is a problem, you can set GO_BINARY e.g. GO_BINARY=go.1.23.8 \
61+
after installing it e.g. go install golang.org/dl/go1.23.8@latest" ; exit 1 )
62+
63+
.PHONY: lint
64+
lint: $(GOLANGCI_LINT_BIN) ## run the linters to check for bad code
65+
cd bib && $(GOLANGCI_LINT_BIN) run

0 commit comments

Comments
 (0)