Makefile 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. PKG?=github.com/smallstep/certificates/cmd/step-ca
  2. BINNAME?=step-ca
  3. # Set V to 1 for verbose output from the Makefile
  4. Q=$(if $V,,@)
  5. PREFIX?=
  6. SRC=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
  7. GOOS_OVERRIDE ?=
  8. all: lint test build
  9. ci: testcgo build
  10. .PHONY: all ci
  11. #########################################
  12. # Bootstrapping
  13. #########################################
  14. bootstra%:
  15. $Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin latest
  16. $Q go install golang.org/x/vuln/cmd/govulncheck@latest
  17. $Q go install gotest.tools/gotestsum@latest
  18. $Q go install github.com/goreleaser/goreleaser@latest
  19. $Q go install github.com/sigstore/cosign/v2/cmd/cosign@latest
  20. .PHONY: bootstra%
  21. #################################################
  22. # Determine the type of `push` and `version`
  23. #################################################
  24. # GITHUB Actions
  25. ifdef GITHUB_REF
  26. VERSION ?= $(shell echo $(GITHUB_REF) | sed 's/^refs\/tags\///')
  27. NOT_RC := $(shell echo $(VERSION) | grep -v -e -rc)
  28. ifeq ($(NOT_RC),)
  29. PUSHTYPE := release-candidate
  30. else
  31. PUSHTYPE := release
  32. endif
  33. else
  34. VERSION ?= $(shell [ -d .git ] && git describe --tags --always --dirty="-dev")
  35. # If we are not in an active git dir then try reading the version from .VERSION.
  36. # .VERSION contains a slug populated by `git archive`.
  37. VERSION := $(or $(VERSION),$(shell ./.version.sh .VERSION))
  38. PUSHTYPE := branch
  39. endif
  40. VERSION := $(shell echo $(VERSION) | sed 's/^v//')
  41. ifdef V
  42. $(info GITHUB_REF is $(GITHUB_REF))
  43. $(info VERSION is $(VERSION))
  44. $(info PUSHTYPE is $(PUSHTYPE))
  45. endif
  46. #########################################
  47. # Build
  48. #########################################
  49. DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
  50. LDFLAGS := -ldflags='-w -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
  51. # Always explicitly enable or disable cgo,
  52. # so that go doesn't silently fall back on
  53. # non-cgo when gcc is not found.
  54. ifeq (,$(findstring CGO_ENABLED,$(GO_ENVS)))
  55. ifneq ($(origin GOFLAGS),undefined)
  56. # This section is for backward compatibility with
  57. #
  58. # $ make build GOFLAGS=""
  59. #
  60. # which is how we recommended building step-ca with cgo support
  61. # until June 2023.
  62. GO_ENVS := $(GO_ENVS) CGO_ENABLED=1
  63. else
  64. GO_ENVS := $(GO_ENVS) CGO_ENABLED=0
  65. endif
  66. endif
  67. download:
  68. $Q go mod download
  69. build: $(PREFIX)bin/$(BINNAME)
  70. @echo "Build Complete!"
  71. build-fips: $(PREFIX)bin/$(BINNAME).fips
  72. @echo "Build Complete!"
  73. $(PREFIX)bin/$(BINNAME): download $(call rwildcard,*.go)
  74. $Q mkdir -p $(@D)
  75. $Q $(GOOS_OVERRIDE) GOFLAGS="$(GOFLAGS)" $(GO_ENVS) go build -v -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
  76. $(PREFIX)bin/$(BINNAME).fips: download $(call rwildcard,*.go)
  77. $Q mkdir -p $(@D)
  78. $Q $(GOOS_OVERRIDE) GOFLAGS="$(GOFLAGS)" $(GO_ENVS) GOEXPERIMENT="boringcrypto" go build -v -o $(PREFIX)bin/$(BINNAME).fips $(LDFLAGS) $(PKG)
  79. # Target to force a build of step-ca without running tests
  80. simple: build
  81. .PHONY: download build simple
  82. #########################################
  83. # Go generate
  84. #########################################
  85. generate:
  86. $Q go generate ./...
  87. .PHONY: generate
  88. #########################################
  89. # Test
  90. #########################################
  91. test: testdefault testtpmsimulator combinecoverage
  92. testdefault:
  93. $Q $(GO_ENVS) gotestsum -- -coverprofile=defaultcoverage.out -short -covermode=atomic ./...
  94. testtpmsimulator:
  95. $Q CGO_ENABLED=1 gotestsum -- -coverprofile=tpmsimulatorcoverage.out -short -covermode=atomic -tags tpmsimulator ./acme
  96. testcgo:
  97. $Q gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
  98. combinecoverage:
  99. cat defaultcoverage.out tpmsimulatorcoverage.out > coverage.out
  100. .PHONY: test testdefault testtpmsimulator testcgo combinecoverage
  101. integrate: integration
  102. integration: bin/$(BINNAME)
  103. $Q $(GO_ENVS) gotestsum -- -tags=integration ./integration/...
  104. .PHONY: integrate integration
  105. #########################################
  106. # Linting
  107. #########################################
  108. fmt:
  109. $Q goimports -l -w $(SRC)
  110. lint: SHELL:=/bin/bash
  111. lint:
  112. $Q LOG_LEVEL=error golangci-lint run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
  113. $Q govulncheck ./...
  114. .PHONY: fmt lint
  115. #########################################
  116. # Install
  117. #########################################
  118. INSTALL_PREFIX?=/usr/
  119. install: $(PREFIX)bin/$(BINNAME)
  120. $Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
  121. uninstall:
  122. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
  123. .PHONY: install uninstall
  124. #########################################
  125. # Clean
  126. #########################################
  127. clean:
  128. ifneq ($(BINNAME),"")
  129. $Q rm -f bin/$(BINNAME)
  130. endif
  131. .PHONY: clean
  132. #########################################
  133. # Dev
  134. #########################################
  135. run:
  136. $Q go run cmd/step-ca/main.go $(shell step path)/config/ca.json
  137. .PHONY: run