-
Notifications
You must be signed in to change notification settings - Fork 51
/
Makefile
70 lines (60 loc) · 2.12 KB
/
Makefile
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
COMMIT := $(shell git rev-parse --short=7 HEAD 2>/dev/null)
VERSION := $(shell git describe --abbrev=0 HEAD 2>/dev/null)
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
ifeq ($(strip $(shell git status --porcelain 2>/dev/null)),)
GIT_TREE_STATE=clean
else
GIT_TREE_STATE=dirty
endif
REPO=planetscale
NAME=pscale
BUILD_PKG=github.com/planetscale/cli/cmd/pscale
GORELEASE_CROSS_VERSION ?= v1.23.2
SYFT_VERSION ?= 1.9.0
.PHONY: all
all: build test lint
.PHONY: test
test:
@go test ./...
.PHONY: build
build:
@go build -trimpath ./...
.PHONY: lint
lint:
@go install honnef.co/go/tools/cmd/staticcheck@HEAD
@staticcheck ./...
@go vet ./...
.PHONY: build-image
build-image:
@echo "==> Building docker image ${REPO}/${NAME}:$(VERSION)"
@# Permit building only if the Git tree is clean
@echo "${GIT_TREE_STATE}" | grep -Eq "^clean" || ( echo "Git tree state is not clean"; exit 1 )
@docker build --build-arg VERSION=$(VERSION:v%=%) --build-arg COMMIT=$(COMMIT) --build-arg DATE=$(DATE) -t ${REPO}/${NAME}:$(VERSION) .
@docker tag ${REPO}/${NAME}:$(VERSION) ${REPO}/${NAME}:latest
.PHONY: push
push:
@# Permit releasing only if VERSION adheres to semver.
@echo "${VERSION}" | grep -Eq "^v[0-9]+\.[0-9]+\.[0-9]+$$" || ( echo "VERSION \"${VERSION}\" does not adhere to semver"; exit 1 )
@echo "==> Pushing docker image ${REPO}/${NAME}:$(VERSION)"
@docker push ${REPO}/${NAME}:latest
@docker push ${REPO}/${NAME}:$(VERSION)
@echo "==> Your image is now available at $(REPO)/${NAME}:$(VERSION)"
.PHONY: clean
clean:
@echo "==> Cleaning artifacts"
@rm ${NAME}
.PHONY: release
release:
@docker build --build-arg GORELEASE_CROSS_VERSION=$(GORELEASE_CROSS_VERSION) --build-arg SYFT_VERSION=$(SYFT_VERSION) -t releaser -f docker/Dockerfile.goreleaser .
@docker run \
--rm \
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
-e AUR_KEY \
-e GORELEASER_CURRENT_TAG=${GORELEASER_CURRENT_TAG} \
-e DOCKER_CREDS_FILE=${DOCKER_CREDS_FILE} \
-v ${DOCKER_CREDS_FILE}:${DOCKER_CREDS_FILE} \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/${REPO}/${NAME} \
-w /go/src/${REPO}/${NAME} \
releaser \
release --clean ${GORELEASER_EXTRA_ARGS}