-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
203 lines (170 loc) · 6.78 KB
/
Makefile
File metadata and controls
203 lines (170 loc) · 6.78 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
# Copyright 2022 Snyk Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# project variables
PROJECT_NAME := snyk-ls
# build variables
.DEFAULT_GOAL = test
BUILD_DIR := build
DEV_GOARCH := $(shell go env GOARCH)
DEV_GOOS := $(shell go env GOOS)
GOPATH := $(shell go env GOPATH)
GOROOT := $(shell go env GOROOT)
VERSION := $(shell git show -s --format=%cd --date=format:%Y%m%d.%H%M%S)
COMMIT := $(shell git show -s --format=%h)
LDFLAGS_DEV := "-X 'github.com/snyk/snyk-ls/application/config.Development=true' -X 'github.com/snyk/snyk-ls/application/config.Version=v$(VERSION)-SNAPSHOT-$(COMMIT)'"
TOOLS_BIN := $(shell pwd)/.bin
OVERRIDE_GOCI_LINT_V := v2.9.0
GOLICENSES_V := v1.6.0
PACT_V := 2.4.2
TIMEOUT := "-timeout=45m"
## tools: Install required tooling.
.PHONY: tools
tools: $(TOOLS_BIN)/go-licenses $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/pact/bin/pact
.PHONY: hooks
hooks:
@pre-commit install
@pre-commit install --hook-type pre-push
$(TOOLS_BIN)/go-licenses:
@echo "==> Installing go-licenses"
@GOBIN=$(TOOLS_BIN) go install github.com/google/go-licenses@$(GOLICENSES_V)
$(TOOLS_BIN)/golangci-lint:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(OVERRIDE_GOCI_LINT_V)/install.sh | sh -s -- -b $(TOOLS_BIN)/ $(OVERRIDE_GOCI_LINT_V)
$(TOOLS_BIN)/pact/bin/pact:
cd $(TOOLS_BIN); curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/v$(PACT_V)/install.sh | PACT_CLI_VERSION=v$(PACT_V) bash
## clean: Delete the build directory
.PHONY: clean
clean:
@echo "==> Removing '$(BUILD_DIR)' directory..."
@rm -rf $(BUILD_DIR)
## lint: Lint code with golangci-lint.
.PHONY: lint
lint: $(TOOLS_BIN)/golangci-lint
@echo "==> Linting code with 'golangci-lint'..."
@$(TOOLS_BIN)/golangci-lint run ./...
## lint: Lint code with golangci-lint.
.PHONY: lint-fix
lint-fix: $(TOOLS_BIN)/golangci-lint
@echo "==> Linting and fixing code with 'golangci-lint'..."
@go fmt ./...
@$(TOOLS_BIN)/golangci-lint run --fix ./...
.PHONY: format
format: lint-fix
@echo "==> Formatting code..."
## test: Run all tests.
.PHONY: test
test: test-js
@echo "==> Running unit tests..."
@mkdir -p $(BUILD_DIR)
go test $(TIMEOUT) -failfast -cover -coverprofile=$(BUILD_DIR)/coverage.out ./...
## test-js: Run all JavaScript tests (tree view + config dialog) and check ES5 compatibility.
.PHONY: test-js
test-js: tree-view-fixture config-dialog-fixture
@echo "==> Running JS tests..."
@cd js-tests && npm install --ignore-scripts && npm test
@echo "==> Linting JS for ES5 compatibility..."
@cd js-tests && npm run lint:es5
.PHONY: race-test
race-test:
@echo "==> Running integration tests with race-detector..."
@mkdir -p $(BUILD_DIR)
@export INTEG_TESTS=true
@export SMOKE_TESTS=true
go test $(TIMEOUT) -race -failfast ./...
.PHONY: proxy-test
proxy-test:
@echo "==> Running integration tests with proxy"
@docker build -t "snyk-ls:$(VERSION)" -f .github/docker-based-tests/Dockerfile .
@docker run --rm --cap-add=NET_ADMIN --name "snyk-ls" --env "SNYK_TOKEN=$(SNYK_TOKEN)" snyk-ls:$(VERSION) make instance-test
instance-test:
@echo "==> Running instance tests"
export SMOKE_TESTS=1 && cd application/server && go test $(TIMEOUT) -failfast -run Test_SmokeInstanceTest && cd -
@curl -sSL https://static.snyk.io/eclipse/stable/p2.index
## tree-view-fixture: Regenerate tree view HTML fixture used by JS tests.
.PHONY: tree-view-fixture
tree-view-fixture:
@echo "==> Generating tree view HTML fixture..."
@mkdir -p js-tests/fixtures
@go run scripts/tree-view/main.go > js-tests/fixtures/tree-view.html
@echo " Written to js-tests/fixtures/tree-view.html"
## config-dialog-fixture: Regenerate config dialog HTML fixture used by JS tests.
.PHONY: config-dialog-fixture
config-dialog-fixture:
@echo "==> Generating config dialog HTML fixture..."
@mkdir -p js-tests/fixtures
@go run scripts/config-dialog/main.go -no-panel > js-tests/fixtures/config-page.html
@echo " Written to js-tests/fixtures/config-page.html"
## generate: Regenerate generated files (e.g. mocks).
.PHONY: generate
generate:
@echo "==> Generating generated files..."
@go generate ./...
## build: Build binary for default local system's OS and architecture.
.PHONY: build
build:
@echo "==> Building binary..."
@echo " running go build for GOOS=$(DEV_GOOS) GOARCH=$(DEV_GOARCH)"
# workaround for missing .exe extension on Windows
ifeq ($(OS),Windows_NT)
@go build -o $(BUILD_DIR)/$(PROJECT_NAME).$(DEV_GOOS).$(DEV_GOARCH).exe \
-ldflags=$(LDFLAGS_DEV)
else
@go build -o $(BUILD_DIR)/$(PROJECT_NAME).$(DEV_GOOS).$(DEV_GOARCH) \
-ldflags=$(LDFLAGS_DEV)
endif
## build-debug: Build binary for debugging
.PHONY: build-debug
build-debug:
@make clean
@echo "==> Building binary..."
@echo " running go build with debug flags"
ifeq ($(OS),Windows_NT)
@go build -o $(BUILD_DIR)/$(PROJECT_NAME).exe \
-ldflags=$(LDFLAGS_DEV) \
-gcflags="all=-N -l"
else
@go build -o $(BUILD_DIR)/$(PROJECT_NAME) \
-ldflags=$(LDFLAGS_DEV)
-gcflags="all=-N -l"
endif
.PHONY: build-release
build-release: $(TOOLS_BIN)/go-licenses
@LICENSES=$(make licenses) goreleaser release --clean --snapshot
## run: Compile and run LSP server.
.PHONY: run
run:
@echo "==> Running Snyk LS server..."
@go run main.go --reportErrors
.PHONY: install
install:
@echo "==> Installing binary..."
@go install -ldflags=$(LDFLAGS_DEV)
.PHONY: license-update
license-update: $(TOOLS_BIN)/go-licenses
@echo "==> Updating license information..."
@# TODO - Find a better solution to prevent the deletion of manually added license files.
@mkdir -p 'licenses_temp/github.com/brianblakely/nodep-date-input-polyfill'
@mv 'licenses/github.com/brianblakely/nodep-date-input-polyfill/LICENSE' 'licenses_temp/github.com/brianblakely/nodep-date-input-polyfill/LICENSE'
@rm -rf 'licenses'
@GOROOT=$(GOROOT) $(TOOLS_BIN)/go-licenses save . --save_path="licenses" --ignore "github.com/snyk/snyk-ls"
@mkdir -p 'licenses/github.com/brianblakely/nodep-date-input-polyfill'
@mv 'licenses_temp/github.com/brianblakely/nodep-date-input-polyfill/LICENSE' 'licenses/github.com/brianblakely/nodep-date-input-polyfill/LICENSE'
@rm -rf 'licenses_temp'
.PHONY: licenses
licenses: $(TOOLS_BIN)/go-licenses
@GOROOT=$(GOROOT) $(TOOLS_BIN)/go-licenses report . --ignore github.com/snyk/snyk-ls
help: Makefile
@echo "Usage: make <command>"
@echo ""
@echo "Commands:"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'