-
Notifications
You must be signed in to change notification settings - Fork 10
/
justfile
298 lines (242 loc) · 11 KB
/
justfile
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# get the latest git tag like v0.14.0 and remove the prefix v
latest := `git describe --abbrev=0 --tags | sed 's/v//'`
ldflags := "-ldflags='-s -w'"
COLOR_GREEN := "[0;32m"
COLOR_RED := "[0;31m"
# build binaries for all platforms
build:
# build the binary in build/
# Linux macOS Windows
# 386 amd64 arm arm64
mkdir -p build
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build {{ldflags}} -o build/g-linux-386
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build {{ldflags}} -o build/g-linux-amd64
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build {{ldflags}} -o build/g-linux-arm
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build {{ldflags}} -o build/g-linux-arm64
CGO_ENABLED=0 GOOS=linux GOARCH=loong64 go build {{ldflags}} -o build/g-linux-loong64
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build {{ldflags}} -o build/g-darwin-amd64
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build {{ldflags}} -o build/g-darwin-arm64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build {{ldflags}} -o build/g-windows-amd64.exe
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build {{ldflags}} -o build/g-windows-386.exe
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build {{ldflags}} -o build/g-windows-arm64.exe
CGO_ENABLED=0 GOOS=windows GOARCH=arm go build {{ldflags}} -o build/g-windows-arm.exe
upx build/g-linux-386
upx build/g-linux-amd64
upx build/g-linux-arm
upx build/g-linux-arm64
upx build/g-darwin-amd64
upx build/g-windows-amd64.exe
upx build/g-windows-386.exe
# upx doesn't support darwin-arm64, linux-loong64, windows-arm64, windows-arm
# upx build/g-darwin-arm64
# upx build/g-linux-loong64
# upx build/g-windows-arm64.exe
# upx build/g-windows-arm.exe
# compress the binaries for all platforms
compress:
# g_OS_ARCH.tar.gz or g_Windows_ARCH.zip
tar -zcvf build/g-Linux-386.tar.gz build/g-linux-386
tar -zcvf build/g-Linux-amd64.tar.gz build/g-linux-amd64
tar -zcvf build/g-Linux-arm.tar.gz build/g-linux-arm
tar -zcvf build/g-Linux-arm64.tar.gz build/g-linux-arm64
tar -zcvf build/g-Linux-loong64.tar.gz build/g-linux-loong64
tar -zcvf build/g-Darwin-amd64.tar.gz build/g-darwin-amd64
tar -zcvf build/g-Darwin-arm64.tar.gz build/g-darwin-arm64
zip -r build/g-Windows-amd64.zip build/g-windows-amd64.exe
zip -r build/g-Windows-386.zip build/g-windows-386.exe
zip -r build/g-Windows-arm64.zip build/g-windows-arm64.exe
zip -r build/g-Windows-arm.zip build/g-windows-arm.exe
# build deb package for all ARCH
deb:
# g_VERSION_ARCH.deb
# |__DEBIAN
# | |__control
# |__usr
# |__local
# |__bin
# | |__g
# |__share
# |__man
# |__man1
# |__g.1.gz
# amd64
mkdir -vp build/g_{{latest}}_amd64/DEBIAN
mkdir -vp build/g_{{latest}}_amd64/usr/local/bin
mkdir -vp build/g_{{latest}}_amd64/usr/local/share/man/man1
cp build/g-linux-amd64 build/g_{{latest}}_amd64/usr/local/bin/g
cp man/g.1.gz build/g_{{latest}}_amd64/usr/local/share/man/man1/g.1.gz
echo "Package: g" > build/g_{{latest}}_amd64/DEBIAN/control
echo "Version: {{latest}}" >> build/g_{{latest}}_amd64/DEBIAN/control
echo "Architecture: amd64" >> build/g_{{latest}}_amd64/DEBIAN/control
echo "Maintainer: Equationzhao <equationzhao at foxmail.com>" >> build/g_{{latest}}_amd64/DEBIAN/control
echo "Description: a powerful ls tool" >> build/g_{{latest}}_amd64/DEBIAN/control
dpkg-deb -b build/g_{{latest}}_amd64
rm -rf build/g_{{latest}}_amd64
# arm64
mkdir -vp build/g_{{latest}}_arm64/DEBIAN
mkdir -vp build/g_{{latest}}_arm64/usr/local/bin
mkdir -vp build/g_{{latest}}_arm64/usr/local/share/man/man1
cp build/g-linux-arm64 build/g_{{latest}}_arm64/usr/local/bin/g
cp man/g.1.gz build/g_{{latest}}_arm64/usr/local/share/man/man1/g.1.gz
echo "Package: g" > build/g_{{latest}}_arm64/DEBIAN/control
echo "Version: {{latest}}" >> build/g_{{latest}}_arm64/DEBIAN/control
echo "Architecture: arm64" >> build/g_{{latest}}_arm64/DEBIAN/control
echo "Maintainer: Equationzhao <equationzhao at foxmail.com>" >> build/g_{{latest}}_arm64/DEBIAN/control
echo "Description: a powerful ls tool" >> build/g_{{latest}}_arm64/DEBIAN/control
dpkg-deb -b build/g_{{latest}}_arm64
rm -rf build/g_{{latest}}_arm64
# 386
mkdir -vp build/g_{{latest}}_386/DEBIAN
mkdir -vp build/g_{{latest}}_386/usr/local/bin
mkdir -vp build/g_{{latest}}_386/usr/local/share/man/man1
cp build/g-linux-386 build/g_{{latest}}_386/usr/local/bin/g
cp man/g.1.gz build/g_{{latest}}_386/usr/local/share/man/man1/g.1.gz
echo "Package: g" > build/g_{{latest}}_386/DEBIAN/control
echo "Version: {{latest}}" >> build/g_{{latest}}_386/DEBIAN/control
echo "Architecture: 386" >> build/g_{{latest}}_386/DEBIAN/control
echo "Maintainer: Equationzhao <equationzhao at foxmail.com>" >> build/g_{{latest}}_386/DEBIAN/control
echo "Description: a powerful ls tool" >> build/g_{{latest}}_386/DEBIAN/control
dpkg-deb -b build/g_{{latest}}_386
rm -rf build/g_{{latest}}_386
# arm
mkdir -vp build/g_{{latest}}_arm/DEBIAN
mkdir -vp build/g_{{latest}}_arm/usr/local/bin
mkdir -vp build/g_{{latest}}_arm/usr/local/share/man/man1
cp build/g-linux-arm build/g_{{latest}}_arm/usr/local/bin/g
cp man/g.1.gz build/g_{{latest}}_arm/usr/local/share/man/man1/g.1.gz
echo "Package: g" > build/g_{{latest}}_arm/DEBIAN/control
echo "Version: {{latest}}" >> build/g_{{latest}}_arm/DEBIAN/control
echo "Architecture: arm" >> build/g_{{latest}}_arm/DEBIAN/control
echo "Maintainer: Equationzhao <equationzhao at foxmail.com>" >> build/g_{{latest}}_arm/DEBIAN/control
echo "Description: a powerful ls tool" >> build/g_{{latest}}_arm/DEBIAN/control
dpkg-deb -b build/g_{{latest}}_arm
rm -rf build/g_{{latest}}_arm
# loong64
mkdir -vp build/g_{{latest}}_loong64/DEBIAN
mkdir -vp build/g_{{latest}}_loong64/usr/local/bin
mkdir -vp build/g_{{latest}}_loong64/usr/local/share/man/man1
cp build/g-linux-loong64 build/g_{{latest}}_loong64/usr
cp man/g.1.gz build/g_{{latest}}_loong64/usr/local/share/man/man1/g.1.gz
echo "Package: g" > build/g_{{latest}}_loong64/DEBIAN/control
echo "Version: {{latest}}" >> build/g_{{latest}}_loong64/DEBIAN/control
echo "Architecture: loong64" >> build/g_{{latest}}_loong64/DEBIAN/control
echo "Maintainer: Equationzhao <equationzhao at foxmail.com>" >> build/g_{{latest}}_loong64/DEBIAN/control
echo "Description: a powerful ls tool" >> build/g_{{latest}}_loong64/DEBIAN/control
dpkg-deb -b build/g_{{latest}}_loong64
rm -rf build/g_{{latest}}_loong64
# generate the checksum file for all build files
checksum:
shasum -a 256 build/* > build/checksum.txt
# build executables and compress and deb and checksum
genrelease: build compress deb checksum
# release to github
release:
gh release create v{{latest}} build/*
url := "https://github.com/Equationzhao/g"
# update aur
aur:
# download the latest source code from {{url}}/"archive/refs/tags/v{{latest}}.tar.gz" if v{{latest}}.tar.gz not exists
#!/usr/bin/env bash
if [ ! -f v{{latest}}.tar.gz ]; then \
wget -c {{url}}/archive/refs/tags/v{{latest}}.tar.gz -O v{{latest}}.tar.gz; \
fi \
# update PKGBUILD
sed -i bak "s/sha256sums=.*/sha256sums=('$(shasum -a 256 v{{latest}}.tar.gz | choose 0)')/g" ../g-ls/PKGBUILD
sed -i bak "s/pkgver=.*/pkgver={{latest}}/g" ../g-ls/PKGBUILD
# update .SRCINFO
sed -i bak "s/pkgver = .*/pkgver = {{latest}}/g" ../g-ls/.SRCINFO
sed -i.bak "s/sha256sums = .*/sha256sums = '$(shasum -a 256 v{{latest}}.tar.gz | awk '{print $1}')'/g" ../g-ls/.SRCINFO
sed -i.bak "s|source = g-.*::.*|source = g-{{latest}}.tar.gz::{{url}}/archive/refs/tags/v{{latest}}.tar.gz|g" ../g-ls/.SRCINFO
cd ../g-ls
# input git commit message
cd ../g-ls && git add -u
cd ../g-ls && git commit
cd ../g-ls && git push
# update homebrew-tap
brew-tap:
if [ ! -f v{{latest}}.tar.gz ]; then \
wget -c {{url}}/archive/refs/tags/v{{latest}}.tar.gz -O v{{latest}}.tar.gz; \
fi
sed -i bak "s#url .*#url \"{{url}}/archive/refs/tags/v{{latest}}.tar.gz\", tag: \"v{{latest}}\"#g" ../homebrew-g/g-ls.rb
sed -i bak "s/sha256 .*/sha256 \"$(shasum -a 256 v{{latest}}.tar.gz | choose 0)\"/g" ../homebrew-g/g-ls.rb
sed -i bak '/assert_match/s/"[0-9.]*"/"{{latest}}"/' ../homebrew-g/g-ls.rb
cd ../homebrew-g
cd ../homebrew-g && git add -u
cd ../homebrew-g && git commit
cd ../homebrew-g && git push
# update homebrew-core
brew:
brew bump-formula-pr --strict --online g-ls
# update scoop
scoop:
cd scoop && sh scoop.sh
# clean the build directory
clean:
rm -rf build
# golangci-lint
lint:
golangci-lint run ./...
# format the code
format:
gofumpt -w -l .
# precheck the code(format and lint)
precheck: format lint
# generate the documentation
doc:
CGO_ENABLED=0 go build -tags 'doc'
./g
rm g
testcustomtheme:
@sh ./script/theme_test.sh
# generate the theme
theme:
CGO_ENABLED=0 go build -tags 'theme'
./g
rm g
# generate the docs(doc and theme)
gendocs: doc theme
check-git-status:
@if [ "$(git rev-parse HEAD)" == "$(git rev-parse v{{latest}})" ]; then \
if [ -z "$(git status --porcelain)" ]; then \
if [ "$(grep 'Version' internal/cli/version.go | awk '{print $4}' | sed 's/"//g')" == {{latest}} ]; then \
echo "{{COLOR_GREEN}}latest tag v{{latest}} is on the current HEAD and the git status is clean. And version matches."; \
else \
echo "{{COLOR_RED}}latest tag v{{latest}} is on the current HEAD and the git status is clean."; \
echo "{{COLOR_RED}}But version doesn't match. Please update the version in internal/cli/version.go."; \
exit 1; \
fi; \
else \
echo "{{COLOR_RED}}latest tag v{{latest}} is on the current HEAD but git status is dirty." && exit 1; \
fi; \
else \
echo "{{COLOR_RED}}latest tag v{{latest}} isn't on the current HEAD." && exit 1; \
fi;
check-install-script:
@echo "git tag: v{{latest}}"
@if [ "$(sh ./script/install.sh -v)" == {{latest}} ]; then \
echo "{{COLOR_GREEN}}install.go -v matches {{latest}} "; \
else \
echo "{{COLOR_RED}}install.go -v "$(sh ./script/install.sh -v)""; \
echo "{{COLOR_RED}}script version doesn't match {{latest}}"; \
fi;
# check git tag and git status
check: check-install-script check-git-status
newtest:
@sh ./script/new_test.sh
reproducetest:
@sh ./script/reproduce_test_result.sh
test: testcustomtheme
go test -cover -gcflags=all=-l -v ./...
@echo "-------- start --------"
go build
@sh ./script/run_test.sh
@rm g
newpatch:
git add -u && git commit -m ":bookmark: new patch version"
newminor:
git add -u && git commit -m ":bookmark: new minor version"
newmajor:
git add -u && git commit -m ":bookmark: new major version"
boostrap:
sh script/install_dev_requirement.sh
all: precheck gendocs test check clean genrelease release