Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
171 lines (153 loc) · 7.32 KB
/
Copy pathMakefile
File metadata and controls
171 lines (153 loc) · 7.32 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
# Everything between the source and the file somebody installs.
#
# One command, in one order, that anybody can run: make release. It was a
# sequence somebody had to remember — build this, check that, do not forget
# the tests — and a sequence somebody has to remember is a sequence that gets
# a step skipped on the evening it matters.
#
# Each step is also a target of its own, because the whole thing takes minutes
# and "run the tests again" should not mean running the packaging again.
SHELL := /bin/bash
ROOT := $(shell pwd)
VERSION := $(shell tr -d ' \t\n\r' < VERSION)
PACKAGES := $(ROOT)/build/packages
GO := CGO_ENABLED=1 go
# Tests make no sound and open no microphone, here or in anything they start.
# Test binaries are silent by themselves (speech.Silent); this covers the
# program and helpers a test runs as a subprocess. See speech/silent.go.
QUIET := PN_SCRIPTS_ASSISTANT_SILENT=1
.PHONY: help clean check test race vulns build package packages validate checksums reproducible ci release version install-deps
help:
@echo " make release everything below, in order, ending in files to publish"
@echo " make check formatting and vet"
@echo " make test every test"
@echo " make vulns known vulnerabilities, including the toolchain's"
@echo " make build the binary, into build/"
@echo " make package the .deb"
@echo " make packages the .deb, the macOS bundles and disk images, the Windows folder"
@echo " make validate lintian and the desktop entry"
@echo " make clean remove build/"
@echo " make ci everything CI runs, in the same order"
@echo " make version what this would be released as"
version:
@echo "declared: $(VERSION) (VERSION)"
@echo "package: $$(bash scripts/build-packages.sh --print-version 2>/dev/null || echo '?')"
@echo "commit: $$(git rev-parse --short HEAD 2>/dev/null || echo 'not a repository')"
clean:
rm -rf build
# Formatting and vet, which is the cheapest check there is and the one most
# worth failing on: a build that has not been formatted has not been read.
check:
@echo "→ gofmt"
@test -z "$$(gofmt -l clients/cmd clients/internal)" || \
{ echo "not formatted:"; gofmt -l clients/cmd clients/internal; exit 1; }
@echo "→ go vet"
@cd clients && $(GO) vet ./...
@bash scripts/version-order-test.sh
@bash scripts/release-versions-test.sh
@bash scripts/release-followers-test.sh
test:
@echo "→ go test"
@cd clients && $(QUIET) $(GO) test ./... -p 2
# The same tests with the race detector, which CI runs on every push.
#
# Separate from `test` because it is several times slower and because the
# thing it is looking for is rare — but it is looking in the right place: this
# program answers on HTTP while a learning worker writes to the same database,
# and a race there is a corrupted brain rather than a crash somebody notices.
#
# Twenty minutes for one package, not go's ten. The two largest packages
# start a real server or a real brain for most of their tests, which the
# detector makes several times slower: the server's took 560 of the 600
# seconds on CI at 1.2.0, and the next eight tests took it over (a red run
# that was no fault and no race). The limit is there to stop a test that
# hangs, and still does; a run that is slow is not a run that hangs.
race:
@echo "→ go test -race"
@cd clients && $(QUIET) $(GO) test -race -timeout 20m ./... -p 2
# Known vulnerabilities, in what is imported and in the toolchain itself.
#
# Not part of `check`, because it needs the network and a check that fails on
# a train is a check people learn to skip. Part of `release`, where the
# network is already needed, and part of CI.
#
# The first run of this found twenty-eight vulnerabilities in the Go standard
# library — crypto/x509, crypto/tls and net/http, all three of which this
# program serves with. None of them was in this code; all of them were fixed
# by raising the toolchain in go.mod.
vulns:
@echo "→ govulncheck"
@command -v govulncheck >/dev/null || \
{ echo " installing govulncheck"; go install golang.org/x/vuln/cmd/govulncheck@latest; }
@cd clients && PATH="$$PATH:$$(go env GOPATH)/bin" govulncheck ./...
# The ordinary build, for looking at. The one that ships is built inside the
# packaging script, with -trimpath and the version stamped in.
build:
@mkdir -p build
@cd clients && $(GO) build -trimpath -o "$(ROOT)/build/pn-scripts-assistant" ./cmd/pn-scripts-assistant
@"$(ROOT)/build/pn-scripts-assistant" version
package:
@bash scripts/build-packages.sh deb
# Everything somebody might download, from one machine.
#
# The .deb and the macOS pieces come out complete; the Windows installer does
# not, because Inno Setup only runs on Windows — the script says so and builds
# the zip anyway. CI builds each one on its own system, which is where the
# files that get published come from.
packages:
@bash scripts/build-packages.sh all
# What the package says about itself, from the outside. Run after packaging
# and again in CI, because a package that installs is not the same as a
# package that is correct.
validate:
@set -e; \
deb="$$(ls $(PACKAGES)/pn-scripts-assistant_*_amd64.deb 2>/dev/null | head -1)"; \
test -n "$$deb" || { echo "no package built"; exit 1; }; \
echo "→ $$deb"; \
dpkg-deb --info "$$deb" | sed -n '3,12p'; \
echo "→ the files it carries"; \
carried="$$(dpkg-deb --contents "$$deb")"; \
echo "$$carried" | grep -E 'usr/(bin|share/(applications|doc|man))' | awk '{print $$1, $$6}'; \
for required in usr/bin/pn-scripts-assistant \
usr/share/applications/pn-scripts-assistant.desktop \
usr/share/doc/pn-scripts-assistant/copyright \
usr/share/doc/pn-scripts-assistant/changelog.gz \
usr/share/man/man1/pn-scripts-assistant.1.gz \
etc/apt/sources.list.d/pn-scripts-assistant.sources; do \
echo "$$carried" | grep -q "$$required" || { echo "missing: $$required"; exit 1; }; \
done; \
if command -v lintian >/dev/null; then \
echo "→ lintian"; \
lintian --fail-on error,warning --tag-display-limit 0 "$$deb"; \
echo " clean"; \
else \
echo "! lintian is not installed; the package was not checked"; \
fi
# What somebody downloading a file needs to know it is the file that was
# built. Written beside the packages, named for the version.
checksums:
@cd $(PACKAGES) && sha256sum *.deb > SHA256SUMS && cat SHA256SUMS
# Built twice from one commit, and the two compared.
#
# "Check what you downloaded is what was built" is only as strong as the build
# being the same build. Run after `package`, and it builds a second one.
reproducible: package
@first="$$(sha256sum $(PACKAGES)/*.deb | cut -d' ' -f1)"; \
bash scripts/build-packages.sh deb >/dev/null; \
second="$$(sha256sum $(PACKAGES)/*.deb | cut -d' ' -f1)"; \
echo "→ reproducible"; \
echo " first: $$first"; \
echo " second: $$second"; \
test "$$first" = "$$second" || { echo " two builds of one commit differ"; exit 1; }; \
echo " identical"
# Everything CI runs, in the same order, so a pull request can be checked here
# rather than found out about afterwards. Slower than `make check` by a long
# way; that is what `check` is for.
ci: check race vulns reproducible validate
release: clean check test vulns package validate checksums
@echo
@echo " Released $(VERSION)"
@echo " Files: $(PACKAGES)"
@ls -lh $(PACKAGES) | tail -n +2 | awk '{print " " $$9, $$5}'
@echo
@echo " Install with: sudo apt install ./$$(cd $(PACKAGES) && ls *.deb)"