Skip to content

Commit

Permalink
Build using go by default. Add goreleaser goal and an intro at the top
Browse files Browse the repository at this point in the history
  • Loading branch information
tashian committed Jul 16, 2024
1 parent 4bac69e commit dd1b642
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Set V=1 for verbose output.
# Run `make bootstrap` to set up your local environment.
# To build using go, use `make build`
# For a binary that's in parity with how our CI system builds,
# run `make goreleaser` to build using GoReleaser Pro.

all: lint test build

ci: test build
Expand All @@ -8,7 +14,39 @@ ci: test build
# Determine the type of `push` and `version`
#################################################

# Set V to 1 for verbose output from the Makefile
ifdef GITHUB_REF
VERSION ?= $(shell echo $(GITHUB_REF) | sed 's/^refs\/tags\///')
NOT_RC := $(shell echo $(VERSION) | grep -v -e -rc)
ifeq ($(NOT_RC),)
PUSHTYPE := release-candidate
else
PUSHTYPE := release
endif
else
VERSION ?= $(shell [ -d .git ] && git describe --tags --always --dirty="-dev")
# If we are not in an active git dir then try reading the version from .VERSION.
# .VERSION contains a slug populated by `git archive`.
VERSION := $(or $(VERSION),$(shell make/version.sh .VERSION))
PUSHTYPE := branch
endif

VERSION := $(shell echo $(VERSION) | sed 's/^v//')

ifdef V
$(info GITHUB_REF is $(GITHUB_REF))
$(info VERSION is $(VERSION))
$(info PUSHTYPE is $(PUSHTYPE))
endif

DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
ifdef DEBUG
LDFLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
GCFLAGS := -gcflags "all=-N -l"
else
LDFLAGS := -ldflags='-w -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
GCFLAGS :=
endif

Q=$(if $V,,@)
PREFIX?=
SRC=$(shell find . -type f -name '*.go')
Expand All @@ -21,7 +59,6 @@ ifdef DEBUG
GORELEASER_BUILD_ID=debug
endif


.PHONY: all

#########################################
Expand All @@ -45,6 +82,14 @@ build: $(PREFIX)bin/step
@echo "Build Complete!"

$(PREFIX)bin/step:
$Q mkdir -p $(@D)
$Q $(GOOS_OVERRIDE) $(CGO_OVERRIDE) go build \
-v \
-o $(PREFIX)bin/step \
$(GCFLAGS) $(LDFLAGS) \
github.com/smallstep/cli/cmd/step

goreleaser:
$Q mkdir -p $(@D)
$Q $(GOOS_OVERRIDE) $(CGO_OVERRIDE) goreleaser build \
--id $(GORELEASER_BUILD_ID) \
Expand All @@ -53,7 +98,8 @@ $(PREFIX)bin/step:
--clean \
--output $(PREFIX)bin/step

.PHONY: build
.PHONY: build gobuild


#########################################
# Test
Expand Down

0 comments on commit dd1b642

Please sign in to comment.