-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
100 lines (83 loc) · 3.33 KB
/
Makefile
File metadata and controls
100 lines (83 loc) · 3.33 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
NAME := s5
FILES := $(shell git ls-files */*.go)
COVERAGE_FILE := coverage.out
REPOSITORY := mvisonneau/$(NAME)
GOLANGCI_LINT := go tool github.com/golangci/golangci-lint/v2/cmd/golangci-lint
GORELEASER := go tool github.com/goreleaser/goreleaser/v2
.DEFAULT_GOAL := help
.PHONY: fmt
fmt: ## Format source code
$(GOLANGCI_LINT) fmt -v
.PHONY: lint
lint: ## Run all lint related tests upon the codebase
$(GOLANGCI_LINT) run -v
.PHONY: test
test: ## Run the tests against the codebase
@rm -rf $(COVERAGE_FILE)
go test -v -count=1 -race ./... -coverprofile=$(COVERAGE_FILE)
@go tool cover -func $(COVERAGE_FILE) | awk '/^total/ {print "coverage: " $$3}'
.PHONY: coverage
coverage: ## Prints coverage report
go tool cover -func $(COVERAGE_FILE)
.PHONY: install
install: ## Build and install locally the binary (dev purpose)
go install ./cmd/$(NAME)
.PHONY: build
build: ## Build the binaries using local GOOS
go build ./cmd/$(NAME)
.PHONY: release
release: ## Build & release the binaries (stable)
mkdir -p ${HOME}/.cache/snapcraft/download
mkdir -p ${HOME}/.cache/snapcraft/stage-packages
git tag -d edge
$(GORELEASER) release --clean
find dist -type f -name "*.snap" -exec snapcraft upload --release stable,edge '{}' \;
.PHONY: prerelease
prerelease: ## Build & prerelease the binaries (edge)
@\
REPOSITORY=$(REPOSITORY) \
NAME=$(NAME) \
GITHUB_TOKEN=$(GITHUB_TOKEN) \
.github/prerelease.sh
.PHONY: clean
clean: ## Remove binary if it exists
rm -f $(NAME)
.PHONY: coverage-html
coverage-html: ## Generates coverage report and displays it in the browser
go tool cover -html=coverage.out
.PHONY: dev-env
dev-env: ## Build a local development environment using Docker
@docker run -d --cap-add IPC_LOCK --name vault vault:$(VAULT_VERSION)
@sleep 2
@docker exec -it \
-e VAULT_ADDR=http://localhost:8200 \
-e VAULT_TOKEN=$$(docker logs vault 2>/dev/null | grep 'Root Token' | cut -d' ' -f3 | sed -E "s/[[:cntrl:]]\[[0-9]{1,3}m//g") \
vault \
/bin/sh -c "vault secrets enable transit"
@docker run -it --rm \
-v $(shell pwd):/go/src/github.com/mvisonneau/$(NAME) \
-w /go/src/github.com/mvisonneau/$(NAME) \
-e VAULT_ADDR=http://$$(docker inspect vault | jq -r '.[0].NetworkSettings.IPAddress'):8200 \
-e VAULT_TOKEN=$$(docker logs vault 2>/dev/null | grep 'Root Token' | cut -d' ' -f3 | sed -E "s/[[:cntrl:]]\[[0-9]{1,3}m//g") \
-e S5_TRANSIT_KEY=foo \
goreleaser/goreleaser:v1.24.0 \
/bin/bash -c 'apk add --no-cache make; make setup; make install; bash'
@docker kill vault
@docker rm vault -f
.PHONY: is-git-dirty
is-git-dirty: ## Tests if git is in a dirty state
@git status --porcelain
@test $(shell git status --porcelain | grep -c .) -eq 0
.PHONY: autocomplete-scripts
autocomplete-scripts: ## Download CLI autocompletion scripts
rm -rf helpers/autocomplete
mkdir -p helpers/autocomplete
go run ./cmd/s5 completion bash > helpers/autocomplete/bash
go run ./cmd/s5 completion fish > helpers/autocomplete/fish
go run ./cmd/s5 completion pwsh > helpers/autocomplete/pwsh
go run ./cmd/s5 completion zsh > helpers/autocomplete/zsh
.PHONY: all
all: lint test build coverage ## Test, builds and ship package for all supported platforms
.PHONY: help
help: ## Displays this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'