-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
83 lines (70 loc) · 3.06 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
.PHONY: test
test:
cd test && make all
######################################################################
# Release Management
# Taken from: https://github.com/MatthiasScholz/demo_github_release
######################################################################
# NOTE Should be set when calling make
token_github :=
release_version ?= v0.4.0
# Extracting version information from the repository
fabio_file := examples/jobs/fabio.nomad
packer_file := modules/ami2/nomad-consul-docker-ecr.json
release_branch := releases/$(release_version)
today := `date +'%Y-%m-%d'`
release_notes_template := _docs/changelogs/CHANGELOG.template.md
release_notes_file := _docs/changelogs/CHANGELOG.$(release_version).md
release_title := "$(release_version) ($(today))"
# Extracting the information from the actual files in use
version_nomad := `cat $(packer_file) | jq '.variables.nomad_version' | tr -d '"'`
version_consul := `cat $(packer_file) | jq '.variables.consul_version' | tr -d '"'`
version_fabio := `cat $(fabio_file) | grep releases | sed -n "s/.*v\([0-9.]*\).*/\1/p"`
version_terraform := `grep --recursive --include=\*.tf "required_version" ./examples/root-example | sed -n "s/.* \([0-9.]*\).*/\1/p" | uniq`
version_tf_nomad := `grep --recursive --include=\*.tf "terraform-aws-nomad.git" ./modules | sed -n "s/.*v\([0-9.]*\).*/\1/p" | uniq`
version_tf_consul := `grep --recursive --include=\*.tf "terraform-aws-consul.git" ./modules | sed -n "s/.*v\([0-9.]*\).*/\1/p" | uniq`
release: release-commit release-push release-github
test-release: release-notes release-commit release-push release-github
# NOTE Ensure existing files are not overwritten
release-notes: $(release_notes_file)
$(release_notes_file):
@echo "INFO :: Writting the Changelog: '$(release_notes_file)'"
release_date=$(today) \
release_version=$(release_version) \
version_nomad=$(version_nomad) \
version_consul=$(version_consul) \
version_fabio=$(version_fabio) \
version_terraform=$(version_terraform) \
version_tf_nomad=$(version_tf_nomad) \
version_tf_consul=$(version_tf_consul) \
consul-template -once -template="$(release_notes_template):$(release_notes_file)"
@echo "INFO :: Adding release to 'CHANGELOG.md'"
@echo "" >> CHANGELOG.md
@echo "## $(release_version) ($(today))" >> CHANGELOG.md
@echo "" >> CHANGELOG.md
@echo "- [release notes]($(release_notes_file))" >> CHANGELOG.md
release-commit:
@git add .
git commit -m ":pushpin: $(release_version)"
release-github:
gh release create $(release_version) --draft --prerelease --title $(release_title) --notes-file $(release_notes_file) --target $(release_branch)
@gh release list
release-push:
git push origin main
@git branch $(release_branch)
git push origin $(release_branch)
gh-login:
ifeq ($(strip $(token_github)),)
@echo "ERROR :: No github token given. Please call 'make' like this: 'make token_github=<put_github_token>'"
@exit 1
endif
echo $(token_github) | gh auth login --with-token
gh auth status
setup:
brew install consul-template
brew install gh
consul-template -version
gh version
uninstall:
brew uninstall consul-template
brew uninstall gh