makefile: implement make lint

This commit is contained in:
Florian Schüller 2024-06-25 12:17:11 +02:00 committed by Florian Schüller
parent 786f44e7e7
commit c36367d4cc
5 changed files with 48 additions and 18 deletions

View file

@ -122,28 +122,17 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Apt update
run: sudo apt-get update
- name: Install dependencies
run: sudo tools/apt-install-deps.sh
# This is needed to lint internal/upload/koji package
- name: Install kerberos devel package
run: sudo apt-get install -y libkrb5-dev
# This is needed for the container upload dependencies
- name: Install libgpgme devel package
run: sudo apt-get install -y libgpgme-dev
# This is needed for the 'github.com/containers/storage' package
- name: Install btrfs-progs devel package
run: sudo apt-get install -y libbtrfs-dev
- name: Install libdevmapper devel package
run: sudo apt-get install -y libdevmapper-dev
- name: Extract golangci-lint version from Makefile
id: golangci_lint_version
run: echo "GOLANGCI_LINT_VERSION=$(awk -F '=' '/^GOLANGCI_LINT_VERSION *=/{print $2}' Makefile)" >> "$GITHUB_OUTPUT"
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.54.2
version: ${{ steps.golangci_lint_version.outputs.GOLANGCI_LINT_VERSION }}
args: --verbose --timeout 5m0s
packit-config-lint:

2
.gitignore vendored
View file

@ -13,3 +13,5 @@ __pycache__
/tools/appsre-ansible/inventory
/docs/osbuild-composer.7
.cache
container_composer_golangci_built.info

View file

@ -0,0 +1,5 @@
ARG GOLANGCI_LINT_VERSION
FROM docker.io/golangci/golangci-lint:${GOLANGCI_LINT_VERSION}
COPY tools/apt-install-deps.sh /usr/local/bin/.
RUN /usr/local/bin/apt-install-deps.sh

View file

@ -19,6 +19,11 @@ SRCDIR ?= .
RST2MAN ?= rst2man
# v1.55 to get golang 1.21 (1.21.3)
# v1.53 to get golang 1.20 (1.20.5)
GOLANGCI_LINT_VERSION=v1.53
GOLANGCI_LINT_CACHE_DIR=$(HOME)/.cache/golangci-lint/$(GOLANGCI_LINT_VERSION)
GOLANGCI_COMPOSER_IMAGE=composer_golangci
#
# Automatic Variables
#
@ -82,6 +87,7 @@ help:
@echo " unit-tests: Run unit tests"
@echo " push-check: Replicates the github workflow checks as close as possible"
@echo " (do this before pushing!)"
@echo " lint: Runs linters as close as github workflow as possible"
$(BUILDDIR)/:
mkdir -p "$@"
@ -89,6 +95,8 @@ $(BUILDDIR)/:
$(BUILDDIR)/%/:
mkdir -p "$@"
$(GOLANGCI_LINT_CACHE_DIR):
mkdir -p "$@"
#
# Documentation
#
@ -156,9 +164,10 @@ install: build
clean:
rm -rf $(BUILDDIR)/bin/
rm -rf $(CURDIR)/rpmbuild
rm -rf container_composer_golangci_built.info
.PHONY: push-check
push-check: build unit-tests srpm man
push-check: lint build unit-tests srpm man
./tools/check-runners
./tools/check-snapshots --errors-only .
rpmlint --config rpmlint.config $(CURDIR)/rpmbuild/SRPMS/*
@ -275,3 +284,11 @@ scratch: $(RPM_SPECFILE) $(RPM_TARBALL)
--nocheck \
$(RPM_SPECFILE)
container_composer_golangci_built.info: Makefile Containerfile_golangci_lint tools/apt-install-deps.sh
podman build -f Containerfile_golangci_lint -t $(GOLANGCI_COMPOSER_IMAGE) --build-arg "GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION)"
echo "Image last built on" > $@
date >> $@
.PHONY: lint
lint: $(GOLANGCI_LINT_CACHE_DIR) container_composer_golangci_built.info
podman run -t --rm -v $(SRCDIR):/app:z -v $(GOLANGCI_LINT_CACHE_DIR):/root/.cache:z -w /app $(GOLANGCI_COMPOSER_IMAGE) golangci-lint run -v

17
tools/apt-install-deps.sh Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# just a warning - as "sudo" is not in the container we are using
echo "This script should be run as root"
apt-get update
# This is needed to lint internal/upload/koji package
apt-get install -y libkrb5-dev
# This is needed for the container upload dependencies
apt-get install -y libgpgme-dev
# This is needed for the 'github.com/containers/storage' package
apt-get install -y libbtrfs-dev
apt-get install -y libdevmapper-dev