generated from block/oss-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathJustfile
More file actions
76 lines (63 loc) · 2.24 KB
/
Justfile
File metadata and controls
76 lines (63 loc) · 2.24 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
set positional-arguments := true
set shell := ["bash", "-c"]
# Import modules
mod docker
# Configuration
VERSION := `git describe --tags --always --dirty 2>/dev/null || echo "dev"`
GIT_COMMIT := `git rev-parse HEAD 2>/dev/null || echo "unknown"`
TAG := `git rev-parse --short HEAD 2>/dev/null || echo "dev"`
RELEASE := "dist"
GOARCH := env("GOARCH", `go env GOARCH`)
GOOS := env("GOOS", `go env GOOS`)
_help:
@just -l
# Run tests
test:
@gotestsum --hide-summary output,skipped --format-hide-empty-pkg ${CI:+--format=github-actions} ./... ${CI:+--tags=integration} -race -timeout 60s
# Lint code
lint:
golangci-lint run
actionlint
# Format code
fmt:
just --unstable --fmt
git ls-files | grep '\.go$' | xargs gosimports -local github.com/block -w
git ls-files | grep '\.go$' | xargs dirname | uniq | sed 's,^,./,' | xargs go fmt
go mod tidy
# ============================================================================
# Build
# ============================================================================
# Build for current platform
build GOOS=(GOOS) GOARCH=(GOARCH):
#!/usr/bin/env bash
set -euo pipefail
mkdir -p {{ RELEASE }}
for binary in cachew cachewd; do
echo "⏲ Building dist/$binary-{{ GOOS }}-{{ GOARCH }}"
CGO_ENABLED=0 GOOS={{ GOOS }} GOARCH={{ GOARCH }} \
go build -trimpath -o {{ RELEASE }}/${binary}-{{ GOOS }}-{{ GOARCH }} \
-ldflags "-s -w -X main.version={{ VERSION }} -X main.gitCommit={{ GIT_COMMIT }}" \
./cmd/${binary}
test "{{ GOOS }}-{{ GOARCH }}" = "$(go env GOOS)-$(go env GOARCH)" && (cd {{ RELEASE }} && ln -sf ${binary}-{{ GOOS }}-{{ GOARCH }} ${binary})
echo "✓ Done"
done
# Build all platforms
build-all:
@mkdir -p {{ RELEASE }}
@echo "Building all platforms..."
just build darwin arm64
just build darwin amd64
just build linux arm64
just build linux amd64
@echo "✓ Built all platforms"
# ============================================================================
# Run
# ============================================================================
# Run dev server with hot reload
dev:
@proctor
# Clean up build artifacts
clean:
@echo "Cleaning..."
@rm -rf {{ RELEASE }}
@echo "✓ Cleaned"