-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (78 loc) · 2.32 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
SHELL := bash
bold := $(shell tput bold)
norm := $(shell tput sgr0)
GOLANG_VERSION := 1.16
APP_NAME := whmcs-inbound-piped
# gh-actions shim
ifdef GITHUB_REPOSITORY
REPO_NAME := $(GITHUB_REPOSITORY)
endif
ifdef GITHUB_REF
ifneq (,$(findstring refs/heads/,$(GITHUB_REF)))
GIT_BRANCH := $(GITHUB_REF:refs/heads/%=%)
else ifneq (,$(findstring refs/tags/,$(GITHUB_REF)))
TAG_NAME := $(GITHUB_REF:refs/tags/%=%)
endif
endif
REPO_NAME ?= $(notdir $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..))/$(shell basename '$(PWD)')
$(info [REPO_NAME: $(REPO_NAME)])
$(info [GIT_BRANCH: $(GIT_BRANCH)])
$(info [TAG_NAME: $(TAG_NAME)])
.PHONY: all
all:
.PHONY: tidy
tidy:
go fmt
go mod tidy
.PHONY: build
build:
go build
docker build -t s-nail docker/s-nail
.PHONY: crossbuild
crossbuild: build-darwin build-linux build-windows
.PHONY: build-darwin
build-darwin:
mkdir -p dist/darwin/amd64
docker run --rm \
-v "$(PWD):/app" \
-w "/app" \
-e "GOOS=darwin" \
-e "GOARCH=amd64" \
-e "CGO_ENABLED=0" \
--entrypoint sh \
'golang:$(GOLANG_VERSION)-alpine' \
-c "go get -d -v && go build -a -v -o dist/darwin/amd64/$(APP_NAME)" \
2> /dev/stdout | while IFS= read -r line; do printf '[%s] %s\n' "$@" "$${line}"; done; [ "$${PIPESTATUS[0]}" -le "0" ] || exit "$${PIPESTATUS[0]}"
.PHONY: build-linux
build-linux:
mkdir -p dist/linux/amd64
docker run --rm \
-v "$(PWD):/app" \
-w "/app" \
-e "GOOS=linux" \
-e "GOARCH=amd64" \
-e "CGO_ENABLED=0" \
--entrypoint sh \
'golang:$(GOLANG_VERSION)-alpine' \
-c "go get -d -v && go build -a -v -o dist/linux/amd64/$(APP_NAME)" \
2> /dev/stdout | while IFS= read -r line; do printf '[%s] %s\n' "$@" "$${line}"; done; [ "$${PIPESTATUS[0]}" -le "0" ] || exit "$${PIPESTATUS[0]}"
.PHONY: build-windows
build-windows:
mkdir -p dist/windows/amd64
docker run --rm \
-v "$(PWD):/app" \
-w "/app" \
-e "GOOS=windows" \
-e "GOARCH=amd64" \
-e "CGO_ENABLED=0" \
--entrypoint sh \
'golang:$(GOLANG_VERSION)-alpine' \
-c "go get -d -v && go build -a -v -o dist/windows/amd64/$(APP_NAME)" \
2> /dev/stdout | while IFS= read -r line; do printf '[%s] %s\n' "$@" "$${line}"; done; [ "$${PIPESTATUS[0]}" -le "0" ] || exit "$${PIPESTATUS[0]}"
.PHONY: package
package: dist/*/*
for file in $^ ; do \
pushd "$${file}" ; \
zip '$(APP_NAME).zip' '$(APP_NAME)' ; \
popd ; \
done