forked from bryannice/gitactions-slack-notification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (71 loc) · 3.14 KB
/
Makefile
File metadata and controls
88 lines (71 loc) · 3.14 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
# -----------------------------------------------------------------------------
# GitActions Slack Notifications
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Internal Variables
# -----------------------------------------------------------------------------
BOLD :=$(shell tput bold)
RED :=$(shell tput setaf 1)
GREEN :=$(shell tput setaf 2)
YELLOW :=$(shell tput setaf 3)
RESET :=$(shell tput sgr0)
# -----------------------------------------------------------------------------
# Git Variables
# -----------------------------------------------------------------------------
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_REPOSITORY_NAME := $(shell git config --get remote.origin.url | rev | cut -d"." -f2 | cut -d"/" -f1 | rev )
GIT_ACCOUNT_NAME := $(shell git config --get remote.origin.url | rev | cut -d"." -f2 | cut -d"/" -f2 | cut -d":" -f1 | rev)
GIT_SHA := $(shell git log --pretty=format:'%H' -n 1)
GIT_TAG ?= $(shell git describe --always --tags | awk -F "-" '{print $$1}')
GIT_TAG_END ?= HEAD
GIT_VERSION := $(shell git describe --always --tags --long --dirty | sed -e 's/\-0//' -e 's/\-g.......//')
GIT_VERSION_LONG := $(shell git describe --always --tags --long --dirty)
# -----------------------------------------------------------------------------
# Docker Variables
# -----------------------------------------------------------------------------
DOCKER_IMAGE_TAG ?= $(GIT_REPOSITORY_NAME):$(GIT_VERSION)
DOCKER_IMAGE_NAME := $(GIT_REPOSITORY_NAME)
# -----------------------------------------------------------------------------
# FUNCTIONS
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Docker-based builds
# -----------------------------------------------------------------------------
.PHONY: docker-build
docker-build: docker-rmi-for-build
@echo "$(BOLD)$(YELLOW)Building docker image.$(RESET)"
@docker build \
--tag $(DOCKER_IMAGE_NAME) \
--tag $(DOCKER_IMAGE_NAME):$(GIT_VERSION) \
--file build/docker/Dockerfile \
.
@echo "$(BOLD)$(GREEN)Completed building docker image.$(RESET)"
.PHONY: docker-build-development-cache
docker-build-development-cache: docker-rmi-for-build-development-cache
@echo "$(BOLD)$(YELLOW)Building docker image.$(RESET)"
@docker build \
--tag $(DOCKER_IMAGE_TAG) \
--file build/docker/Dockerfile \
.
@echo "$(BOLD)$(GREEN)Completed building docker image.$(RESET)"
# -----------------------------------------------------------------------------
# Docker Clean up targets
# -----------------------------------------------------------------------------
.PHONY: docker-rmi-for-build
docker-rmi-for-build:
-docker rmi --force \
$(DOCKER_IMAGE_NAME):$(GIT_VERSION) \
$(DOCKER_IMAGE_NAME)
.PHONY: docker-rmi-for-build-development-cache
docker-rmi-for-build-development-cache:
-docker rmi --force $(DOCKER_IMAGE_TAG)
# -------------
# Go Lang
# -------------
.PHONY: fmt
fmt:
@gofmt -w -s -d command/notifier
@gofmt -w -s -d configuration
.PHONY: test-build
test-build: fmt
@go build