-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile-git
64 lines (56 loc) · 2.74 KB
/
Makefile-git
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
# vim: set foldmethod=indent foldnestmax=1 foldcolumn=1:
##@ Developer Recipes
.PHONY: _test-git-porcelain-clean
_test-git-porcelain-clean:
@# Test that source is committed to git. Sometimes it is convenient to disable this.
@echo -e $(_begin)
@# Enable test
@test -z "$$(git status --porcelain)" || (echo -e "\nError: Git is not clean\n" && false)
@# Disabled test
@#test true
@echo -e $(_finish)
.PHONY: _test-git-cherry
_test-git-cherry:
@# Test that HEAD is pushed to upstream
@echo -e $(_begin)
@git symbolic-ref --short HEAD || (echo -e "\nError: Must be on a git branch, not headless\n" && false)
@test -z "$$(git cherry)" || (echo -e "\nError: Git commit needs to be pushed to origin\n" && false)
@echo -e $(_finish)
.PHONY: _test-git-tag-exists
_test-git-tag-exists:
@# Test that there is a git commit matching _IMAGE_TAG.
@echo -e $(_begin)
@test -n "$$(git tag --list $(_IMAGE_TAG) | grep $(_IMAGE_TAG))" || (echo -e "\nError: Git commit is not tagged as $(_IMAGE_TAG)\n " && false)
@echo -e $(_finish)
.PHONY: _test-git-local-commit-tag-and-head-match
_test-git-local-commit-tag-and-head-match:
@# Test that there is a local tag commit matching HEAD.
@echo -e $(_begin)
@local_tag_commit=$$(git rev-list -n 1 $(_IMAGE_TAG)) && \
head_commit=$$(git rev-parse HEAD) && \
if [[ "$$local_tag_commit" != "$$head_commit" ]]; then echo -e "\nError: For tag $(_IMAGE_TAG), HEAD commit $$head_commit does not match local tag commit $$local_tag_commit" && false; fi
@echo -e $(_finish)
.PHONY: _test-git-tag-exists-remote
_test-git-tag-exists-remote:
@# Test that the git tag has been pushed to remote.
@echo -e $(_begin)
@test -n "$$(git ls-remote --tags origin $(_IMAGE_TAG) | grep $(_IMAGE_TAG))" || (echo -e "\nError: Git commit is not tagged as $(_IMAGE_TAG) on origin\n" && false)
@echo -e $(_finish)
.PHONY: _test-git-tag-remote-and-local-match
_test-git-tag-remote-and-local-match:
@# Test that there is a remote tag commit matching the local tag commit.
@echo -e $(_begin)
@remote_tag_commit=$$(git ls-remote -t origin | grep $(_IMAGE_TAG) | awk '{ print $$1 }') && \
local_tag_commit=$$(git rev-list -n 1 $(_IMAGE_TAG)) && \
if [[ "$$local_tag_commit" != "$$remote_tag_commit" ]]; then echo -e "\nError: For tag $(_IMAGE_TAG), remote tag commit $$remote_tag_commit does not match local tag commit $$local_tag_commit" && false; fi
@echo -e $(_finish)
.PHONY: releaseable
releaseable: ## Test that the project is git clean and therefore may be used for a release.
@echo -e $(_begin)
@$(_make) _test-git-porcelain-clean
@$(_make) _test-git-cherry
@$(_make) _test-git-tag-exists
@$(_make) _test-git-local-commit-tag-and-head-match
@$(_make) _test-git-tag-exists-remote
@$(_make) _test-git-tag-remote-and-local-match
@echo -e $(_finish)