4
0

Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. $(PREFIX)bin/$(BINNAME): download $(call rwildcard,*.go)
  72. $Q mkdir -p $(@D)
  73. $Q $(GOOS_OVERRIDE) GOFLAGS="$(GOFLAGS)" $(GO_ENVS) go build -v -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
  74. # Target to force a build of step-ca without running tests
  75. simple: build
  76. .PHONY: download build simple
  77. #########################################
  78. # Go generate
  79. #########################################
  80. generate:
  81. $Q go generate ./...
  82. .PHONY: generate
  83. #########################################
  84. # Test
  85. #########################################
  86. test: testdefault testtpmsimulator combinecoverage
  87. testdefault:
  88. $Q $(GO_ENVS) gotestsum -- -coverprofile=defaultcoverage.out -short -covermode=atomic ./...
  89. testtpmsimulator:
  90. $Q CGO_ENABLED=1 gotestsum -- -coverprofile=tpmsimulatorcoverage.out -short -covermode=atomic -tags tpmsimulator ./acme
  91. testcgo:
  92. $Q gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
  93. combinecoverage:
  94. cat defaultcoverage.out tpmsimulatorcoverage.out > coverage.out
  95. .PHONY: test testdefault testtpmsimulator testcgo combinecoverage
  96. integrate: integration
  97. integration: bin/$(BINNAME)
  98. $Q $(GO_ENVS) gotestsum -- -tags=integration ./integration/...
  99. .PHONY: integrate integration
  100. #########################################
  101. # Linting
  102. #########################################
  103. fmt:
  104. $Q goimports -l -w $(SRC)
  105. lint: SHELL:=/bin/bash
  106. lint:
  107. $Q LOG_LEVEL=error golangci-lint run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
  108. $Q govulncheck ./...
  109. .PHONY: fmt lint
  110. #########################################
  111. # Install
  112. #########################################
  113. INSTALL_PREFIX?=/usr/
  114. install: $(PREFIX)bin/$(BINNAME)
  115. $Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
  116. uninstall:
  117. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
  118. .PHONY: install uninstall
  119. #########################################
  120. # Clean
  121. #########################################
  122. clean:
  123. ifneq ($(BINNAME),"")
  124. $Q rm -f bin/$(BINNAME)
  125. endif
  126. .PHONY: clean
  127. #########################################
  128. # Dev
  129. #########################################
  130. run:
  131. $Q go run cmd/step-ca/main.go $(shell step path)/config/ca.json
  132. .PHONY: run