Skip to content

Commit f8c29ab

Browse files
committed
Add golangci-lint infra for code quality checks
This adds linting support using golangci-lint v1.64.8 via containerized execution, matching the approach used in ovn-kubernetes. Includes a Makefile with lint and lint-fix targets, a GitHub Actions workflow for automated PR checks, and the necessary hack/lint.sh script. This work was patterned mostly from what is in ovn-kubernetes/ovn-kubernetes.git except that the github actions will now use 'make lint' instead of a github marketplace action so that the lint in CI will match exactly what a dev would do locally Assisted-by: Claude Code Signed-off-by: Jamo Luhrsen <jluhrsen@gmail.com>
1 parent f5622ca commit f8c29ab

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

.github/workflows/lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
lint:
14+
name: Lint
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v4
19+
20+
- name: Run lint
21+
run: make lint

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# CONTAINER_RUNNABLE determines if the tests can be run inside a container. It checks to see if
2+
# podman/docker is installed on the system.
3+
PODMAN ?= $(shell podman -v > /dev/null 2>&1; echo $$?)
4+
ifeq ($(PODMAN), 0)
5+
CONTAINER_RUNTIME?=podman
6+
else
7+
CONTAINER_RUNTIME?=docker
8+
endif
9+
CONTAINER_RUNNABLE ?= $(shell $(CONTAINER_RUNTIME) -v > /dev/null 2>&1; echo $$?)
10+
11+
.PHONY: lint
12+
lint:
13+
ifeq ($(CONTAINER_RUNNABLE), 0)
14+
@GOPATH=${GOPATH} ./hack/lint.sh $(CONTAINER_RUNTIME) || { echo "lint failed! Try running 'make lint-fix'"; exit 1; }
15+
else
16+
echo "linter can only be run within a container since it needs a specific golangci-lint version"; exit 1
17+
endif
18+
19+
.PHONY: lint-fix
20+
lint-fix:
21+
ifeq ($(CONTAINER_RUNNABLE), 0)
22+
@GOPATH=${GOPATH} ./hack/lint.sh $(CONTAINER_RUNTIME) fix || { echo "ERROR: lint fix failed! There is a bug that changes file ownership to root \
23+
when this happens. To fix it, simply run 'chown -R <user>:<group> *' from the repo root."; exit 1; }
24+
else
25+
echo "linter can only be run within a container since it needs a specific golangci-lint version"; exit 1
26+
endif

hack/lint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
VERSION=v1.64.8
3+
extra_flags=""
4+
if [ "$#" -ne 1 ]; then
5+
if [ "$#" -eq 2 ] && [ "$2" == "fix" ]; then
6+
extra_flags="--fix"
7+
else
8+
echo "Expected command line argument - container runtime (docker/podman) got $# arguments: $@"
9+
exit 1
10+
fi
11+
fi
12+
13+
# Create cache directory if it doesn't exist
14+
mkdir -p ${HOME}/.cache/golangci-lint
15+
16+
$1 run --security-opt label=disable --rm \
17+
-v ${HOME}/.cache/golangci-lint:/cache -e GOLANGCI_LINT_CACHE=/cache \
18+
-v $(pwd):/app -w /app -e GO111MODULE=on docker.io/golangci/golangci-lint:${VERSION} \
19+
golangci-lint run --verbose --print-resources-usage \
20+
--modules-download-mode=vendor --timeout=15m0s ${extra_flags} && \
21+
echo "lint OK!"

0 commit comments

Comments
 (0)