-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
146 lines (127 loc) · 4.57 KB
/
Copy pathMakefile
File metadata and controls
146 lines (127 loc) · 4.57 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Patchwork - automated patch tracking system
# Copyright (C) The Patchwork Contributors (see CONTRIBUTORS)
#
# SPDX-License-Identifier: GPL-2.0-or-later
PATCHWORK_VERSION ?= $(shell git describe --long --abbrev=8 --dirty 2>/dev/null || echo v4.0.0-rc3)
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
V ?= 0
ifeq ($V,1)
Q =
else
Q = @
endif
GO_LDFLAGS += -X main.Version=$(PATCHWORK_VERSION)
GO_LDFLAGS += -X main.Date=$(DATE)
.PHONY: all
all: pw
src = $(shell git ls-files ':!:*_templ.go' '*.go' '*.css' '*.templ')
pw: $(src)
$(GO) generate ./...
$(GO) build -trimpath -ldflags "$(GO_LDFLAGS)" -o pw ./cmd/pw
prefix ?= /usr
sysconfdir ?= /etc
unitdir ?= $(prefix)/lib/systemd/system
datadir ?= $(prefix)/share
.PHONY: install
install: pw
install -Dm755 pw $(DESTDIR)$(prefix)/bin/pw
install -Dm644 etc/pw-http.service $(DESTDIR)$(unitdir)/pw-http.service
install -Dm644 etc/pw-ingress.service $(DESTDIR)$(unitdir)/pw-ingress.service
install -Dm644 etc/pw.bash-completion $(DESTDIR)$(datadir)/bash-completion/completions/pw
$(DESTDIR)$(prefix)/bin/pw config > $(DESTDIR)$(sysconfdir)/patchwork.toml
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(prefix)/bin/pw
rm -f $(DESTDIR)$(unitdir)/pw-http.service
rm -f $(DESTDIR)$(unitdir)/pw-ingress.service
rm -f $(DESTDIR)$(datadir)/bash-completion/completions/pw
rm -f $(DESTDIR)$(sysconfdir)/patchwork.toml
PYTHON ?= python3
.PHONY: docs
docs:
$Q if ! [ -x docs/.venv/bin/sphinx-build ]; then \
set -xe && \
$(PYTHON) -m venv docs/.venv && \
docs/.venv/bin/pip install -q -r docs/requirements.txt; \
fi
docs/.venv/bin/sphinx-build --builder html --isolated \
-Dextensions=reno.sphinxext \
-Dproject=Patchwork \
-Dcopyright="The Patchwork Contributors" \
-Dauthor="The Patchwork Contributors" \
-Dversion="$(PATCHWORK_VERSION)" \
-Drelease="$(PATCHWORK_VERSION)" \
-Dtoday="$(DATE)" \
-Dexclude_patterns=_build,.venv \
-Dhtml_theme=sphinx_rtd_theme \
docs docs/_build
import_reviser ?= github.com/incu6us/goimports-reviser/v3@v3.12.6
import_reviser_flags ?= -rm-unused -project-name github.com/getpatchwork/patchwork
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' ':!:*.yaml' ':!:docs/requirements.txt' ':!:*.service' ':!:CONTRIBUTORS' ':!:LICENSE' ':!:.*' ':!:go.mod' ':!:go.sum' ':!:pkg/mail/testdata'
.PHONY: test
test:
$(GO) generate ./...
$(GO) test ./...
.PHONY: lint
lint:
$(GO) generate ./...
@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: GPL-2.0-or-later' -- $(license_exclude) || { \
echo 'error: above files are missing license'; \
exit 1; \
}
$Q ! git --no-pager grep -LF 'Copyright (C) The Patchwork Contributors' -- $(license_exclude) || { \
echo 'error: above files are missing copyright notice'; \
exit 1; \
}
@echo '[white-space]'
$Q git ls-files ':!:pkg/mail/testdata' | 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-patches
check-patches:
$Q devtools/check-patches $(REVISION_RANGE)
.PHONY: git-config
git-config:
git config format.subjectPrefix "PATCH patchwork"
git config sendemail.to "patchwork@lists.ozlabs.org"
@mkdir -p .git/hooks
@rm -f .git/hooks/commit-msg*
ln -s ../../devtools/commit-msg .git/hooks/commit-msg
.PHONY: tag-release
tag-release:
@cur_version=`sed -En 's/PATCHWORK_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 "patchwork: release v$$next_version" -m "`devtools/git-stats v$$cur_version..`" Makefile && \
git tag -sm "`devtools/git-stats v$$cur_version..HEAD^`" "v$$next_version"