-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
138 lines (102 loc) · 3.18 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
# Makefile for fredy project
#
# Set the default shell
SHELL := bash
# Where I am
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# Variables used during the installation
PREFIX ?= /usr/local
PROJECT_NAME := fredy
INSTALL_DIR = $(DESTDIR)$(PREFIX)/share/$(PROJECT_NAME)
BIN_DIR = $(DESTDIR)$(PREFIX)/bin
# Get script version
APP_VERSION := $(shell ./bin/fredy --version)
# Get VCS latest tag
VCS_VERSION := $(shell git describe --abbrev=0 --tags)
# Only release from this branch
VCS_MAIN_BRANCH := main
# Get the current branch
VCS_BRANCH := $(shell git branch --show-current)
# Test if we are inside the main branch
ifeq ($(VCS_BRANCH),$(VCS_MAIN_BRANCH))
VCS_IS_MAIN_BRANCH := 1
else
VCS_IS_MAIN_BRANCH := 0
endif
# Our image name
DOCKER_IMG := galantelab/fredy
# Set latest or dev to docker image accordig
# to the branch
DOCKER_TAG := $(if $(VCS_IS_MAIN_BRANCH),latest,dev)
.DEFAULT_GOAL := help
.PHONY: help
help:
@echo "Makefile for fredy project"
@echo ""
@echo "==> Installation"
@echo "install Install fredy"
@echo "uninstall Uninstall fredy"
@echo ""
@echo "==> Manage git"
@echo "git-check-status Check if the wordir is dirty"
@echo "git-check-version Check if there is a new version"
@echo "git-check-branch Check if this is the main branch"
@echo "git-check Check status, version and branch"
@echo "git-tag Tag the new version"
@echo "git-release Release the new tagged version"
@echo ""
@echo "==> Manage docker"
@echo "docker-build Build a docker image"
@echo "docker-tag Tag the docker image version"
@echo "docker-release Push docker image to registry"
@echo ""
.PHONY: install
install:
mkdir -p $(INSTALL_DIR) $(BIN_DIR)
cp -r --preserve=mode $(ROOT_DIR)/{bin,lib,scripts} $(INSTALL_DIR)
ln -s $(INSTALL_DIR)/bin/* $(BIN_DIR)
.PHONY: uninstall
uninstall:
rm -rf $(INSTALL_DIR)
rm -f $(addprefix $(BIN_DIR)/, $(notdir $(wildcard $(ROOT_DIR)/bin/*)))
.PHONY: git-release
git-release: git-check git-tag
git push
git push origin $(APP_VERSION)
.PHONY: git-tag
git-tag:
git tag -a $(APP_VERSION) -m 'Version $(APP_VERSION)'
.PHONY: git-check-branch
git-check-branch:
@if [[ "$(VCS_IS_MAIN_BRANCH)" -eq 1 ]]; then \
echo I only release from $(VCS_MAIN_BRANCH); \
echo Use 'git checkout $(VCS_MAIN_BRANCH)' before release; \
fi
.PHONY: git-check
git-check: git-check-status git-check-version git-check-branch
.PHONY: git-check-version
git-check-version:
@if [[ "$(APP_VERSION)" == "$(VCS_VERSION)" ]]; then \
echo There is already a git tag for the version $(APP_VERSION); \
false; \
fi
.PHONY: git-check-status
git-check-status:
@if git status --porcelain | grep -qE '^ *[M?]+'; then \
echo The working tree is dirty or has untracked files; \
echo Use 'git status' for more details; \
false; \
fi
.PHONY: docker-release
docker-release: git-check docker-build docker-tag
docker login
docker push $(DOCKER_IMG):$(DOCKER_TAG)
docker push $(DOCKER_IMG):$(APP_VERSION)
docker logout
.PHONY: docker-tag
docker-tag:
docker tag $(DOCKER_IMG):$(DOCKER_TAG) $(DOCKER_IMG):$(APP_VERSION)
.PHONY: docker-build
docker-build:
docker build -t $(DOCKER_IMG):$(DOCKER_TAG) .