Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. GOFLAGS := CGO_ENABLED=0
  52. download:
  53. $Q go mod download
  54. build: $(PREFIX)bin/$(BINNAME)
  55. @echo "Build Complete!"
  56. $(PREFIX)bin/$(BINNAME): download $(call rwildcard,*.go)
  57. $Q mkdir -p $(@D)
  58. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
  59. # Target to force a build of step-ca without running tests
  60. simple: build
  61. .PHONY: download build simple
  62. #########################################
  63. # Go generate
  64. #########################################
  65. generate:
  66. $Q go generate ./...
  67. .PHONY: generate
  68. #########################################
  69. # Test
  70. #########################################
  71. test:
  72. $Q $(GOFLAGS) gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
  73. testcgo:
  74. $Q gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
  75. .PHONY: test testcgo
  76. integrate: integration
  77. integration: bin/$(BINNAME)
  78. $Q $(GOFLAGS) gotestsum -- -tags=integration ./integration/...
  79. .PHONY: integrate integration
  80. #########################################
  81. # Linting
  82. #########################################
  83. fmt:
  84. $Q goimports -l -w $(SRC)
  85. lint: SHELL:=/bin/bash
  86. lint:
  87. $Q LOG_LEVEL=error golangci-lint run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
  88. $Q govulncheck ./...
  89. .PHONY: fmt lint
  90. #########################################
  91. # Install
  92. #########################################
  93. INSTALL_PREFIX?=/usr/
  94. install: $(PREFIX)bin/$(BINNAME)
  95. $Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
  96. uninstall:
  97. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
  98. .PHONY: install uninstall
  99. #########################################
  100. # Clean
  101. #########################################
  102. clean:
  103. ifneq ($(BINNAME),"")
  104. $Q rm -f bin/$(BINNAME)
  105. endif
  106. .PHONY: clean
  107. #########################################
  108. # Dev
  109. #########################################
  110. run:
  111. $Q go run cmd/step-ca/main.go $(shell step path)/config/ca.json
  112. .PHONY: run