Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce make lint #4228

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/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:
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
5 changes: 5 additions & 0 deletions Containerfile_golangci_lint
Original file line number Diff line number Diff line change
@@ -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
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/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 changes: 17 additions & 0 deletions tools/apt-install-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
Loading