-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMakefile
More file actions
224 lines (167 loc) · 8.76 KB
/
Makefile
File metadata and controls
224 lines (167 loc) · 8.76 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
ifeq ($(OS),Windows_NT)
SHELL := pwsh
else
SHELL := /bin/bash
endif
.PHONY : check lint install-linters dep test test-e2e test-e2e-build test-e2e-run test-e2e-test test-e2e-stop test-e2e-clean build
VERSION := $(shell git describe --always)
RFC_3339 := "+%Y-%m-%dT%H:%M:%SZ"
COMMIT := $(shell git rev-list -1 HEAD)
ifeq ($(OS),Windows_NT)
BIN := .\bin
BIN_DIR?=.\bin
CMD_DIR := .\cmd
DATE := $(shell powershell -Command date -u ${RFC_3339})
OPTS?=powershell -Command setx GO111MODULE on;
.DEFAULT_GOAL := help-windows
else
BIN := ${PWD}/bin
BIN_DIR?=./bin
CMD_DIR := ./cmd
DATE := $(shell date -u ${RFC_3339})
OPTS?=GO111MODULE=on
.DEFAULT_GOAL := help
endif
TEST_OPTS:=-v -tags no_ci -cover -timeout=5m
RACE_FLAG:=-race
GOARCH:=$(shell go env GOARCH)
ifneq (,$(findstring 64,$(GOARCH)))
TEST_OPTS:=$(TEST_OPTS) $(RACE_FLAG)
endif
DMSG_REPO := github.com/skycoin/dmsg
SKYWIRE_UTILITIES_BASE := github.com/skycoin/skywire/pkg/skywire-utilities
BUILDINFO_PATH := $(SKYWIRE_UTILITIES_BASE)/pkg/buildinfo
BUILDINFO_VERSION := -X $(BUILDINFO_PATH).version=$(VERSION)
BUILDINFO_DATE := -X $(BUILDINFO_PATH).date=$(DATE)
BUILDINFO_COMMIT := -X $(BUILDINFO_PATH).commit=$(COMMIT)
BUILDINFO?=$(BUILDINFO_VERSION) $(BUILDINFO_DATE) $(BUILDINFO_COMMIT)
BUILD_OPTS?=-mod=vendor "-ldflags=$(BUILDINFO)"
BUILD_OPTS_DEPLOY?=-mod=vendor "-ldflags=$(BUILDINFO) -w -s"
check: lint test ## Run linters and tests
check-windows: lint test-windows ## Run linters and tests on windows
lint: ## Run linters. Use make install-linters first
golangci-lint version
${OPTS} golangci-lint run -c .golangci.yml ./cmd/...
${OPTS} golangci-lint run -c .golangci.yml ./pkg/...
${OPTS} golangci-lint run -c .golangci.yml ./internal/...
${OPTS} golangci-lint run -c .golangci.yml ./...
${OPTS} golangci-lint run -c .golangci.yml .
vendorcheck: ## Run vendorcheck
GO111MODULE=off vendorcheck ./...
test: ## Run tests
-go clean -testcache &>/dev/null
${OPTS} go test ${TEST_OPTS} ./...
test-e2e-build: ## Build Docker images for e2e tests
cd docker && docker compose -f docker-compose.e2e.yml build
test-e2e-run: ## Start e2e test environment
cd docker && docker compose -f docker-compose.e2e.yml up -d
@echo "Waiting for services to be ready..."
sleep 15
test-e2e-test: ## Run e2e tests (requires e2e-run)
-go clean -testcache
go test -v -timeout=10m ./internal/e2e/...
test-e2e-stop: ## Stop e2e environment
cd docker && docker compose -f docker-compose.e2e.yml stop
test-e2e-clean: ## Stop and remove e2e environment
cd docker && docker compose -f docker-compose.e2e.yml down -v
test-e2e: test-e2e-build test-e2e-run test-e2e-test test-e2e-stop ## Run complete e2e test suite
test-windows: ## Run tests
-go clean -testcache
${OPTS} go test ${TEST_OPTS} ./...
install-linters: ## Install linters
# GO111MODULE=off go get -u github.com/FiloSottile/vendorcheck
# For some reason this install method is not recommended, see https://github.com/golangci/golangci-lint#install
# However, they suggest `curl ... | bash` which we should not do
${OPTS} go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
${OPTS} go install golang.org/x/tools/cmd/goimports@latest
${OPTS} go install github.com/incu6us/goimports-reviser@latest
install-linters-windows: ## Install linters on windows
${OPTS} go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
${OPTS} go install golang.org/x/tools/cmd/goimports@latest
${OPTS} go install github.com/incu6us/goimports-reviser@latest
format: ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters).
${OPTS} goimports -w -local ${DMSG_REPO} ./pkg ./cmd ./internal ./examples
find . -type f -name '*.go' -not -path "./.git/*" -not -path "./vendor/*" -exec goimports-reviser -project-name ${DMSG_REPO} {} \;
format-windows: ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters-windows).
powershell -Command .\scripts\format-windows.ps1
dep: ## Sorts dependencies
${OPTS} go mod vendor -v
${OPTS} go mod tidy -v
install: ## Install `dmsg-discovery`, `dmsg-server`, `dmsgcurl`,`dmsgpty-cli`, `dmsgpty-host`, `dmsgpty-ui`
${OPTS} go install ${BUILD_OPTS} ./cmd/*
build: ## Build binaries into ./bin
mkdir -p ${BIN}; go build ${BUILD_OPTS} -o ${BIN} ${CMD_DIR}/*
build-windows: ## Build binaries into ./bin
powershell -Command new-item ${BIN} -itemtype directory -force
powershell 'Get-ChildItem ${CMD_DIR} | % { go build ${BUILD_OPTS} -o ${BIN} $$_.FullName }'
build-deploy: ## Build for deployment Docker images
go build -tags netgo ${BUILD_OPTS_DEPLOY} -o /release/dmsg-discovery ./cmd/dmsg-discovery
go build -tags netgo ${BUILD_OPTS_DEPLOY} -o /release/dmsg-server ./cmd/dmsg-server
build-docker:
./docker/scripts/docker-push.sh -t "develop" -b
github-prepare-release:
$(eval GITHUB_TAG=$(shell git describe --abbrev=0 --tags | cut -c 2-6))
sed '/^## ${GITHUB_TAG}$$/,/^## .*/!d;//d;/^$$/d' ./CHANGELOG.md > releaseChangelog.md
github-release: github-prepare-release
goreleaser --clean --config .goreleaser-linux.yml --release-notes releaseChangelog.md
github-release-darwin:
goreleaser --clean --config .goreleaser-darwin.yml --skip=publish
$(eval GITHUB_TAG=$(shell git describe --abbrev=0 --tags))
gh release upload --repo skycoin/dmsg ${GITHUB_TAG} ./dist/dmsg-${GITHUB_TAG}-darwin-amd64.tar.gz
gh release upload --repo skycoin/dmsg ${GITHUB_TAG} ./dist/dmsg-${GITHUB_TAG}-darwin-arm64.tar.gz
gh release download ${GITHUB_TAG} --repo skycoin/dmsg --pattern 'checksums*'
cat ./dist/checksums.txt >> ./checksums.txt
gh release upload --repo skycoin/dmsg ${GITHUB_TAG} --clobber ./checksums.txt
github-release-windows:
.\goreleaser\goreleaser.exe --clean --config .goreleaser-windows.yml --skip=publish
$(eval GITHUB_TAG=$(shell powershell git describe --abbrev=0 --tags))
gh release upload --repo skycoin/dmsg ${GITHUB_TAG} ./dist/dmsg-${GITHUB_TAG}-windows-amd64.zip
gh release upload --repo skycoin/dmsg ${GITHUB_TAG} ./dist/dmsg-${GITHUB_TAG}-windows-386.zip
gh release download ${GITHUB_TAG} --repo skycoin/dmsg --pattern 'checksums*'
cat ./dist/checksums.txt >> ./checksums.txt
gh release upload --repo skycoin/dmsg ${GITHUB_TAG} --clobber ./checksums.txt
dep-github-release:
mkdir musl-data
wget -c https://more.musl.cc/10/x86_64-linux-musl/aarch64-linux-musl-cross.tgz -O aarch64-linux-musl-cross.tgz
tar -xzf aarch64-linux-musl-cross.tgz -C ./musl-data && rm aarch64-linux-musl-cross.tgz
wget -c https://more.musl.cc/10/x86_64-linux-musl/arm-linux-musleabi-cross.tgz -O arm-linux-musleabi-cross.tgz
tar -xzf arm-linux-musleabi-cross.tgz -C ./musl-data && rm arm-linux-musleabi-cross.tgz
wget -c https://more.musl.cc/10/x86_64-linux-musl/arm-linux-musleabihf-cross.tgz -O arm-linux-musleabihf-cross.tgz
tar -xzf arm-linux-musleabihf-cross.tgz -C ./musl-data && rm arm-linux-musleabihf-cross.tgz
wget -c https://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-cross.tgz -O x86_64-linux-musl-cross.tgz
tar -xzf x86_64-linux-musl-cross.tgz -C ./musl-data && rm x86_64-linux-musl-cross.tgz
snapshot-linux: snapshot-clean
goreleaser --snapshot --config .goreleaser-linux.yml --skip-publish --rm-dist
snapshot-darwin: snapshot-clean
goreleaser --snapshot --config .goreleaser-darwin.yml --skip-publish --rm-dist
snapshot-windows: snapshot-clean
goreleaser --snapshot --config .goreleaser-windows.yml --skip-publish --rm-dist
snapshot-clean: ## Cleans snapshot / release
rm -rf ./dist
start-db: ## Init local database env.
source ./integration/env.sh && init_redis
stop-db: ## Stop local database env.
source ./integration/env.sh && stop_redis
attach-db: ## Attach local database env.
source ./integration/env.sh && attach_redis
start-dmsg: build ## Init local dmsg env.
source ./integration/env.sh && init_dmsg
stop-dmsg: ## Stop local dmsg env.
source ./integration/env.sh && stop_dmsg
attach-dmsg: ## Attach local dmsg tmux session.
source ./integration/env.sh && attach_dmsg
start-pty: build ## Init local dmsgpty env.
source ./integration/env.sh && init_dmsgpty
stop-pty: ## Stop local dmsgpty env.
source ./integration/env.sh && stop_dmsgpty
attach-pty: ## Attach local dmsgpty tmux session.
source ./integration/env.sh && attach_dmsgpty
stop-all: stop-pty stop-dmsg stop-db ## Stop all local tmux sessions.
integration-windows-start: ## Start integration test on windows.
powershell -Command .\integration\integration.ps1 start
integration-windows-stop: ## Stops integration test on windows.
powershell -Command .\integration\integration.ps1 stop
help: ## Display help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
help-windows: ## Display help for windows
@powershell 'Select-String -Pattern "windows[a-zA-Z_-]*:.*## .*$$" $(MAKEFILE_LIST) | % { $$_.Line -split ":.*?## " -Join "`t:`t" } '