-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
137 lines (109 loc) · 3.99 KB
/
justfile
File metadata and controls
137 lines (109 loc) · 3.99 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
app := "gnverifier"
org := "github.com/gnames/"
test_opts := "-count=1 -p 1 -shuffle=on -coverprofile=coverage.txt -covermode=atomic"
build_dir := "bin/"
release_dir := "/tmp/"
no_c := "CGO_ENABLED=0"
x86 := "GOARCH=amd64"
arm := "GOARCH=arm64"
linux := "GOOS=linux"
mac := "GOOS=darwin"
win := "GOOS=windows"
version := `git describe --tags 2>/dev/null || echo "dev"`
ver := `git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.1"`
date := `date -u '+%Y-%m-%d_%H:%M:%S%Z'`
# Colors
green := `tput -Txterm setaf 2`
yellow := `tput -Txterm setaf 3`
white := `tput -Txterm setaf 7`
cyan := `tput -Txterm setaf 6`
reset := `tput -Txterm sgr0`
# LD flags with version and build date
flags_ld := "-trimpath -ldflags '-X " + org + app + \
"/pkg/sf.Build=" + date + " -X " + org + app + \
"/pkg/sf.Version=" + version + "'"
flags_rel := "-trimpath -ldflags '-s -w -X " + org + app + \
"/pkg/sf.Build=" + date + "'"
default: install
# Show this help
help:
@echo ''
@echo 'Usage:'
@echo ' {{yellow}}just{{reset}} {{green}}<target>{{reset}}'
@echo ''
@echo 'Targets:'
@just --list --unsorted
# Display current version
version:
@echo {{version}}
# Clean up and sync dependencies
tidy:
@go mod tidy
@go mod verify
# Install tools
tools: tidy
@go install tool
@echo "✅ tools of the project are installed"
# Download dependencies
deps:
@echo "Download go.mod dependencies"
go mod download
# Build binary
build:
@mkdir -p {{build_dir}}
{{no_c}} go build -o {{build_dir}}{{app}} {{flags_ld}}
@echo "✅ {{app}} built to {{build_dir}}{{app}}"
# Build binary without debug info and with hardcoded version
buildrel:
@mkdir -p {{build_dir}}
{{no_c}} go build -o {{build_dir}}{{app}} {{flags_rel}}
@echo "✅ {{app}} release binary built to {{build_dir}}{{app}}"
# Build and install binary
install:
{{no_c}} go install {{flags_ld}}
@echo "✅ {{app}} installed to ~/go/bin/{{app}}"
# Build and package binaries for a release
release: buildrel dockerhub
@echo "Building releases for Linux, Mac, Windows (Intel and Arm)"
{{no_c}} {{linux}} {{x86}} go build {{flags_rel}} -o {{release_dir}}{{app}}
tar zcvf {{release_dir}}{{app}}-{{version}}-linux-amd64.tar.gz {{release_dir}}{{app}}
rm {{release_dir}}{{app}}
{{no_c}} {{linux}} {{arm}} go build {{flags_rel}} -o {{release_dir}}{{app}}
tar zcvf {{release_dir}}{{app}}-{{version}}-linux-arm64.tar.gz {{release_dir}}{{app}}
rm {{release_dir}}{{app}}
{{no_c}} {{mac}} {{x86}} go build {{flags_rel}} -o {{release_dir}}{{app}}
tar zcvf {{release_dir}}{{app}}-{{version}}-mac-amd64.tar.gz {{release_dir}}{{app}}
rm {{release_dir}}{{app}}
{{no_c}} {{mac}} {{arm}} go build {{flags_rel}} -o {{release_dir}}{{app}}
tar zcvf {{release_dir}}{{app}}-{{version}}-mac-arm64.tar.gz {{release_dir}}{{app}}
rm {{release_dir}}{{app}}
{{no_c}} {{win}} {{x86}} go build {{flags_rel}} -o {{release_dir}}{{app}}.exe
cd {{release_dir}} && zip -9 {{app}}-{{version}}-win-amd64.zip {{app}}.exe
rm {{release_dir}}{{app}}.exe
{{no_c}} {{win}} {{arm}} go build {{flags_rel}} -o {{release_dir}}{{app}}.exe
cd {{release_dir}} && zip -9 {{app}}-{{version}}-win-arm64.zip {{app}}.exe
rm {{release_dir}}{{app}}.exe
@echo "✅ Release binaries created in {{release_dir}}"
# Build Docker images
docker: build
@echo "Build Docker images"
docker buildx build -t gnames/{{app}}:latest -t gnames/{{app}}:{{version}} .
# Push Docker images to DockerHub
dockerhub: docker
@echo "Push Docker images to DockerHub"
docker push gnames/{{app}}
docker push gnames/{{app}}:{{version}}
# Lint the code
lint:
golangci-lint run
# Run tests
test: deps install
@echo "Run tests"
go test {{test_opts}} ./...
# Run tests with race detector
test-race: deps install
go test -count=1 -race ./...
# Run tests and export coverage
coverage: deps install
@go test -p 1 -cover -covermode=count -coverprofile=profile.cov ./...
@go tool cover -func profile.cov