-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
103 lines (87 loc) · 2.88 KB
/
Copy pathMakefile
File metadata and controls
103 lines (87 loc) · 2.88 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2026 Robin Jarry
PWFORGE_VERSION ?= $(shell git describe --long --abbrev=8 --dirty 2>/dev/null || echo v0.1.0)
DATE_FMT = +%Y-%m-%d
ifdef SOURCE_DATE_EPOCH
DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || \
date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || \
date -u "$(DATE_FMT)")
else
DATE ?= $(shell date "$(DATE_FMT)")
endif
GO ?= go
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
GO_LDFLAGS += -X main.Version=$(PWFORGE_VERSION)
GO_LDFLAGS += -X main.Date=$(DATE)
V ?= 0
ifeq ($V,1)
Q =
else
Q = @
endif
.PHONY: all
all: pwforge
.PHONY: clean
clean:
rm -f pwforge
.PHONY: install
install: $(DESTDIR)$(BINDIR)/pwforge
go_src = $(shell git ls-files '*.go') go.mod go.sum
pwforge: $(go_src)
$(GO) build -trimpath -ldflags "$(GO_LDFLAGS)" -o $@ ./cmd/pwforge
$(DESTDIR)$(BINDIR)/pwforge: pwforge
install -D -m 0755 $< $@
import_reviser ?= github.com/incu6us/goimports-reviser/v3@v3.12.6
import_reviser_flags ?= -rm-unused -project-name github.com/getpatchwork/pwforge
gofumpt ?= mvdan.cc/gofumpt@v0.9.2
golangci_lint ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2
license_exclude = ':!:*.md' ':!:*.asc' ':!:LICENSE' ':!:.*' ':!:go.mod' ':!:go.sum' ':!:local'
.PHONY: local
local:
./local/run.sh
.PHONY: lint
lint:
@echo '[goimports-reviser]'
$Q ! $(GO) run $(import_reviser) $(import_reviser_flags) -list-diff -output stdout ./... | grep . || { \
echo 'error: above files need import sorting'; \
exit 1; \
}
@echo '[gofumpt]'
$Q ! $(GO) run $(gofumpt) -d . | grep ^diff || { \
echo 'error: above files need reformatting'; \
exit 1; \
}
@echo '[golangci-lint]'
@$(GO) run $(golangci_lint) run
@echo '[license-check]'
$Q ! git --no-pager grep -LF 'SPDX-License-Identifier: Apache-2.0' -- $(license_exclude) || { \
echo 'error: above files are missing license'; \
exit 1; \
}
$Q ! git --no-pager grep -LF 'Copyright ' -- $(license_exclude) || { \
echo 'error: above files are missing copyright notice'; \
exit 1; \
}
@echo '[white-space]'
$Q git ls-files | xargs devtools/check-whitespace
@echo '[codespell]'
$Q codespell *
.PHONY: format
format:
$(GO) run $(import_reviser) $(import_reviser_flags) ./...
$(GO) run $(gofumpt) -w .
REVISION_RANGE ?= @{u}..
.PHONY: check-commits
check-commits:
$Q devtools/check-patches $(REVISION_RANGE)
.PHONY: tag-release
tag-release:
@cur_version=`sed -En 's/PWFORGE_VERSION .* \|\| echo v([0-9].*)\>\)$$/\1/p' Makefile` && \
next_version=`echo $$cur_version | awk -F. -v OFS=. '{$$(NF) += 1; print}'` && \
read -rp "next version ($$next_version)? " n && \
if [ -n "$$n" ]; then next_version="$$n"; fi && \
set -xe && \
sed -i "s/\<v$$cur_version\>/v$$next_version/" Makefile && \
git commit -sm "pwforge: release v$$next_version" -m "`git shortlog -sn v$$cur_version..`" Makefile && \
git tag -sm "v$$next_version" "v$$next_version"