-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
161 lines (133 loc) · 5.36 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
DEV_CONTAINER_TAG:=ghcr.io/lawrencegripper/azbrowse/devcontainer:latest
DEV_CONTAINER_SNAPBASE_TAG:=ghcr.io/lawrencegripper/azbrowse/snapbase:latest
-include .env
# Used to override with richgo for colorized test output
GO_BINARY?=go
.PHONY: checks test build fail
## ----------Targets------------
## all:
## Default action - check, test and build
all: ci
## help:
## Show this help
help : Makefile
@sed -n 's/^##//p' $<
## test-go:
## Run short go unit tests
test-go:
$(GO_BINARY) test -mod=vendor ./...
## test-python
## Run python tests, mostly used for swagger gen
test-python: swagger-update-requirements
$(HOME)/.local/bin/pytest ./scripts/swagger_update/test_swagger_update.py
## test:
## Run all tests
test: test-go test-python
## checks:
## Check/lint code
checks:
golangci-lint run
## build:
## Build azbrowse binary
build:
$(GO_BINARY) build -mod=vendor ./cmd/azbrowse
## ci:
## Build lint and check
ci: swagger-codegen checks test build
## debug:
## Starts azbrowse using Delve ready for debugging from VSCode.
debug:
dlv debug ./cmd/azbrowse --headless --listen localhost:2345 --api-version 2 -- ${ARGS}
## debug-fuzzer:
## Starts azbrowse using Delve ready for debugging from VSCode and running the fuzzer.
debug-fuzzer:
dlv debug ./cmd/azbrowse --headless --listen localhost:2345 --api-version 2 -- -fuzzer 5
## dcterminal
## Starts an interactive terminal running inside the devcontainer
dcterminal:
docker exec -it -w /workspaces/azbrowse azbdev /bin/bash
## fmt:
## Format code
fmt:
find . -name '*.go' | grep -v vendor | xargs gofmt -s -w
## run:
## Quick command to lint and then launch azbrowse
run: install
azbrowse --debug
## fuzz-from:
## Runs azbrowse fuzzer which browses resource attempting to find problems
fuzz: checks install
azbrowse --fuzzer 5
## fuzz:
## Runs azbrowse fuzzer which browses resource attempting to find problems
## Accepts `node_id=/some/path/here` to start at a certain location in subscriptions
fuzz-from: checks install
azbrowse --fuzzer 5 --navigate ${node_id}
## install:
## Build and install azbrowse on this machine
install:
$(GO_BINARY) install -mod=vendor ./cmd/azbrowse
## ----------Advanced Targets------------
## docs-update:
## Generate the docs for the command line
docs-update: install
AZB_GEN_COMMAND_MARKDOWN=TRUE azbrowse
## swagger-update:
## Download the latest swagger definitions for Azure services and filter to the latest versions
swagger-update: swagger-update-requirements
python3 ./scripts/swagger_update/app.py
swagger-update-requirements:
pip3 install -q -r scripts/swagger_update/requirements.txt
## swagger-codegen:
## Generate the code needed for browse services from the swagger definitions
## set VERBOSE=true to see full output
swagger-codegen:
export GO111MODULE=on
$(GO_BINARY) run -mod=vendor ./cmd/swagger-codegen/
# Format the generated code
gofmt -s -w internal/pkg/expanders/swagger-armspecs.generated.go
gofmt -s -w internal/pkg/expanders/search.generated.go
gofmt -s -w internal/pkg/expanders/databricks.generated.go
# Build the generated go files to check for any go build issues
$(GO_BINARY) build -mod=vendor internal/pkg/expanders/swagger-armspecs.generated.go internal/pkg/expanders/swagger-armspecs.go internal/pkg/expanders/swagger.go internal/pkg/expanders/types.go internal/pkg/expanders/test_utils.go
# Test the generated code initalizes
$(GO_BINARY) test -mod=vendor -v internal/pkg/expanders/swagger-armspecs_test.go internal/pkg/expanders/swagger-armspecs.generated.go internal/pkg/expanders/swagger-armspecs.go internal/pkg/expanders/swagger.go internal/pkg/expanders/types.go
## swagger-create-pr
## Generate the code needed for browse services from the swagger definitions
## set VERBOSE=true to see full output
swagger-create-pr: swagger_update swagger-codegen
git checkout -b auto/arm-update-$(shell date +%s)
git add .
git commit -m "🧹 Update ARM Specs $(shell date --iso=date)"
git push
gh pr create --fill --base main
## autocomplete-install:
## Add autocompletion for azbrowse to your bash prompt
autocomplete-install: install
echo 'source <(azbrowse completion bash)' >> ~/.bashrc
echo "Create a new shell and autocomplete will be working"
## autocomplete-test:
## Invoke autocompletion for subscriptions and time the result
autocomplete-test: install
@/bin/bash -c "time azbrowse __complete --subscription LG"
@/bin/bash -c "time azbrowse __complete --navigate /"
## autocomplete-clear:
## Invoke autocompletion for subscriptions and time the result
autocomplete-clear:
rm ~/.azbrowse/*
## selfupdate-test:
## Launches AzBrowse with a low version number to allow testing of the self-update feature
selfupdate-test:
$(GO_BINARY) install -mod=vendor -i -ldflags "-X main.version=0.0.1-testupdate" ./cmd/azbrowse
AZBROWSE_FORCE_UPDATE=true azbrowse
## local-ci
## Run CI from inside a devcontainer or codespace, the build won't be published but the same process will be followed as PR builds
local-ci:
./scripts/local-ci.sh
## devcontainer-local-ci
## Run CI from outside a devcontainer on a box with docker and the devcontainer/cli installed https://github.com/devcontainers/cli/
devcontainer-local-ci:
# Run 'npm install -g @devcontainers/cli' to install the CLI
devcontainer up --workspace-folder ${PWD}
devcontainer run-user-commands --workspace-folder ${PWD}
devcontainer exec --workspace-folder ${PWD} '/workspaces/azbrowse/scripts/local-ci.sh'