-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
188 lines (147 loc) · 4.72 KB
/
Makefile
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
## SPDX-FileCopyrightText: 2019 M. Shulhan <[email protected]>
## SPDX-License-Identifier: GPL-3.0-or-later
LD_FLAGS=-s -w
VERSION=$(shell git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
.PHONY: all
all: test lint
.PHONY: test
test:
go test -cover ./... -test.gocoverdir=_coverage
go tool covdata textfmt -i=_coverage -o cover.txt
go tool cover -html=cover.txt -o cover.html
.PHONY: lint
lint:
-fieldalignment ./...
-shadow ./...
-golangci-lint run \
--presets bugs,metalinter,performance,unused \
--disable bodyclose \
--disable contextcheck \
--disable dupword \
--disable gomoddirectives \
./...
## embed convert the TypeScript files into JavaScript and embed all _wui
## assets into memfs for web-user interface.
.PHONY: embed
embed:
go run ./internal/cmd/awwan-internal build
.PHONY: build
build: embed
go build -o _bin/awwan ./cmd/awwan
.PHONY: install
install: lint-www lint embed
go install ./cmd/awwan
.PHONY: dev
dev:
go run ./cmd/awwan -dev -address 127.0.0.1:17500 serve _example
#{{{ Task to lint the TypeScript files.
.PHONY: lint-www
lint-www:
-cd _wui && eslint --fix .
#}}}
#{{{ Unit and integration tests using container. Linux only.
.PHONY: build-awwan-test
build-awwan-test:
@echo ">>> Stopping container ..."
-sudo machinectl stop awwan-test
@echo ">>> Creating binding ..."
mkdir -p /data/awwan/
ln -sTf $$(pwd) /data/awwan/src
ln -sTf $(shell go env GOCACHE) /data/awwan/gocache
ln -sTf $(shell go env GOMODCACHE) /data/awwan/gomodcache
@echo ">>> Building container awwan-test ..."
sudo mkosi --directory=_ops/awwan-test/ --force build
sudo machinectl --force import-tar /data/awwan/awwan-test.tar
sudo machinectl start awwan-test
## Once the container is imported, we can enable and run them any
## time without rebuilding again.
.PHONY: test-integration
test-integration:
go test -tags=integration -c .
machinectl shell awwan@awwan-test \
/bin/sh -c "cd src; ./awwan.test"
.PHONY: test-all
test-all:
rm -f _coverage/*
go test -cover ./... -test.gocoverdir=_coverage
machinectl shell awwan@awwan-test \
/bin/sh -c "cd src; \
go test -cover -tags=integration ./... -test.gocoverdir=_coverage"
go tool covdata textfmt -i=_coverage -o cover.txt
go tool cover -html=cover.txt -o cover.html
go tool covdata percent -i=_coverage
#}}}
#{{{ Tasks to test or deploy awwan.org website.
.PHONY: build-www
build-www: embed
go build ./internal/cmd/www-awwan/
.PHONY: serve-www
serve-www:
go run ./internal/cmd/www-awwan -dev
.PHONY: install-www
install-www: embed
go install ./internal/cmd/www-awwan
.PHONY: deploy-www
deploy-www: GOOS=linux GOARCH=amd64 CGO_ENABLED=0
deploy-www: build-www
rsync --progress ./www-awwan awwan.org:/data/app/bin/
#}}}
#{{{ Task to build and upload binaries.
## Currently, only support amd64 architecture on non-mobile OS.
.PHONY: build-all-amd64
build-all-amd64: GOARCH=amd64
build-all-amd64: LD_FLAGS+=-X 'git.sr.ht/~shulhan/awwan.Version=$(VERSION)'
build-all-amd64:
for os in "darwin" "dragonfly" "freebsd" "linux" "netbsd" "openbsd" "plan9" "solaris" "windows"; do \
echo ">>> Building for $$os/$(GOARCH)";\
GOOS=$$os go build \
-o _bin/dl/awwan-$$os-$(GOARCH) \
-trimpath \
-ldflags="$(LD_FLAGS)" \
./cmd/awwan/;\
done
.PHONY: build-all-arm64
build-all-arm64: GOARCH=arm64
build-all-arm64: LD_FLAGS+=-X 'git.sr.ht/~shulhan/awwan.Version=$(VERSION)'
build-all-arm64:
for os in "darwin" "freebsd" "linux" "netbsd" "openbsd" "windows"; do \
echo ">>> Building for $$os/$(GOARCH)";\
GOOS=$$os go build \
-o _bin/dl/awwan-$$os-$(GOARCH) \
-trimpath \
-ldflags="$(LD_FLAGS)" \
./cmd/awwan/;\
done
## Task to release binaries automatically using karajo at
## build.kilabit.info.
.PHONY: release-sync
release-sync:
sudo chown -R ms:karajo /srv/awwan/
sudo chmod -R g+w /srv/awwan/
rsync -rtvO --progress ./_bin/dl/ /srv/awwan/dl/
.PHONY: release-tip
release-tip: embed build-all-amd64 build-all-arm64 release-sync
## Task to release binaries manually from local.
.PHONY: release-sync-local
release-sync-local:
rsync -av --progress ./_bin/dl/ awwan.org:/srv/awwan/dl/
.PHONY: release-tip-local
release-tip-local: embed build-all-amd64 build-all-arm64 release-sync-local
#}}}
#{{{ Tasks for tour.awwan.org.
## Build the tour.awwan.org container in local.
.PHONY: build-tour
build-tour:
@echo ">>> Building container ..."
sudo mkosi --directory=_ops/awwan-tour --force build
.PHONY: build-tour-local
build-tour-local: build-tour
@echo ">>> Stopping container ..."
-sudo machinectl stop awwan-tour
## We need to bind src/_bin and src/_tour into container.
@echo ">>> Creating binding ..."
mkdir -p /data/awwan/
ln -sTf $$(pwd) /data/awwan/src
sudo machinectl --force import-tar /data/awwan/awwan-tour.tar
sudo machinectl start awwan-tour
#}}}