-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (76 loc) · 2.66 KB
/
Makefile
File metadata and controls
85 lines (76 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
.PHONY: help build test lint clean fmt lint-only dev-tag
# Docker image versions
GOLANGCI_LINT_VERSION := v2.7.0
# Default target
help:
@echo "Available targets:"
@echo " build - Build the application"
@echo " test - Run tests"
@echo " lint - Format code and run golangci-lint"
@echo " fmt - Format code using golangci-lint"
@echo " lint-only - Run golangci-lint without formatting"
@echo " clean - Clean build artifacts"
@echo " dev-tag - Generate dev tag for Docker image"
# Build the application
build:
@echo "Building ghcr-exporter..."
@VERSION=$$(git describe --tags --always --dirty 2>/dev/null || echo "dev") && \
COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") && \
BUILD_DATE=$$(date -u +"%Y-%m-%dT%H:%M:%SZ") && \
go build -v -ldflags="-s -w \
-X ghcr-exporter/internal/version.Version=$$VERSION \
-X ghcr-exporter/internal/version.Commit=$$COMMIT \
-X ghcr-exporter/internal/version.BuildDate=$$BUILD_DATE" \
-o ghcr-exporter ./cmd
# Run tests
test:
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... || true
# Format code using golangci-lint formatters (faster than separate tools)
fmt:
docker run --rm \
-u "$(shell id -u):$(shell id -g)" \
-e GOCACHE=/tmp/go-cache \
-e GOLANGCI_LINT_CACHE=/tmp/golangci-lint-cache \
-v "$(PWD):/app" \
-v "$(HOME)/.cache:/tmp/cache" \
-w /app \
golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) \
golangci-lint run --fix
# Run golangci-lint (formats first, then lints)
lint:
docker run --rm \
-u "$(shell id -u):$(shell id -g)" \
-e GOCACHE=/tmp/go-cache \
-e GOLANGCI_LINT_CACHE=/tmp/golangci-lint-cache \
-v "$(PWD):/app" \
-v "$(HOME)/.cache:/tmp/cache" \
-w /app \
golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) \
golangci-lint run --fix
# Run only linting without formatting
lint-only:
docker run --rm \
-u "$(shell id -u):$(shell id -g)" \
-e GOCACHE=/tmp/go-cache \
-e GOLANGCI_LINT_CACHE=/tmp/golangci-lint-cache \
-v "$(PWD):/app" \
-v "$(HOME)/.cache:/tmp/cache" \
-w /app \
golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) \
golangci-lint run
# Clean build artifacts
clean:
rm -f ghcr-exporter coverage.txt
# Generate dev tag for Docker image
dev-tag:
@SHORT_SHA=$$(git rev-parse --short HEAD 2>/dev/null || echo "unknown"); \
LAST_TAG=$$(git describe --tags --abbrev=0 --match="v[0-9]*.[0-9]*.[0-9]*" 2>/dev/null || echo ""); \
if [ -z "$$LAST_TAG" ]; then \
VERSION="0.0.0"; \
COMMIT_COUNT=$$(git rev-list --count HEAD); \
else \
VERSION=$${LAST_TAG#v}; \
COMMIT_COUNT=$$(git rev-list --count $${LAST_TAG}..HEAD); \
fi; \
DEV_TAG="v$${VERSION}-dev.$${COMMIT_COUNT}.$${SHORT_SHA}"; \
echo "$$DEV_TAG"