forked from terralist/terralist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yaml
92 lines (89 loc) · 3.33 KB
/
Taskfile.yaml
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
version: '3'
tasks:
build:
summary: "Build the Terralist binary."
silent: true
vars:
ARG:
sh: echo "{{default "release" .CLI_ARGS}}"
ARG_CHECKER:
sh: echo "{{has .ARG (list "debug" "release")}}"
MODE:
sh: echo "{{ternary .ARG "release" (eq .ARG_CHECKER "true")}}"
BRANCH:
sh: git rev-parse --abbrev-ref HEAD
COMMIT_HASH:
sh: git rev-parse --short HEAD
BINARY_FILE_NAME:
sh: echo '{{printf "terralist%s" (ternary ".exe" "" (eq OS "windows"))}}'
ALL_TAGS:
sh: git tag
LATEST_TAG: '{{splitList "\n" .ALL_TAGS | last}}'
TERRALIST_VERSION: "{{.LATEST_TAG}}-{{.BRANCH}}+{{.COMMIT_HASH}}"
env:
# Get rid of sqlite3 lib warnings
CGO_CFLAGS: "-g -O2 -Wno-return-local-addr"
TERRALIST_VERSION: "{{.TERRALIST_VERSION}}"
cmds:
- echo "[>] Installing web application dependencies."
- yarn --cwd ./web install
- echo "[>] Building web application."
- yarn --cwd ./web build
- >-
echo "{{
ternary
(printf "[>] Building in '%s' mode." .MODE)
(printf "[!] Build mode '%s' unknown, fallback to 'release' mode." .CLI_ARGS)
(eq .ARG_CHECKER "true")
}}"
- >-
go build \
-o={{.BINARY_FILE_NAME}} \
-v \
-ldflags="-X 'main.Version={{.TERRALIST_VERSION}}' \
-X 'main.CommitHash={{.COMMIT_HASH}}' \
-X 'main.BuildTimestamp={{now | date "2006-01-02T15:04:05"}}' \
-X 'main.Mode={{.MODE}}'" \
./cmd/terralist/main.go
- echo "[>] Executable wrote to '{{ .BINARY_FILE_NAME }}'."
generate-mocks:
summary: "Generate interface mocks."
silent: true
vars:
MOCKERY_ARGS: '--all --case underscore --note "go:build mocks"'
cmds:
- mockery --dir ./internal/server/services --output ./mocks/server/services {{.MOCKERY_ARGS}}
- mockery --dir ./internal/server/repositories --output ./mocks/server/repositories {{.MOCKERY_ARGS}}
- mockery --dir ./pkg/auth --output ./mocks/pkg/auth {{.MOCKERY_ARGS}}
- mockery --dir ./pkg/auth/jwt --output ./mocks/pkg/auth/jwt {{.MOCKERY_ARGS}}
- mockery --dir ./pkg/file --output ./mocks/pkg/file {{.MOCKERY_ARGS}}
- mockery --dir ./pkg/storage --output ./mocks/pkg/storage {{.MOCKERY_ARGS}}
run-tests:
summary: "Run all tests."
silent: true
vars:
WITH_SUMMARY: '{{eq .CLI_ARGS "summary"}}'
ALL_PACKAGES:
sh: "go list ./..."
TEST_EXCLUSIONS: '{{list "mocks" "cmd" "models" | join "|"}}'
TEST_PACKAGES:
sh: >-
{{- $excl := .TEST_EXCLUSIONS -}}
{{- $pkgs := (list) -}}
{{- range $i, $pkg := (splitList "\n" .ALL_PACKAGES) -}}
{{- if not (regexMatch (printf "[/]%s[/]" $excl) $pkg) -}}
{{- $pkgs = append $pkgs $pkg -}}
{{- end -}}
{{- end -}}
echo "{{$pkgs | join " "}}"
BUILD_TAGS: "mocks"
env:
# Get rid of sqlite3 lib warnings
CGO_CFLAGS: "-g -O2 -Wno-return-stack-address"
cmds:
- >-
{{- if eq .WITH_SUMMARY "true" -}}
gotestsum -f testname -- -tags={{.BUILD_TAGS}} -count=1 {{.TEST_PACKAGES}}
{{- else -}}
go test -tags=mocks -count=1 {{.TEST_PACKAGES}}
{{- end -}}