Skip to content

Commit 6187feb

Browse files
authored
Merge pull request #1231 from smallstep/carl/goreleaser-make
Allow GoReleaser Pro for `make` builds
2 parents 90703e4 + b92ea5c commit 6187feb

File tree

2 files changed

+74
-44
lines changed

2 files changed

+74
-44
lines changed

.goreleaser.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ project_name: step
44

55
before:
66
hooks:
7-
# You may remove this if you don't use go modules.
87
- go mod download
9-
# - go generate ./...
108

119
builds:
1210
- &COMMON
@@ -36,8 +34,10 @@ builds:
3634
- windows_amd64
3735
- windows_arm64
3836
binary: bin/step
39-
ldflags:
40-
- -w -X main.Version={{.Version}} -X main.BuildTime={{.Date}}
37+
-
38+
<< : *COMMON
39+
id: debug
40+
gcflags: all=-N -l
4141
-
4242
# This build is for S3 binaries that follow our naming convention there.
4343
<< : *COMMON

Makefile

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
# Run `make bootstrap` to set up your local environment.
2+
# To build using go, use `make build`
3+
# For a binary that's in parity with how our CI system builds,
4+
# run `make goreleaser` to build using GoReleaser Pro.
5+
6+
# Variables:
7+
# V=1 for verbose output.
8+
9+
# the name of the executable
10+
BINNAME?=step
11+
12+
# the build output path
13+
PREFIX?=bin
14+
15+
# the install path
16+
DESTDIR?=/usr/local/bin
17+
18+
# GOOS_OVERRIDE="GOOS=linux GOARCH=arm GOARM=6" to change OS and arch
19+
GOOS_OVERRIDE?=
20+
21+
# CGO_OVERRIDE="CGO_ENABLED=1" to enable CGO
22+
CGO_OVERRIDE?=CGO_ENABLED=0
23+
24+
# which build id in .goreleaser.yml to build
25+
GORELEASER_BUILD_ID?=default
26+
ifdef DEBUG
27+
GORELEASER_BUILD_ID=debug
28+
endif
29+
130
all: lint test build
231

332
ci: test build
@@ -32,15 +61,17 @@ $(info VERSION is $(VERSION))
3261
$(info PUSHTYPE is $(PUSHTYPE))
3362
endif
3463

35-
PKG?=github.com/smallstep/cli/cmd/step
36-
BINNAME?=step
64+
DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
65+
ifdef DEBUG
66+
LDFLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
67+
GCFLAGS := -gcflags "all=-N -l"
68+
else
69+
LDFLAGS := -ldflags='-w -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
70+
GCFLAGS :=
71+
endif
3772

38-
# Set V to 1 for verbose output from the Makefile
3973
Q=$(if $V,,@)
40-
PREFIX?=
4174
SRC=$(shell find . -type f -name '*.go')
42-
GOOS_OVERRIDE ?=
43-
CGO_OVERRIDE ?= CGO_ENABLED=0
4475
OUTPUT_ROOT=output/
4576

4677
ifeq ($(OS),Windows_NT)
@@ -76,26 +107,28 @@ bootstra%:
76107
# Build
77108
#########################################
78109

79-
DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
80-
ifdef DEBUG
81-
LDFLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
82-
GCFLAGS := -gcflags "all=-N -l"
83-
else
84-
LDFLAGS := -ldflags='-w -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
85-
GCFLAGS :=
86-
endif
110+
build: $(PREFIX)/$(BINNAME)
111+
@echo "Build Complete!"
87112

88-
download:
89-
$Q go mod download
113+
$(PREFIX)/$(BINNAME):
114+
$Q mkdir -p $(PREFIX)
115+
$Q $(GOOS_OVERRIDE) $(CGO_OVERRIDE) go build \
116+
-v \
117+
-o $(PREFIX)/$(BINNAME) \
118+
$(GCFLAGS) $(LDFLAGS) \
119+
github.com/smallstep/cli/cmd/step
90120

91-
build: $(PREFIX)bin/$(BINNAME)
92-
@echo "Build Complete!"
121+
goreleaser:
122+
$Q mkdir -p $(PREFIX)
123+
$Q $(GOOS_OVERRIDE) $(CGO_OVERRIDE) goreleaser build \
124+
--id $(GORELEASER_BUILD_ID) \
125+
--snapshot \
126+
--single-target \
127+
--clean \
128+
--output $(PREFIX)/$(BINNAME)
93129

