Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. OUTPUT_ROOT=output/
  9. RELEASE=./.releases
  10. all: lint test build
  11. ci: testcgo build
  12. .PHONY: all ci
  13. #########################################
  14. # Bootstrapping
  15. #########################################
  16. bootstra%:
  17. $Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin latest
  18. $Q go install golang.org/x/vuln/cmd/govulncheck@latest
  19. $Q go install gotest.tools/gotestsum@latest
  20. .PHONY: bootstra%
  21. #################################################
  22. # Determine the type of `push` and `version`
  23. #################################################
  24. # If TRAVIS_TAG is set then we know this ref has been tagged.
  25. ifdef TRAVIS_TAG
  26. VERSION ?= $(TRAVIS_TAG)
  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. # GITHUB Actions
  34. else ifdef GITHUB_REF
  35. VERSION ?= $(shell echo $(GITHUB_REF) | sed 's/^refs\/tags\///')
  36. NOT_RC := $(shell echo $(VERSION) | grep -v -e -rc)
  37. ifeq ($(NOT_RC),)
  38. PUSHTYPE := release-candidate
  39. else
  40. PUSHTYPE := release
  41. endif
  42. else
  43. VERSION ?= $(shell [ -d .git ] && git describe --tags --always --dirty="-dev")
  44. # If we are not in an active git dir then try reading the version from .VERSION.
  45. # .VERSION contains a slug populated by `git archive`.
  46. VERSION := $(or $(VERSION),$(shell ./.version.sh .VERSION))
  47. ifeq ($(TRAVIS_BRANCH),master)
  48. PUSHTYPE := master
  49. else
  50. PUSHTYPE := branch
  51. endif
  52. endif
  53. VERSION := $(shell echo $(VERSION) | sed 's/^v//')
  54. DEB_VERSION := $(shell echo $(VERSION) | sed 's/-/./g')
  55. ifdef V
  56. $(info TRAVIS_TAG is $(TRAVIS_TAG))
  57. $(info GITHUB_REF is $(GITHUB_REF))
  58. $(info VERSION is $(VERSION))
  59. $(info DEB_VERSION is $(DEB_VERSION))
  60. $(info PUSHTYPE is $(PUSHTYPE))
  61. endif
  62. #########################################
  63. # Build
  64. #########################################
  65. DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
  66. LDFLAGS := -ldflags='-w -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
  67. GOFLAGS := CGO_ENABLED=0
  68. download:
  69. $Q go mod download
  70. build: $(PREFIX)bin/$(BINNAME)
  71. @echo "Build Complete!"
  72. $(PREFIX)bin/$(BINNAME): download $(call rwildcard,*.go)
  73. $Q mkdir -p $(@D)
  74. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
  75. # Target to force a build of step-ca without running tests
  76. simple: build
  77. .PHONY: download build simple
  78. #########################################
  79. # Go generate
  80. #########################################
  81. generate:
  82. $Q go generate ./...
  83. .PHONY: generate
  84. #########################################
  85. # Test
  86. #########################################
  87. test:
  88. $Q $(GOFLAGS) gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
  89. testcgo:
  90. $Q gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
  91. .PHONY: test testcgo
  92. integrate: integration
  93. integration: bin/$(BINNAME)
  94. $Q $(GOFLAGS) gotestsum -- -tags=integration ./integration/...
  95. .PHONY: integrate integration
  96. #########################################
  97. # Linting
  98. #########################################
  99. fmt:
  100. $Q goimports -l -w $(SRC)
  101. lint: SHELL:=/bin/bash
  102. lint:
  103. $Q LOG_LEVEL=error golangci-lint run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
  104. $Q govulncheck ./...
  105. .PHONY: fmt lint
  106. #########################################
  107. # Install
  108. #########################################
  109. INSTALL_PREFIX?=/usr/
  110. install: $(PREFIX)bin/$(BINNAME)
  111. $Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
  112. uninstall:
  113. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
  114. .PHONY: install uninstall
  115. #########################################
  116. # Clean
  117. #########################################
  118. clean:
  119. ifneq ($(BINNAME),"")
  120. $Q rm -f bin/$(BINNAME)
  121. endif
  122. .PHONY: clean
  123. #########################################
  124. # Dev
  125. #########################################
  126. run:
  127. $Q go run cmd/step-ca/main.go $(shell step path)/config/ca.json
  128. .PHONY: run
  129. #########################################
  130. # Debian
  131. #########################################
  132. changelog:
  133. $Q echo "step-ca ($(DEB_VERSION)) unstable; urgency=medium" > debian/changelog
  134. $Q echo >> debian/changelog
  135. $Q echo " * See https://github.com/smallstep/certificates/releases" >> debian/changelog
  136. $Q echo >> debian/changelog
  137. $Q echo " -- Smallstep Labs, Inc. <techadmin@smallstep.com> $(shell date -uR)" >> debian/changelog
  138. debian: changelog
  139. $Q mkdir -p $(RELEASE); \
  140. OUTPUT=../step-ca*.deb; \
  141. rm $$OUTPUT; \
  142. dpkg-buildpackage -b -rfakeroot -us -uc && cp $$OUTPUT $(RELEASE)/
  143. distclean: clean
  144. .PHONY: changelog debian distclean