-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (118 loc) · 4.92 KB
/
Makefile
File metadata and controls
139 lines (118 loc) · 4.92 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
#==============================================================#
# File : Makefile
# Mtime : 2026-02-08
# Copyright (C) 2018-2026 Ruohang Feng
#==============================================================#
VERSION=v1.4.0
PIG_VERSION:=$(patsubst v%,%,$(VERSION))
# Build Variables
BRANCH=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
REVISION=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GO_VERSION=$(shell go version | awk '{print $$3}')
# LD Flags for injecting build-time variables
LD_FLAGS=-X 'pig/internal/config.PigVersion=$(PIG_VERSION)' \
-X 'pig/internal/config.Branch=$(BRANCH)' \
-X 'pig/internal/config.Revision=$(REVISION)' \
-X 'pig/internal/config.BuildDate=$(BUILD_DATE)' \
-X 'pig/internal/config.GoVersion=$(GO_VERSION)'
###############################################################
# Build & Release #
###############################################################
# Release Dir
LINUX_AMD_DIR:=dist/$(VERSION)/pig-$(VERSION).linux-amd64
LINUX_ARM_DIR:=dist/$(VERSION)/pig-$(VERSION).linux-arm64
DARWIN_AMD_DIR:=dist/$(VERSION)/pig-$(VERSION).darwin-amd64
DARWIN_ARM_DIR:=dist/$(VERSION)/pig-$(VERSION).darwin-arm64
build-linux-amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "$(LD_FLAGS) -extldflags '-static'" -o pig
upx pig
build-linux-arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -ldflags "$(LD_FLAGS) -extldflags '-static'" -o pig
upx pig
rel: release
release: release-linux
release-linux: linux-amd64 linux-arm64
linux-amd64: clean build-linux-amd64
rm -rf $(LINUX_AMD_DIR) && mkdir -p $(LINUX_AMD_DIR)
nfpm package --packager rpm --config package/nfpm-amd64.yaml --target dist/$(VERSION)
nfpm package --packager deb --config package/nfpm-amd64.yaml --target dist/$(VERSION)
cp -r pig $(LINUX_AMD_DIR)/pig
tar -czf dist/$(VERSION)/pig-$(VERSION).linux-amd64.tar.gz -C dist/$(VERSION) pig-$(VERSION).linux-amd64
rm -rf $(LINUX_AMD_DIR)
linux-arm64: clean build-linux-arm64
rm -rf $(LINUX_ARM_DIR) && mkdir -p $(LINUX_ARM_DIR)
nfpm package --packager rpm --config package/nfpm-arm64.yaml --target dist/$(VERSION)
nfpm package --packager deb --config package/nfpm-arm64.yaml --target dist/$(VERSION)
cp -r pig $(LINUX_ARM_DIR)/pig
tar -czf dist/$(VERSION)/pig-$(VERSION).linux-arm64.tar.gz -C dist/$(VERSION) pig-$(VERSION).linux-arm64
rm -rf $(LINUX_ARM_DIR)
###############################################################
# GoReleaser #
###############################################################
# Install goreleaser if not present
gr-install:
@which goreleaser > /dev/null || (echo "Installing goreleaser..." && go install github.com/goreleaser/goreleaser/v2@latest)
# Build snapshot release (without publishing)
gr-snapshot:
goreleaser release --snapshot --clean --skip=publish
# Build release locally (without git tag)
gr-build:
goreleaser build --snapshot --clean
# Build release locally without snapshot suffix (requires clean git)
gr-local:
goreleaser release --clean --skip=publish
# Release with goreleaser (requires git tag)
gr-release:
goreleaser release --clean
# Production release (set prerelease to false in config first)
gr-prod-release:
@echo "Creating production release (will notify subscribers if announce.skip is false)..."
goreleaser release --clean
# Check goreleaser configuration
gr-check: gr-install
goreleaser check
# New main release task using goreleaser
release-new: gr-release
###############################################################
# Development #
###############################################################
u: upload
upload:
bin/upload.sh
tag:
git tag -d $(VERSION) || true
git tag $(VERSION)
run:
go run main.go
r: run
b: build
build:
go build -ldflags "$(LD_FLAGS)" -o pig
c: clean
clean:
rm -rf pig
docs-serve:
hugo serve
docs-build:
hugo --minify
d: docs-serve
db: docs-build
###############################################################
# Testing #
###############################################################
arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -ldflags "$(LD_FLAGS) -extldflags '-static'" -o pig
amd:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "$(LD_FLAGS) -extldflags '-static'" -o pig
2m:
scp pig meta:/tmp/pig; ssh meta sudo mv /tmp/pig /usr/bin/pig
2c:
docker cp pig d13a:/usr/bin/pig
2a:
scp pig ai:/tmp/pig; ssh ai sudo mv /tmp/pig /usr/bin/pig
2j: amd
scp pig jp:/tmp/pig; ssh jp sudo mv /tmp/pig /usr/bin/pig
.PHONY: run build clean rel release release-linux build-linux-amd64 build-linux-arm64 linux-amd64 linux-arm64 \
gr-install gr-snapshot gr-build gr-local gr-release gr-prod-release gr-check release-new \
upload tag docs-serve docs-build d db r b c arm amd 2m 2c 2a 2j