-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (58 loc) · 1.98 KB
/
Copy pathMakefile
File metadata and controls
70 lines (58 loc) · 1.98 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
.PHONY: all \
vet fmt version release test \
push-container clean gomod \
frontend-build
DOCKER_PLATFORMS=linux/amd64,linux/arm64
VERSION=$(shell cat version.txt)
TAG?=$(VERSION)
REGISTRY?=docker.io/llaoj
PKG:=github.com/llaoj/gcopy
GCOPY_IMAGE_REPO:=$(REGISTRY)/gcopy
CGO_ENABLED:=0
OS_ARCHS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
STATIC_DIR=internal/static/dist
# Frontend build output directory for Go embed
STATIC_DIR=internal/static/dist
version:
@echo $(VERSION)
cd frontend && npm version $(VERSION) --allow-same-version && npm run prettier && cd ..
frontend-build:
rm -rf $(STATIC_DIR)
cd frontend && npm ci && npm run build
cp -r frontend/out $(STATIC_DIR)
vet:
go vet ./...
fmt:
gofmt -s -w -l $(shell find . -type f -name '*.go' -not -path './vendor/*')
cd frontend && npm run prettier && cd ..
test: vet fmt
go test -timeout=1m -v -race -short ./...
bin/gcopy: frontend-build
@for os_arch in $(OS_ARCHS); do \
os=$${os_arch%%/*}; \
arch=$${os_arch##*/}; \
echo "Building bin/gcopy-$(VERSION)-$$os-$$arch ..."; \
CGO_ENABLED=$(CGO_ENABLED) GOOS=$$os GOARCH=$$arch go build \
-o bin/gcopy-$(VERSION)-$$os-$$arch \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
./cmd; \
done
push-container: clean
docker buildx create --platform $(DOCKER_PLATFORMS) --use
docker buildx build --push --platform $(DOCKER_PLATFORMS) --build-arg VERSION=$(VERSION) -t $(GCOPY_IMAGE_REPO):$(TAG) -t $(GCOPY_IMAGE_REPO):latest -f build/Dockerfile .
clean:
rm -rf bin/
rm -rf $(STATIC_DIR)
rm -f coverage.out
gomod:
go mod tidy
go mod vendor
go mod verify
release:
@if [ -z "$(NEW_VERSION)" ]; then echo "Usage: make release NEW_VERSION=vX.Y.Z"; exit 1; fi
@echo $(NEW_VERSION) > version.txt
$(MAKE) version
git add version.txt frontend/package.json frontend/package-lock.json
git commit -m "release $(NEW_VERSION)"
git tag -a $(NEW_VERSION) -m "$(NEW_VERSION)"
@echo "Created tag $(NEW_VERSION). Push with: git push origin main --tags"