1
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
helium-blockchain-exporter/Makefile

103 lines
2.3 KiB
Makefile
Raw Normal View History

2021-09-12 14:17:31 +00:00
PROGRAM := helium-blockchain-exporter
TARGET_DIR := ./bin
VERSION := $(shell git describe --tags --always)
SRC := $(shell find -name '*.go' -not -name '*_test.go' -type f)
BIN := $(TARGET_DIR)/$(PROGRAM)
# tests
ALL_SRC := $(shell find -name '*.go' -type f)
COVER_PROFILE := $(TARGET_DIR)/coverage.out
COVER_REPORT := $(TARGET_DIR)/coverage.html
# go
GO := go
GOFMT := $(GO) fmt
GORUN := $(GO) run -race
GOCLEAN := $(GO) clean
GOTEST := $(GO) test
GOCOVER := $(GO) tool cover
GOBUILD := $(GO) build
# docker
DOCKER := docker
DOCKERBUILD := $(DOCKER) build
DOCKERTAG := $(DOCKER) tag
DOCKERPUSH := $(DOCKER) push
DOCKER_TAGS := $(PROGRAM):$(VERSION)
.PHONY: all
all: build
.PHONY: help
help:
@echo "clean revert back to clean state"
@echo "lint lint and format the code"
@echo "prepare prepare environment for build"
@echo "test build and run short test suite"
@echo "coverage build and run full test suite and generate coverage report"
@echo "build build the binary"
2021-09-25 19:09:40 +00:00
@echo "dist build the binary for release"
@echo "docker build the docker image"
2021-09-12 14:17:31 +00:00
# clean: revert back to initial state
.PHONY: clean
clean:
$(GOCLEAN)
2021-09-25 19:09:40 +00:00
rm -r $(TARGET_DIR) || true
2021-09-12 14:17:31 +00:00
# lint: lint and format the code
.PHONY: lint
lint:
$(GOFMT) ./...
# prepare: prepare environment for build
$(TARGET_DIR):
mkdir $(TARGET_DIR) &>/dev/null || true
.PHONY: prepare
prepare: $(TARGET_DIR)
# test: run short test suite
.PHONY: test
test: lint
$(GOTEST) -short ./...
# coverage: run full test suite with coverage report
$(COVER_PROFILE): $(TARGET_DIR) $(ALL_SRC)
$(GOTEST) -coverprofile=$(COVER_PROFILE) ./...
$(COVER_REPORT): $(TARGET_DIR) $(COVER_PROFILE)
$(GOCOVER) -html=$(COVER_PROFILE) -o=$(COVER_REPORT)
.PHONY: coverage
coverage: lint $(COVER_REPORT)
$(GOCOVER) -func=$(COVER_PROFILE)
2021-09-25 19:09:40 +00:00
# build: build the program
2021-09-12 14:17:31 +00:00
$(BIN): $(TARGET_DIR) $(SRC)
2021-09-25 19:09:40 +00:00
$(GOBUILD) -o=$(BIN) -race
2021-09-12 14:17:31 +00:00
.PHONY: build
build: lint $(BIN)
2021-09-25 19:09:40 +00:00
# dist: build the program for release
.PHONY: dist
dist: $(TARGET_DIR) $(SRC)
$(GOBUILD) -o=$(BIN) -a -ldflags "-linkmode external -extldflags -static"
# docker: build the docker image
2021-09-12 14:17:31 +00:00
2021-09-25 19:09:40 +00:00
.PHONY: docker
docker: $(BIN)
2021-09-12 14:17:31 +00:00
$(DOCKERBUILD) -t $(PROGRAM) .
$(foreach tag,$(DOCKER_TAGS),$(DOCKERTAG) $(PROGRAM) $(tag);)