-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
44 lines (37 loc) · 1.25 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
DOCKER_IMAGE ?= dnesting/sense-exporter
DOCKER_TAG ?= latest
DATE=$(shell TZ=UTC date +"%Y-%m-%dT%H:%M:%SZ")
TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
VERSION := $(TAG:v%=%)
ifneq ($(COMMIT), $(TAG_COMMIT))
VERSION := $(VERSION)-next-$(COMMIT)-$(DATE)
endif
ifeq ($(VERSION),)
VERSION := $(COMMIT)-$(DATE)
endif
ifneq ($(shell git status --porcelain),)
VERSION := $(VERSION)-dirty
endif
all: write-version docker-build docker-push
write-version:
@echo "package main" >cmd/sense-exporter/version.go
@echo "const (" >>cmd/sense-exporter/version.go
@echo " Version = \"$(VERSION)\"" >>cmd/sense-exporter/version.go
@echo " BuildDate = \"$(DATE)\"" >>cmd/sense-exporter/version.go
@echo ")" >>cmd/sense-exporter/version.go
@echo "// cmd/sense-exporter/version.go"
@cat cmd/sense-exporter/version.go
.PHONY: docker-build
docker-build:
docker buildx build \
--push \
--platform linux/arm/v7,linux/arm64/v8,linux/amd64 \
-t $(DOCKER_IMAGE):$(DOCKER_TAG) \
.
docker-push:
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
test:
go test -v ./...