94-
$(PREFIX)bin/$(BINNAME): download $(call rwildcard,*.go)
95-
$Q mkdir -p $(@D)
96-
$Q $(GOOS_OVERRIDE) $(CGO_OVERRIDE) go build -v -o $@ $(GCFLAGS) $(LDFLAGS) $(PKG)
130+
.PHONY: build goreleaser
97131

98-
.PHONY: build simple
99132

100133
#########################################
101134
# Test
@@ -111,7 +144,7 @@ race:
111144

112145
integrate: integration
113146

114-
integration: bin/$(BINNAME)
147+
integration: build
115148
$Q $(CGO_OVERRIDE) gotestsum -- -tags=integration ./integration/...
116149

117150
.PHONY: integrate integration
@@ -138,14 +171,12 @@ govulncheck:
138171
# Install
139172
#########################################
140173

141-
INSTALL_PREFIX?=/usr/local/
142-
143-
install: $(PREFIX)bin/$(BINNAME)
144-
$Q mkdir -p $(INSTALL_PREFIX)bin/
145-
$Q install $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
174+
install: $(PREFIX)/$(BINNAME)
175+
$Q mkdir -p $(DESTDIR)/
176+
$Q install $(PREFIX)/$(BINNAME) $(DESTDIR)/$(BINNAME)
146177

147178
uninstall:
148-
$Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
179+
$Q rm -f $(DESTDIR)/$(BINNAME)
149180

150181
.PHONY: install uninstall
151182

@@ -154,9 +185,8 @@ uninstall:
154185
#########################################
155186

156187
clean:
157-
ifneq ($(BINNAME),"")
158-
$Q rm -f bin/$(BINNAME)
159-
endif
188+
$Q rm -f $(PREFIX)/$(BINNAME)
189+
$Q rm -rf dist
160190

161191
.PHONY: clean
162192

@@ -171,28 +201,28 @@ define BUNDLE_MAKE
171201
# $(2) -- Go Architecture (e.g. amd64, arm, arm64, etc.)
172202
# $(3) -- Go ARM architectural family (e.g. 7, 8, etc.)
173203
# $(4) -- Parent directory for executables generated by 'make'.
174-
$(q) GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2) GOARM=$(3)' PREFIX=$(4) make $(4)bin/step
204+
$Q GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2) GOARM=$(3)' PREFIX=$(4) make $(4)/$(BINNAME)
175205
endef
176206

177207
binary-linux-amd64:
178-
$(call BUNDLE_MAKE,linux,amd64,,$(BINARY_OUTPUT)linux-amd64/)
208+
$(call BUNDLE_MAKE,linux,amd64,,$(BINARY_OUTPUT)linux-amd64)
179209

180210
binary-linux-arm64:
181-
$(call BUNDLE_MAKE,linux,arm64,,$(BINARY_OUTPUT)linux-arm64/)
211+
$(call BUNDLE_MAKE,linux,arm64,,$(BINARY_OUTPUT)linux-arm64)
182212

183213
binary-linux-armv7:
184-
$(call BUNDLE_MAKE,linux,arm,7,$(BINARY_OUTPUT)linux-armv7/)
214+
$(call BUNDLE_MAKE,linux,arm,7,$(BINARY_OUTPUT)linux-armv7)
185215

186216
binary-linux-mips:
187-
$(call BUNDLE_MAKE,linux,mips,,$(BINARY_OUTPUT)linux-mips/)
217+
$(call BUNDLE_MAKE,linux,mips,,$(BINARY_OUTPUT)linux-mips)
188218

189219
binary-darwin-amd64:
190-
$(call BUNDLE_MAKE,darwin,amd64,,$(BINARY_OUTPUT)darwin-amd64/)
220+
$(call BUNDLE_MAKE,darwin,amd64,,$(BINARY_OUTPUT)darwin-amd64)
191221

192222
binary-darwin-arm64:
193-
$(call BUNDLE_MAKE,darwin,amd64,,$(BINARY_OUTPUT)darwin-arm64/)
223+
$(call BUNDLE_MAKE,darwin,amd64,,$(BINARY_OUTPUT)darwin-arm64)
194224

195225
binary-windows-amd64:
196-
$(call BUNDLE_MAKE,windows,amd64,,$(BINARY_OUTPUT)windows-amd64/)
226+
$(call BUNDLE_MAKE,windows,amd64,,$(BINARY_OUTPUT)windows-amd64)
197227

198228
.PHONY: binary-linux-amd64 binary-linux-arm64 binary-linux-armv7 binary-linux-mips binary-darwin-amd64 binary-darwin-arm64 binary-windows-amd64

0 commit comments

Comments
 (0)