-
Notifications
You must be signed in to change notification settings - Fork 628
Expand file tree
/
Copy pathMakefile
More file actions
195 lines (161 loc) · 5.61 KB
/
Makefile
File metadata and controls
195 lines (161 loc) · 5.61 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
GO?=go
GOOS=$(shell ${GO} env GOOS)
GOARCH=$(shell ${GO} env GOARCH)
GOLANGCI_LINT_VERSION=$(shell awk '/GOLANGCI_LINT_VERSION:/ { print $$2 }' .github/workflows/main.yml)
GORELEASER_VERSION=$(shell awk '/GORELEASER_VERSION:/ { print $$2 }' .github/workflows/main.yml)
SYFT_VERSION=$(shell awk '/SYFT_VERSION:/ { print $$2 }' .github/workflows/main.yml)
UPSTREAM=$(shell git remote -v | awk '/github.com[:\/]twpayne\/chezmoi(.git)? \(fetch\)/ {print $$1}')
ifdef VERSION
GO_LDFLAGS+=-X main.version=${VERSION}
endif
ifdef COMMIT
GO_LDFLAGS+=-X main.commit=${COMMIT}
endif
ifdef DATE
GO_LDFLAGS+=-X main.date=${DATE}
endif
ifdef BUILT_BY
GO_LDFLAGS+=-X main.builtBy=${BUILT_BY}
endif
PREFIX?=/usr/local
.PHONY: default
default: build
.PHONY: smoke-test
smoke-test: run build-all test lint format
.PHONY: build
build:
ifeq (${GO_LDFLAGS},)
${GO} build . || ( rm -f chezmoi ; false )
else
${GO} build -ldflags "${GO_LDFLAGS}" . || ( rm -f chezmoi ; false )
endif
.PHONY: install
install: build
mkdir -p "${DESTDIR}${PREFIX}/bin"
install -m 755 --target-directory "${DESTDIR}${PREFIX}/bin" chezmoi
.PHONY: install-from-git-working-copy
install-from-git-working-copy:
${GO} install -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags) \
-X main.commit=$(shell git rev-parse HEAD) \
-X main.date=$(shell git show -s --format=%ct HEAD) \
-X main.builtBy=source"
.PHONY: build-in-git-working-copy
build-in-git-working-copy:
${GO} build -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags) \
-X main.commit=$(shell git rev-parse HEAD) \
-X main.date=$(shell git show -s --format=%ct HEAD) \
-X main.builtBy=source"
.PHONY: build-all
build-all: build-darwin build-freebsd build-linux build-windows
.PHONY: build-darwin
build-darwin:
GOOS=darwin GOARCH=amd64 ${GO} build -o /dev/null .
GOOS=darwin GOARCH=arm64 ${GO} build -o /dev/null .
.PHONY: build-freebsd
build-freebsd:
GOOS=freebsd GOARCH=amd64 ${GO} build -o /dev/null .
.PHONY: build-linux
build-linux:
GOOS=linux GOARCH=amd64 ${GO} build -o /dev/null .
GOOS=linux GOARCH=amd64 ${GO} build -tags=noupgrade -o /dev/null .
.PHONY: build-windows
build-windows: create-syso
GOOS=windows GOARCH=amd64 ${GO} build -o /dev/null .
.PHONY: run
run:
${GO} tool chezmoi --version
.PHONY: test-all
test-all: test test-release rm-dist test-docker test-vagrant
.PHONY: rm-dist
rm-dist:
rm -rf dist
.PHONY: test
test:
${GO} test -ldflags="-X chezmoi.io/chezmoi/internal/chezmoitest.umaskStr=0o022" ./...
${GO} test -ldflags="-X chezmoi.io/chezmoi/internal/chezmoitest.umaskStr=0o002" ./...
.PHONY: test-docker
test-docker:
( cd assets/docker && ./test.sh alpine archlinux fedora )
.PHONY: test-vagrant
test-vagrant:
( cd assets/vagrant && ./test.sh freebsd14 )
.PHONY: coverage-html
coverage-html: coverage
${GO} tool cover -html=coverage.out
.PHONY: coverage
coverage:
${GO} test -coverprofile=coverage.out -coverpkg=chezmoi.io/chezmoi/... ./...
.PHONY: capslock
capslock:
${GO} tool capslock -output=package > .config/capslock-summary.json
.PHONY: lint
lint: ensure-golangci-lint shellcheck
${GO} tool actionlint
${GO} tool editorconfig-checker -config=.config/editorconfig-checker.json
./bin/golangci-lint run --config=.config/golangci.yml
${GO} tool lint-whitespace
find . -name \*.txtar | xargs ${GO} tool lint-txtar
${GO} tool find-typos chezmoi .
${GO} tool lint-commit-messages ${UPSTREAM}/master..HEAD
.PHONY: lint-markdown
lint-markdown:
markdownlint-cli2 --config=.config/markdownlint-cli2.yaml --strict-config
.PHONY: format
format: ensure-golangci-lint
./bin/golangci-lint fmt
find . -name \*.txtar | xargs ${GO} tool lint-txtar -w
.PHONY: format-yaml
format-yaml:
find . -name \*.yaml -o -name \*.yml | xargs uv run task format-yaml
.PHONY: create-syso
create-syso:
${GO} tool execute-template -output ./versioninfo.json ./assets/templates/versioninfo.json.tmpl
${GO} tool goversioninfo -platform-specific
.PHONY: ensure-tools
ensure-tools: \
ensure-golangci-lint \
ensure-goreleaser \
ensure-syft
.PHONY: ensure-golangci-lint
ensure-golangci-lint:
if [ ! -x bin/golangci-lint ] || ( ./bin/golangci-lint version | grep -Fqv "version ${GOLANGCI_LINT_VERSION}" ) ; then \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- v${GOLANGCI_LINT_VERSION} ; \
fi
.PHONY: ensure-goreleaser
ensure-goreleaser:
if [ ! -x bin/goreleaser ] || ( ./bin/goreleaser --version | grep -Fqv "${GORELEASER_VERSION}" ) ; then \
GOBIN=$(shell pwd)/bin ${GO} install "github.com/goreleaser/goreleaser/v2@v${GORELEASER_VERSION}" ; \
fi
.PHONY: ensure-syft
ensure-syft:
if [ ! -x bin/syft ] || ( ./bin/syft --version | grep -Fqv "${SYFT_VERSION}" ) ; then \
curl -fsLS https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/syft_${SYFT_VERSION}_$(shell ${GO} env GOOS)_$(shell ${GO} env GOARCH).tar.gz | tar -C bin -xzf - syft ; \
fi
.PHONY: generate
generate:
CHEZMOIDEV=ignoreflags=1,ignorehelp=1 ${GO} generate
.PHONY: release
release: ensure-goreleaser
./bin/goreleaser release \
--clean \
${GORELEASER_FLAGS}
.PHONY: shellcheck
shellcheck:
find . -type f -name \*.sh | xargs shellcheck
.PHONY: test-release
test-release: ensure-goreleaser
./bin/goreleaser release \
--clean \
--skip=chocolatey,sign \
--snapshot \
${GORELEASER_FLAGS}
# FIXME parse go.mod instead of hardcoding tools here
.PHONY: update-go-tools
update-go-tools:
go get \
github.com/editorconfig-checker/editorconfig-checker/v3@latest \
github.com/google/capslock@latest \
github.com/josephspurrier/goversioninfo@latest \
github.com/rhysd/actionlint@latest \
github.com/twpayne/find-typos@latest \
github.com/twpayne/go-jsonstruct/v3@latest