Skip to content

Commit

Permalink
makefile: implement make lint
Browse files Browse the repository at this point in the history
  • Loading branch information
schuellerf committed Jun 25, 2024
1 parent d1b9c19 commit 8a21b62
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
23 changes: 6 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/install_golangci_lint_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.59.1
version: ${{ steps.golangci_lint_version.outputs.GOLANGCI_LINT_VERSION }}
args: --verbose --timeout 5m0s

packit-config-lint:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ __pycache__
/tools/appsre-ansible/inventory

/docs/osbuild-composer.7
.cache
container_composer_golangci_built.info
6 changes: 6 additions & 0 deletions Containerfile_golangci_lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG GOLANGCI_LINT_VERSION
FROM docker.io/golangci/golangci-lint:${GOLANGCI_LINT_VERSION}

COPY tools/install_golangci_lint_deps.sh /usr/local/bin/.
RUN /usr/local/bin/install_golangci_lint_deps.sh

19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -82,13 +87,16 @@ 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 "$@"

$(BUILDDIR)/%/:
mkdir -p "$@"

$(GOLANGCI_LINT_CACHE_DIR):
mkdir -p "$@"
#
# Documentation
#
Expand Down Expand Up @@ -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/*
Expand Down Expand Up @@ -275,3 +284,11 @@ scratch: $(RPM_SPECFILE) $(RPM_TARBALL)
--nocheck \
$(RPM_SPECFILE)

container_composer_golangci_built.info: Makefile Containerfile_golangci_lint tools/install_golangci_lint_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 changes: 17 additions & 0 deletions tools/install_golangci_lint_deps.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8a21b62

Please sign in to comment.