From 515f67625448b11ec4693228f0882f6da32fe80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=BCller?= Date: Tue, 25 Jun 2024 12:17:11 +0200 Subject: [PATCH] makefile: implement make lint --- .github/workflows/tests.yml | 23 ++++++----------------- .gitignore | 2 ++ Containerfile_golangci_lint | 5 +++++ Makefile | 19 ++++++++++++++++++- tools/apt-install-deps.sh | 17 +++++++++++++++++ 5 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 Containerfile_golangci_lint create mode 100755 tools/apt-install-deps.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 467bb68eea..e4b4278a6e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -122,28 +122,17 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Apt update - run: sudo apt-get update - - # 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 dependencies + run: sudo tools/apt-install-deps.sh - - 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: diff --git a/.gitignore b/.gitignore index a899a7e1d5..f4cc59761d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ __pycache__ /tools/appsre-ansible/inventory /docs/osbuild-composer.7 +.cache +container_composer_golangci_built.info diff --git a/Containerfile_golangci_lint b/Containerfile_golangci_lint new file mode 100644 index 0000000000..18c975df89 --- /dev/null +++ b/Containerfile_golangci_lint @@ -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 diff --git a/Makefile b/Makefile index 7ecb2e8de4..ffec336ddb 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/tools/apt-install-deps.sh b/tools/apt-install-deps.sh new file mode 100755 index 0000000000..b1db420f6a --- /dev/null +++ b/tools/apt-install-deps.sh @@ -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