-
Notifications
You must be signed in to change notification settings - Fork 6
/
.justfile
90 lines (69 loc) · 3.07 KB
/
.justfile
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
set dotenv-load := true
dev_dir := join(justfile_directory(), "hack", "dev")
genmocks_dir := join(justfile_directory(), "test", "mocks")
genpb_dir := join(justfile_directory(), "genpb")
tools_mod_dir := join(justfile_directory(), "tools")
export TOOLS_BIN_DIR := join(env_var_or_default("XDG_CACHE_HOME", join(env_var("HOME"), ".cache")), "cerbos-cloud-api/bin")
default:
@ just --list
compile:
@ go build ./... && go test -tags=tests,integration -run=ignore ./... > /dev/null
cover PKG='./...' TEST='.*': _cover
#!/usr/bin/env bash
set -euo pipefail
COVERFILE="$(mktemp -t cloud-api-XXXXX)"
trap 'rm -rf "$COVERFILE"' EXIT
go test -tags=tests,integration -coverprofile="$COVERFILE" -count=1 -run='{{ TEST }}' '{{ PKG }}'
"${TOOLS_BIN_DIR}/cover" -p "$COVERFILE"
generate: generate-proto-code generate-mocks
generate-mocks QUIET='--quiet': _mockery
#!/usr/bin/env bash
set -euo pipefail
cd {{ justfile_directory() }}
rm -rf {{ genmocks_dir }}
"${TOOLS_BIN_DIR}/mockery" {{ QUIET }}
generate-proto-code: _buf
#!/usr/bin/env bash
set -euo pipefail
cd {{ justfile_directory() }}
"${TOOLS_BIN_DIR}/buf" format -w
rm -rf {{ genpb_dir }}
(
cd {{ tools_mod_dir }}
"${TOOLS_BIN_DIR}/buf" generate --template=buf.gen.yaml --output=..
)
lint: _golangcilint _buf
@ "${TOOLS_BIN_DIR}/golangci-lint" run --config=.golangci.yaml --fix
@ "${TOOLS_BIN_DIR}/buf" lint
@ "${TOOLS_BIN_DIR}/buf" format --diff --exit-code
pre-commit: generate lint tests
test PKG='./...' TEST='.*':
@ go test -v -tags=tests,integration -failfast -cover -count=1 -run='{{ TEST }}' '{{ PKG }}'
tests PKG='./...' TEST='.*': _gotestsum
@ "${TOOLS_BIN_DIR}/gotestsum" --format=dots-v2 --format-hide-empty-pkg -- -tags=tests,integration -failfast -count=1 -run='{{ TEST }}' '{{ PKG }}'
# Executables
_buf: (_install "buf" "github.com/bufbuild/buf" "cmd/buf")
_cover: (_install "cover" "nikand.dev/go/cover@master" )
_golangcilint: (_install "golangci-lint" "github.com/golangci/golangci-lint" "cmd/golangci-lint")
_gotestsum: (_install "gotestsum" "gotest.tools/gotestsum")
_mockery: (_install "mockery" "github.com/vektra/mockery/v2")
_install EXECUTABLE MODULE CMD_PKG="":
#!/usr/bin/env bash
set -euo pipefail
cd {{ tools_mod_dir }}
TMP_VERSION=$(GOWORK=off go list -m -f "{{{{.Version}}" "{{ MODULE }}")
VERSION="${TMP_VERSION#v}"
BINARY="${TOOLS_BIN_DIR}/{{ EXECUTABLE }}"
SYMLINK="${BINARY}-${VERSION}"
if [[ ! -e "$SYMLINK" ]]; then
echo "Installing $SYMLINK" 1>&2
mkdir -p "$TOOLS_BIN_DIR"
find "${TOOLS_BIN_DIR}" -lname "$BINARY" -delete
if [[ "{{ EXECUTABLE }}" == "golangci-lint" ]]; then
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$TOOLS_BIN_DIR"
else
export CGO_ENABLED={{ if EXECUTABLE =~ "(^sql|^tbls)" { "1" } else { "0" } }}
GOWORK=off GOBIN="$TOOLS_BIN_DIR" go install {{ if CMD_PKG != "" { MODULE + "/" + CMD_PKG } else { MODULE } }}
fi
ln -s "$BINARY" "$SYMLINK"
fi