Skip to content

Commit d5ce301

Browse files
committed
feat: Add makefile with release feature
Signed-off-by: Ronny Trommer <ronny@no42.org>
1 parent 9f4f5ae commit d5ce301

File tree

3 files changed

+127
-3
lines changed

3 files changed

+127
-3
lines changed

.java-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17

Makefile

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
.DEFAULT_GOAL := jrobin-to-rrdtool
2+
3+
SHELL := /bin/bash -o nounset -o pipefail -o errexit
4+
VERSION ?= $(shell mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
5+
GIT_BRANCH := $(shell git branch --show-current)
6+
GIT_SHORT_HASH := $(shell git rev-parse --short HEAD)
7+
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") # Date format RFC3339
8+
JAVA_MAJOR_VERSION := 17
9+
10+
ARTIFACTS_DIR := ./target/artifacts
11+
RELEASE_VERSION := UNSET.0.0
12+
RELEASE_BRANCH := main
13+
MAJOR_VERSION := $(shell echo $(RELEASE_VERSION) | cut -d. -f1)
14+
MINOR_VERSION := $(shell echo $(RELEASE_VERSION) | cut -d. -f2)
15+
PATCH_VERSION := $(shell echo $(RELEASE_VERSION) | cut -d. -f3)
16+
SNAPSHOT_VERSION := $(MAJOR_VERSION).$(MINOR_VERSION).$(shell expr $(PATCH_VERSION) + 1)-SNAPSHOT
17+
RELEASE_LOG := $(ARTIFACTS_DIR)/release.log
18+
OK := "[ 👍 ]"
19+
20+
.PHONY: help
21+
help:
22+
@echo ""
23+
@echo "Build JRobin to RRDTool converter from source"
24+
@echo "Goals:"
25+
@echo " help: Show this help with explaining the build goals"
26+
@echo " jrobin-to-rrdtool: Compile and create a runnable jar from source"
27+
@echo " clean: Clean the build artifacts"
28+
@echo " release: Create a release in the local repository, e.g. make release RELEASE_VERSION=x.y.z"
29+
@echo ""
30+
31+
.PHONY: deps-build
32+
deps-build:
33+
@echo -n "👮‍♀️ Create artifact directory: "
34+
@mkdir -p $(ARTIFACTS_DIR)
35+
@echo $(OK)
36+
@echo -n "👮‍♀️ Check Java runtime: "
37+
@command -v java > /dev/null
38+
@echo $(OK)
39+
@echo -n "👮‍♀️ Check Java compiler: "
40+
@command -v javac > /dev/null
41+
@echo $(OK)
42+
@echo -n "👮‍♀️ Check Maven binary: "
43+
@command -v mvn > /dev/null
44+
@echo $(OK)
45+
@echo -n "👮‍♀️ Check Java version $(JAVA_MAJOR_VERSION): "
46+
@java --version | grep '$(JAVA_MAJOR_VERSION)\.[[:digit:]]*\.[[:digit:]]*' >/dev/null
47+
@echo $(OK)
48+
@echo -n "👮‍♀️ Validate Maven project: "
49+
@mvn validate > /dev/null
50+
@echo $(OK)
51+
52+
.PHONY: jrobin-to-rrdtool
53+
jrobin-to-rrdtool: deps-build
54+
mvn install assembly:single
55+
56+
.PHONY: clean
57+
clean: deps-build
58+
mvn clean
59+
60+
.PHONY: collect-artifacts
61+
collect-artifacts:
62+
find . -type f -regex ".*\/target\/convertjrb-$(VERSION)-jar-with-dependencies\.jar" -exec cp {} $(ARTIFACTS_DIR) \;
63+
echo $(VERSION) > $(ARTIFACTS_DIR)/pom-version.txt
64+
shasum -a 256 -b $(ARTIFACTS_DIR)/convertjrb-$(VERSION)-jar-with-dependencies.jar > $(ARTIFACTS_DIR)/shasum256.txt
65+
cd $(ARTIFACTS_DIR); tar czf convertjrb-$(VERSION).tar.gz convertjrb-$(VERSION)-jar-with-dependencies.jar shasum256.txt
66+
shasum -a 256 -b $(ARTIFACTS_DIR)/convertjrb-$(VERSION).tar.gz > $(ARTIFACTS_DIR)/convertjrb-$(VERSION).sha256
67+
68+
.PHONY: release
69+
release: deps-build
70+
@mkdir -p target
71+
@echo ""
72+
@echo "Release version: $(RELEASE_VERSION)"
73+
@echo "New snapshot version: $(SNAPSHOT_VERSION)"
74+
@echo "Git version tag: v$(RELEASE_VERSION)"
75+
@echo "Current branch: $(GIT_BRANCH)"
76+
@echo "Release branch: $(RELEASE_BRANCH)"
77+
@echo "Release log file: $(RELEASE_LOG)"
78+
@echo ""
79+
@echo -n "👮‍♀️ Check release branch: "
80+
@if [ "$(GIT_BRANCH)" != "$(RELEASE_BRANCH)" ]; then echo "Releases are made from the $(RELEASE_BRANCH) branch, your branch is $(GIT_BRANCH)."; exit 1; fi
81+
@echo "$(OK)"
82+
@echo -n "👮‍♀️ Check uncommited changes "
83+
@if git status --porcelain | grep -q .; then echo "There are uncommited changes in your repository."; exit 1; fi
84+
@echo "$(OK)"
85+
@echo -n "👮‍♀️ Check branch in sync "
86+
@if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then echo "$(RELEASE_BRANCH) branch not in sync with remote origin."; exit 1; fi
87+
@echo "$(OK)"
88+
@echo -n "👮‍♀️ Check release version: "
89+
@if [ "$(RELEASE_VERSION)" = "UNSET.0.0" ]; then echo "Set a release version, e.g. make release RELEASE_VERSION=1.0.0"; exit 1; fi
90+
@echo "$(OK)"
91+
@echo -n "👮‍♀️ Check version tag available: "
92+
@if git rev-parse v$(RELEASE_VERSION) >$(RELEASE_LOG) 2>&1; then echo "Tag v$(RELEASE_VERSION) already exists"; exit 1; fi
93+
@echo "$(OK)"
94+
@echo -n "💅 Set Maven release version: "
95+
@mvn versions:set -DnewVersion=$(RELEASE_VERSION) >>$(RELEASE_LOG) 2>&1
96+
@echo "$(OK)"
97+
@echo -n "👮‍♀️ Validate build: "
98+
@$(MAKE) jrobin-to-rrdtool >>$(RELEASE_LOG) 2>&1
99+
@echo "$(OK)"
100+
@echo -n "🎁 Git commit new release "
101+
@git commit --signoff -am "release: JRobin to RRDTool converter $(RELEASE_VERSION)" >>$(RELEASE_LOG) 2>&1
102+
@echo "$(OK)"
103+
@echo -n "🦄 Set Git version tag: "
104+
@git tag -a "v$(RELEASE_VERSION)" -m "Release JRobin to RRDTool converter version $(RELEASE_VERSION)" >>$(RELEASE_LOG) 2>&1
105+
@echo "$(OK)"
106+
@echo -n "⬆️ Set Maven snapshot version: "
107+
@mvn versions:set -DnewVersion=$(SNAPSHOT_VERSION) >>$(RELEASE_LOG) 2>&1
108+
@echo "$(OK)"
109+
@echo -n "🎁 Git commit snapshot release: "
110+
@git commit --signoff -am "release: JRobin to RRDTool converter version $(SNAPSHOT_VERSION)" >>$(RELEASE_LOG) 2>&1
111+
@echo "$(OK)"
112+
@echo ""
113+
@echo "🦄 Congratulations! ✨"
114+
@echo "You made a release in your local repository."
115+
@echo "Publish the release by pushing the version tag"
116+
@echo "and the new snapshot version to the remote repo"
117+
@echo "with the following commands:"
118+
@echo ""
119+
@echo " git push"
120+
@echo " git push origin v$(RELEASE_VERSION)"
121+
@echo ""
122+
@echo "Thank you for computing with us."
123+
@echo ""

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@
102102
<releases>
103103
<enabled>true</enabled>
104104
</releases>
105-
<id>opennms-release</id>
106-
<name>OpenNMS Release Maven Repository</name>
107-
<url>http://maven.opennms.org/content/groups/opennms.org-release/</url>
105+
<id>opennms-jrobin</id>
106+
<name>OpenNMS JRobin Maven Repository</name>
107+
<url>https://archive.opennms.com/repo-maven/maven2</url>
108108
</repository>
109109
</repositories>
110110
</project>

0 commit comments

Comments
 (0)