Skip to content

Commit ed543b4

Browse files
authored
fix: Add a Makefile (#100)
I do not have time to be hunting build commands around, particularly those buried deep down in GitHub Action workflow files. This is very basic: build the thing. It tries to avoid rebuilding stuff if not necessary, but it's not perfect. Run `make clean && make build` if you switch versions. Signed-off-by: Marcelo E. Magallon <[email protected]>
1 parent a92f83c commit ed543b4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Makefile

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ROOTDIR := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
2+
GO_WORKSPACE := $(abspath $(dir $(filter-out off,$(shell go env GOWORK))))
3+
LOCAL_K6_VERSION := $(shell GOWORK=off go list -m go.k6.io/k6 | cut -d' ' -f2)
4+
WORKSPACE_K6_VERSION := $(shell go list -m go.k6.io/k6 | cut -d' ' -f2)
5+
# This is gross.
6+
GSM_API_GO_CLIENT_HASH := $(shell grep github.com/grafana/gsm-api-go-client@ .github/workflows/push-pr-release.yaml | sed -e 's,.*@,,; s,[^a-f0-9].*,,')
7+
GSM_API_GO_CLIENT := github.com/grafana/gsm-api-go-client@$(GSM_API_GO_CLIENT_HASH)
8+
9+
ifneq ($(strip $(GO_WORKSPACE)),)
10+
GSM_API_GO_CLIENT_DIR := $(abspath $(ROOTDIR)/../gsm-api-go-client)
11+
GSM_API_GO_CLIENT := github.com/grafana/gsm-api-go-client=$(GSM_API_GO_CLIENT_DIR)
12+
GSM_API_GO_CLIENT_SRCS := $(shell go list -json $(GSM_API_GO_CLIENT_DIR) | jq -r '.Dir as $$dir | .GoFiles[]? | [$$dir, .] | join("/")')
13+
endif
14+
15+
XK6_SM_SRCS := $(shell go list -json $(ROOTDIR) | jq -r '.Dir as $$dir | .GoFiles[]? | [$$dir, .] | join("/")')
16+
17+
.DEFAULT_GOAL := all
18+
19+
.PHONY: all
20+
all: build
21+
@echo "Done."
22+
23+
.PHONY: build
24+
build:
25+
@true
26+
27+
build: dist/k6
28+
dist/k6: $(XK6_SM_SRCS)
29+
@mkdir -p '$(dir $@)'
30+
xk6 build '$(LOCAL_K6_VERSION)' \
31+
--output '$@' \
32+
--with 'github.com/grafana/xk6-sm=$(ROOTDIR)'
33+
34+
ifeq ($(strip $(GO_WORKSPACE)),)
35+
# This is here to force a rebuild every time if we are using a remote gsm-api-go-client.
36+
.PHONY: dist/k6-gsm
37+
endif
38+
39+
build: dist/k6-gsm
40+
dist/k6-gsm: $(XK6_SM_SRCS)
41+
dist/k6-gsm: $(GSM_API_GO_CLIENT_SRCS)
42+
@mkdir -p '$(dir $@)'
43+
xk6 build '$(WORKSPACE_K6_VERSION)' \
44+
--output '$@' \
45+
--with 'github.com/grafana/xk6-sm=$(ROOTDIR)' \
46+
--with '$(GSM_API_GO_CLIENT)'
47+
48+
.PHONY: clean
49+
clean:
50+
rm -rf dist

0 commit comments

Comments
 (0)