-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
89 lines (70 loc) · 2.05 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
# This variable is overriden by `nix develop`
O11Y_NIX_SHELL_ENABLED ?= 0
# Command used to run inside a `nix develop` shell.
# HOME is needed for `go build`.
NIX_DEVELOP = nix --extra-experimental-features nix-command develop --extra-experimental-features flakes -i --keep HOME --keep DOCKER_USERNAME --keep DOCKER_PASSWORD --keep DOCKER_REGISTRY --keep DOCKER_REPOSITORY --keep DOCKER_TAG_SUFFIX --keep DOCKER_ORG
# Docker settings
export DOCKER_ORG ?= o11y
export DOCKER_PASSWORD ?= none
export DOCKER_REGISTRY ?= quay.io
export DOCKER_REPOSITORY ?= oy-toolkit
export DOCKER_TAG_SUFFIX ?=
export DOCKER_USERNAME ?= none
# This is true if we are in `nix develop` shell.
ifeq ($(O11Y_NIX_SHELL_ENABLED),1)
all: lint build
# Human friendly way of running tests.
.PHONY: test
test: lint
@gotestsum ./...
# Build runs tests, we do not need to explicitely add test as a dependency.
.PHONY: build
build: oy-toolkit
.PHONY: fmt
fmt:
@gofumpt -l -w --extra .
@goimports -w -local github.com/o11ydev/oy-toolkit .
@alejandra -q *.nix
.PHONY: lint
lint:
@golangci-lint run
@alejandra -q --check *.nix
oy-%: rebuild
@echo ">> Building oy-$*"
@nix build ".#oy-$*"
.PHONY: tidy
tidy:
@go mod tidy -compat=1.17 -go=1.17
# Shortcut to force running go build each time.
.PHONY: rebuild
rebuild:
.PHONY: publish-script
publish-script:
@echo ">> Creating publishing script"
@nix build ".#publish-script" -o ./publish.sh
.PHONY: publish
publish: publish-script
@echo ">> Running publishing script"
@bash -eu ./publish.sh
.PHONY: documentation
documentation:
@echo ">> Generating documentation"
@nix build ".#documentation" -o ./documentation
.PHONY: packages
packages:
@echo ">> Generating packages"
@nix build ".#nfpmPackages"
.PHONY: vendorhash
vendorhash:
@go mod tidy -compat=1.21 -go=1.21
@sed -i '/vendorSha256/s@".*"@"$(shell go mod vendor && nix hash path vendor)"@' packages.nix
@rm -r vendor
# If we are not in a `nix develop` shell, automatically run into it.
else
default:
@$(NIX_DEVELOP) -c $(MAKE)
%:
@$(NIX_DEVELOP) -c $(MAKE) $*
shell:
@$(NIX_DEVELOP)
endif