This repository has been archived by the owner on Feb 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
146 lines (111 loc) · 4.92 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
DIST_DIR ?= dist/
GOOS ?= $(shell uname -s | tr "[:upper:]" "[:lower:]")
ARCH ?= $(shell uname -m)
ifeq ($(ARCH),x86_64)
GOARCH := amd64
else
GOARCH := $(ARCH) # no idea if this works for other platforms....
endif
BUILDINFOSDET ?=
PROGRAM_ARGS ?=
PROJECT_VERSION := 0.1.4
DOCKER_REPO := synfinatic
PROJECT_NAME := onelogin-aws-role
PROJECT_TAG := $(shell git describe --tags 2>/dev/null $(git rev-list --tags --max-count=1))
ifeq ($(PROJECT_TAG),)
PROJECT_TAG := NO-TAG
endif
PROJECT_COMMIT := $(shell git rev-parse HEAD)
ifeq ($(PROJECT_COMMIT),)
PROJECT_COMMIT := NO-CommitID
endif
PROJECT_DELTA := $(shell DELTA_LINES=$$(git diff | wc -l); if [ $${DELTA_LINES} -ne 0 ]; then echo $${DELTA_LINES} ; else echo "''" ; fi)
VERSION_PKG := $(shell echo $(PROJECT_VERSION) | sed 's/^v//g')
LICENSE := GPLv3
URL := https://github.com/$(DOCKER_REPO)/$(PROJECT_NAME)
DESCRIPTION := OneLogin Go AWS Assume Role
BUILDINFOS := $(shell date +%FT%T%z)$(BUILDINFOSDET)
HOSTNAME := $(shell hostname)
LDFLAGS := -X "main.Version=$(PROJECT_VERSION)" -X "main.Delta=$(PROJECT_DELTA)" -X "main.Buildinfos=$(BUILDINFOS)" -X "main.Tag=$(PROJECT_TAG)" -X "main.CommitID=$(PROJECT_COMMIT)"
OUTPUT_NAME := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-$(GOOS)-$(GOARCH) # default for current platform
# supported platforms for `make release`
WINDOWS_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-windows-amd64.exe
WINDOWS32_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-windows-386.exe
LINUX_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-linux-amd64
LINUXARM64_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-linux-arm64
DARWIN_BIN := $(DIST_DIR)$(PROJECT_NAME)-$(PROJECT_VERSION)-darwin-amd64
ALL: $(OUTPUT_NAME) ## Build binary. Needs to be a supported plaform as defined above
include help.mk # place after ALL target and before all other targets
build-release: windows windows32 linux linux-arm64 darwin ## Build all our release binaries
release: clean build-release
cd dist && shasum -a 256 * | gpg --clear-sign >release.sig
.PHONY: run
run: cmd/*.go ## build and run cria using $PROGRAM_ARGS
go run cmd/*.go $(PROGRAM_ARGS)
clean-all: clean ## clean _everything_
clean: ## Remove all binaries in dist
rm -f dist/*
clean-go: ## Clean Go cache
go clean -i -r -cache -modcache
go-get: ## Get our go modules
go get -v all
.PHONY: build-race
build-race: .prepare ## Build race detection binary
go build -race -ldflags='$(LDFLAGS)' -o $(OUTPUT_NAME) cmd/*.go
debug: .prepare ## Run debug in dlv
dlv debug cmd/*.go
.PHONY: unittest
unittest: ## Run go unit tests
go test ./...
.PHONY: test-race
test-race: ## Run `go test -race` on the code
@echo checking code for races...
go test -race ./...
.PHONY: vet
vet: ## Run `go vet` on the code
@echo checking code is vetted...
go vet $(shell go list ./...)
test: vet unittest ## Run all tests
$(DIST_DIR):
@if test ! -d $(DIST_DIR); then mkdir -p $(DIST_DIR) ; fi
.PHONY: fmt
fmt: ## Format Go code
@go fmt cmd
.PHONY: test-fmt
test-fmt: fmt ## Test to make sure code if formatted correctly
@if test `git diff cmd | wc -l` -gt 0; then \
echo "Code changes detected when running 'go fmt':" ; \
git diff -Xfiles ; \
exit -1 ; \
fi
.PHONY: test-tidy
test-tidy: ## Test to make sure go.mod is tidy
@go mod tidy
@if test `git diff go.mod | wc -l` -gt 0; then \
echo "Need to run 'go mod tidy' to clean up go.mod" ; \
exit -1 ; \
fi
precheck: test test-fmt test-tidy ## Run all tests that happen in a PR
# Build targets for our supported plaforms
windows: $(WINDOWS_BIN) ## Build 64bit Windows binary
$(WINDOWS_BIN): $(wildcard */*.go) $(DIST_DIR)
GOARCH=amd64 GOOS=windows go build -ldflags='$(LDFLAGS)' -o $(WINDOWS_BIN) cmd/*.go
@echo "Created: $(WINDOWS_BIN)"
windows32: $(WINDOWS32_BIN) ## Build 32bit Windows binary
$(WINDOWS32_BIN): cmd/*.go $(DIST_DIR)
GOARCH=386 GOOS=windows go build -ldflags='$(LDFLAGS)' -o $(WINDOWS32_BIN) cmd/*.go
@echo "Created: $(WINDOWS32_BIN)"
linux: $(LINUX_BIN) ## Build Linux/x86_64 binary
$(LINUX_BIN): cmd/*.go $(DIST_DIR)
GOARCH=amd64 GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUX_BIN) cmd/*.go
@echo "Created: $(LINUX_BIN)"
linux-arm64: $(LINUXARM64_BIN) ## Build Linux/arm64 binary
$(LINUXARM64_BIN): cmd/*.go $(DIST_DIR)
GOARCH=arm64 GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUXARM64_BIN) cmd/*.go
@echo "Created: $(LINUXARM64_BIN)"
darwin: $(DARWIN_BIN) ## Build MacOS/x86_64 binary
$(DARWIN_BIN): $(wildcard */*.go) $(DIST_DIR)
GOARCH=amd64 GOOS=darwin go build -ldflags='$(LDFLAGS)' -o $(DARWIN_BIN) cmd/*.go
@echo "Created: $(DARWIN_BIN)"
workflow.png: workflow.dot
dot -oworkflow.png -Tpng workflow.dot