-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
72 lines (59 loc) · 2.95 KB
/
Copy pathMakefile
File metadata and controls
72 lines (59 loc) · 2.95 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
PREVIOUS_TAG ?= $(shell git tag -l | tail -n 1)
TAG=v2.2.0
.PHONY: help
help:
@echo 'Usage:'
@echo ' make generate-index Generate `index.js` and `post.js` files'
@echo ' make main-linux-amd64 Build static binary for linux/amd64'
@echo ' make main-linux-arm64 Build static binary for linux/arm64'
@echo ' make main-windows-amd64 Build static binary for windows/amd64'
@echo ' make build Build all static binaries + `index.js` and `post.js`'
@echo ' make dist Build generated artifacts and commit them locally'
@echo ' make tag Print tag instructions'
@echo ' make release Print release instructions'
@echo ''
UPX_BIN := $(shell command -v upx 2> /dev/null)
COMMAND := "."
.PHONY: js
js:
rm -f index.js post.js
echo 'package main; import ("os"; "text/template"); func main() { tmpl, _ := template.ParseFiles("index.template.js"); tmpl.Execute(os.Stdout, map[string]string{"Args": ""}) }' > temp.go && go run temp.go > index.js && rm temp.go
echo 'package main; import ("os"; "text/template"); func main() { tmpl, _ := template.ParseFiles("index.template.js"); tmpl.Execute(os.Stdout, map[string]string{"Args": "--post"}) }' > temp.go && go run temp.go > post.js && rm temp.go
.PHONY: main-linux-amd64
main-linux-amd64: _require-upx
rm -f main-linux-amd64-*
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -installsuffix static -o "main-linux-amd64" $(COMMAND)
upx -q -9 "main-linux-amd64"
.PHONY: main-linux-arm64
main-linux-arm64: _require-upx
rm -f main-linux-arm64-*
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -installsuffix static -o "main-linux-arm64" $(COMMAND)
upx -q -9 "main-linux-arm64"
.PHONY: main-windows-amd64
main-windows-amd64: _require-upx
rm -f main-windows-amd64-*
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -installsuffix static -o "main-windows-amd64.exe" $(COMMAND)
upx -q -9 "main-windows-amd64.exe"
.PHONY: build
build: main-linux-amd64 main-linux-arm64 main-windows-amd64 js
# Rebuild generated action artifacts and create a local dist commit.
.PHONY: dist
dist: build
git add main-linux-amd64 main-linux-arm64 main-windows-amd64.exe index.js post.js
git commit -m "dist: rebuild binaries"
.PHONY: _require-upx
_require-upx:
ifndef UPX_BIN
$(error 'upx is not installed, it can be installed via "apt-get install upx", "apk add upx" or "brew install upx".')
endif
.PHONY: bump tag release
bump:
gsed -i "s/$(PREVIOUS_TAG)/$(TAG)/g" README.md
gsed -i "s/$(PREVIOUS_TAG)/$(TAG)/g" action.yml
tag:
@echo 'Release tags are created by the manual GitHub Actions "Release" workflow after CI commits generated artifacts.'
@echo 'Do not create release tags locally.'
@exit 1
release:
@echo 'Releases are created by the manual GitHub Actions "Release" workflow.'
@echo 'Run it with the desired tag, for example TAG=$(TAG), so CI builds, commits, tags, signs, and attests the exact release artifacts.'