-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
188 lines (151 loc) · 8.02 KB
/
Copy pathMakefile
File metadata and controls
188 lines (151 loc) · 8.02 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
.PHONY: build \
build-darwin-amd64 build-darwin-arm64 build-linux-amd64 build-linux-arm64 \
amd arm cross build-cross cross-check \
module-check shell-check maintenance-check test race vet staticcheck deadcode errcheck vuln check license-check \
image-pipeline-test image-pipeline-native-test install-test \
catalog-export catalog-keygen catalog-sign catalog-verify \
release-check release-snapshot release-local gr-check gr-snapshot gr-local release-dev
SNAPSHOT_DIST ?= .goreleaser-snapshot
build:
./packaging/build-dev.sh "$$(go env GOOS)" "$$(go env GOARCH)" bin
build-darwin-amd64:
./packaging/build-dev.sh darwin amd64 bin/darwin_amd64
build-darwin-arm64:
./packaging/build-dev.sh darwin arm64 bin/darwin_arm64
build-linux-amd64:
./packaging/build-dev.sh linux amd64 bin/linux_amd64
build-linux-arm64:
./packaging/build-dev.sh linux arm64 bin/linux_arm64
amd: build-linux-amd64
arm: build-linux-arm64
test:
go test ./...
race:
go test -race ./...
vet:
go vet ./...
staticcheck:
staticcheck ./...
# The production-only diagnostic, `deadcode ./...`, is expected to report only
# YAML MarshalYAML/UnmarshalYAML hooks invoked through reflection. The enforced
# four-target test-linked intersection below must remain completely empty.
deadcode:
@set -eu; \
temporary_parent=$$(cd "$${TMPDIR:-/tmp}" && pwd -P); \
temporary=$$(mktemp -d "$${temporary_parent}/farrow-deadcode.XXXXXX"); \
cleanup() { \
case "$${temporary}" in \
"$${temporary_parent}"/farrow-deadcode.*) rm -rf -- "$${temporary}" ;; \
*) printf 'refuse unsafe deadcode cleanup: %s\n' "$${temporary}" >&2 ;; \
esac; \
}; \
trap cleanup EXIT; \
for target in darwin-arm64 darwin-amd64 linux-amd64 linux-arm64; do \
goos=$${target%-*}; goarch=$${target#*-}; \
GOOS=$${goos} GOARCH=$${goarch} deadcode -test ./... >"$${temporary}/$${target}.raw"; \
LC_ALL=C sort "$${temporary}/$${target}.raw" >"$${temporary}/$${target}"; \
done; \
comm -12 "$${temporary}/darwin-arm64" "$${temporary}/darwin-amd64" >"$${temporary}/intersection-2"; \
comm -12 "$${temporary}/intersection-2" "$${temporary}/linux-amd64" >"$${temporary}/intersection-3"; \
comm -12 "$${temporary}/intersection-3" "$${temporary}/linux-arm64" >"$${temporary}/intersection"; \
if test -s "$${temporary}/intersection"; then cat "$${temporary}/intersection"; exit 1; fi
errcheck:
@output=$$(golangci-lint run --no-config --default=none -E errcheck \
--max-issues-per-linter=0 --max-same-issues=0 ./... 2>&1) || { printf '%s\n' "$${output}"; exit 1; }
vuln:
govulncheck ./...
module-check:
go mod verify
go mod tidy -diff
shell-check:
@for script in packaging/*.sh packaging/image-pipeline/*.sh tests/*.sh; do bash -n "$$script"; done
# A maintenance file must have an explicit owner in a Make target, workflow, or
# contributor documentation. Go tool tests use their package directory as the
# stable reference so adding another *_test.go does not require an inventory edit.
maintenance-check:
@git ls-files 'tools/**' 'packaging/**' | while IFS= read -r path; do \
case "$$path" in tools/*/*.go) reference=$${path%/*} ;; *) reference=$$path ;; esac; \
grep -Fqs -- "$$reference" Makefile CONTRIBUTING.md .github/workflows/*.yml || { \
printf 'unowned maintenance file: %s\n' "$$path" >&2; exit 1; \
}; \
done
cross: build-darwin-amd64 build-darwin-arm64 build-linux-amd64 build-linux-arm64
build-cross: cross
cross-check:
GOOS=darwin GOARCH=arm64 go build ./...
GOOS=darwin GOARCH=amd64 go build ./...
GOOS=linux GOARCH=amd64 go build ./...
GOOS=linux GOARCH=arm64 go build ./...
check: module-check shell-check maintenance-check test race vet staticcheck deadcode errcheck vuln cross-check image-pipeline-test install-test license-check
license-check:
./packaging/verify-licenses.sh
image-pipeline-test:
./tests/image-pipeline-test.sh
image-pipeline-native-test:
FARROW_IMAGE_PIPELINE_NATIVE_REQUIRED=1 ./tests/image-pipeline-native-test.sh
install-test:
./tests/install-test.sh
catalog-export:
@test -n "$(CATALOG_OUTPUT)" || { echo "CATALOG_OUTPUT is required" >&2; exit 2; }
go run ./tools/catalogexport "$(CATALOG_OUTPUT)"
catalog-keygen:
@test -n "$(CATALOG_KEY_DIR)" || { echo "CATALOG_KEY_DIR is required" >&2; exit 2; }
@test -n "$(CATALOG_KEY_NAME)" || { echo "CATALOG_KEY_NAME is required" >&2; exit 2; }
go run ./tools/catalogsign generate "$(CATALOG_KEY_DIR)" "$(CATALOG_KEY_NAME)"
catalog-sign:
@test -n "$(CATALOG_KEY)" || { echo "CATALOG_KEY is required" >&2; exit 2; }
@test -n "$(CATALOG_FILE)" || { echo "CATALOG_FILE is required" >&2; exit 2; }
go run ./tools/catalogsign sign "$(CATALOG_KEY)" "$(CATALOG_FILE)"
catalog-verify:
@test -n "$(CATALOG_PUBLIC_KEY)" || { echo "CATALOG_PUBLIC_KEY is required" >&2; exit 2; }
@test -n "$(CATALOG_FILE)" || { echo "CATALOG_FILE is required" >&2; exit 2; }
go run ./tools/catalogsign verify "$(CATALOG_PUBLIC_KEY)" "$(CATALOG_FILE)"
release-check:
./packaging/check-toolchain.sh goreleaser
goreleaser check
release-snapshot: release-check
@normalized=$$(printf '%s' "$(SNAPSHOT_DIST)" | tr '[:upper:]' '[:lower:]'); \
case "$$normalized" in ""|*/*|.goreleaser-dist|.goreleaser-companion|.goreleaser-licenses) \
echo "SNAPSHOT_DIST must be one new directory directly under the repository root" >&2; exit 2 ;; \
esac
@test ! -e "$(SNAPSHOT_DIST)" || { echo "refuse existing snapshot output: $(SNAPSHOT_DIST)" >&2; exit 1; }
@test ! -e .goreleaser-dist || { echo "refuse existing GoReleaser work output: .goreleaser-dist" >&2; exit 1; }
@test ! -e .goreleaser-companion -a ! -L .goreleaser-companion || { echo "refuse existing GoReleaser companion stage: .goreleaser-companion" >&2; exit 1; }
@test ! -e .goreleaser-licenses -a ! -L .goreleaser-licenses || { echo "refuse existing generated license stage: .goreleaser-licenses" >&2; exit 1; }
@set -e; \
source_epoch=$${SOURCE_DATE_EPOCH:-$$(git show -s --format=%ct HEAD)}; \
test -n "$$source_epoch" || { echo "cannot resolve SOURCE_DATE_EPOCH" >&2; exit 2; }; \
commit=$$(git rev-parse --verify HEAD); \
if ! git diff --quiet || ! git diff --cached --quiet || test -n "$$(git status --short --untracked-files=normal)"; then commit=uncommitted; fi; \
if build_date=$$(date -u -r "$$source_epoch" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null); then :; \
else build_date=$$(date -u -d "@$$source_epoch" +%Y-%m-%dT%H:%M:%SZ); fi; \
cleanup_companions() { \
./packaging/goreleaser-companion.sh cleanup darwin amd64 .goreleaser-companion; \
./packaging/goreleaser-companion.sh cleanup darwin arm64 .goreleaser-companion; \
./packaging/goreleaser-companion.sh cleanup linux amd64 .goreleaser-companion; \
./packaging/goreleaser-companion.sh cleanup linux arm64 .goreleaser-companion; \
./packaging/dependency-licenses.sh clean .goreleaser-licenses; \
if test -e .goreleaser-dist; then rm -rf -- .goreleaser-dist; fi; \
}; \
trap cleanup_companions EXIT; \
SOURCE_DATE_EPOCH="$$source_epoch" FARROW_COMMIT="$$commit" FARROW_BUILD_DATE="$$build_date" \
goreleaser release --snapshot --parallelism 1; \
snapshot_version=$$(jq -er '.version | strings | select(length > 0)' .goreleaser-dist/metadata.json); \
SOURCE_DATE_EPOCH="$$source_epoch" ./packaging/verify-goreleaser.sh "$$snapshot_version" "$$PWD/.goreleaser-dist"; \
./packaging/verify-linux-packages.sh "$$snapshot_version" "$$commit" "$$source_epoch" "$$PWD/.goreleaser-dist"; \
mv .goreleaser-dist "$(SNAPSHOT_DIST)"
release-local:
@test -n "$(VERSION)" || { echo "VERSION is required" >&2; exit 2; }
@if test -n "$(OUTPUT)"; then \
./packaging/release-local.sh "$(VERSION)" "$(OUTPUT)"; \
else \
./packaging/release-local.sh "$(VERSION)"; \
fi
gr-check: release-check
gr-snapshot: release-snapshot
gr-local: release-local
release-dev:
@test -n "$(VERSION)" || { echo "VERSION is required" >&2; exit 2; }
@test -n "$(SOURCE_DATE_EPOCH)" || { echo "SOURCE_DATE_EPOCH is required" >&2; exit 2; }
SOURCE_DATE_EPOCH="$(SOURCE_DATE_EPOCH)" ./packaging/build-release.sh "$(VERSION)" "dist/$(VERSION)"
./packaging/verify-release.sh "$(VERSION)" "$(CURDIR)/dist/$(VERSION)"