1all: build
 2
 3GIT_COMMIT:=$(shell git rev-list -1 HEAD)
 4GIT_LAST_TAG:=$(shell git describe --abbrev=0 --tags 2>/dev/null || true)
 5GIT_EXACT_TAG:=$(shell git name-rev --name-only --tags HEAD)
 6UNAME_S := $(shell uname -s)
 7XARGS:=xargs -r
 8ifeq ($(UNAME_S),Darwin)
 9    XARGS:=xargs
10endif
11
12SYSTEM=$(shell nix eval --impure --expr 'builtins.currentSystem' --raw 2>/dev/null || echo '')
13
14COMMANDS_PATH:=github.com/git-bug/git-bug/commands
15LDFLAGS:=-X ${COMMANDS_PATH}.GitCommit="${GIT_COMMIT}" \
16	-X ${COMMANDS_PATH}.GitLastTag="${GIT_LAST_TAG}" \
17	-X ${COMMANDS_PATH}.GitExactTag="${GIT_EXACT_TAG}"
18
19.PHONY: list-checks
20list-checks:
21	@if test -z "$(SYSTEM)"; then echo "unable to detect system. is nix installed?" && exit 1; fi
22	@printf "Available checks for $(SYSTEM) (run all with \`nix flake check\`):\n"
23	@nix flake show --json 2>/dev/null |\
24		dasel -r json -w plain '.checks.x86_64-linux.keys().all()' |\
25		xargs -I NAME printf '\t%-20s %s\n' "NAME" "nix build .#checks.linux.NAME"
26
27.PHONY: build
28build:
29	go generate
30	go build -ldflags "$(LDFLAGS)" .
31
32# produce a debugger-friendly build
33.PHONY: build/debug
34build/debug:
35	go generate
36	go build -ldflags "$(LDFLAGS)" -gcflags=all="-N -l" .
37
38.PHONY: install
39install:
40	go generate
41	go install -ldflags "$(LDFLAGS)" .
42
43.PHONY: releases
44releases:
45	go generate
46	go run github.com/mitchellh/gox@v1.0.1 -ldflags "$(LDFLAGS)" -osarch '!darwin/386' -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}"
47
48.PHONY: secure
49secure:
50	go run golang.org/x/vuln/cmd/govulncheck ./...
51
52.PHONY: test
53test:
54	go test -v -bench=. ./...
55
56.PHONY: pack-webui
57pack-webui:
58	npm run --prefix webui build
59	go run webui/pack_webui.go
60
61# produce a build that will fetch the web UI from the filesystem instead of from the binary
62.PHONY: debug-webui
63debug-webui:
64	go build -ldflags "$(LDFLAGS)" -tags=debugwebui
65
66.PHONY: clean-local-bugs
67clean-local-bugs:
68	git for-each-ref refs/bugs/ | cut -f 2 | $(XARGS) -n 1 git update-ref -d
69	git for-each-ref refs/remotes/origin/bugs/ | cut -f 2 | $(XARGS) -n 1 git update-ref -d
70	rm -f .git/git-bug/bug-cache
71
72.PHONY: clean-remote-bugs
73clean-remote-bugs:
74	git ls-remote origin "refs/bugs/*" | cut -f 2 | $(XARGS) git push origin -d
75
76.PHONY: clean-local-identities
77clean-local-identities:
78	git for-each-ref refs/identities/ | cut -f 2 | $(XARGS) -n 1 git update-ref -d
79	git for-each-ref refs/remotes/origin/identities/ | cut -f 2 | $(XARGS) -n 1 git update-ref -d
80	rm -f .git/git-bug/identity-cache
81
82.PHONY: clean-local-identities
83clean-remote-identities:
84	git ls-remote origin "refs/identities/*" | cut -f 2 | $(XARGS) git push origin -d