Skip to content

Commit 684ecf6

Browse files
committed
updated to v1.0.4
1 parent ff23c6a commit 684ecf6

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

Makefile

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Makefile
2+
3+
# Variables
4+
TAG_NUMBER_FILE = '.tag_number'
5+
BRANCH_NAME ?= master
6+
#POM_FILE = pom.xml
7+
#ARTIFACT_ID ?= test-artifact
8+
9+
# Prevent make from treating the targets as files
10+
#.PHONY: all update_version commit_changes create_tag push_changes push_tags clean help
11+
.PHONY: all increment_version commit_changes create_tag push_changes push_tags clean help
12+
13+
# Default target
14+
#all: update_version commit_changes create_tag push_changes push_tags
15+
all: increment_version commit_changes create_tag push_changes push_tags
16+
17+
## Update the version for the specified artifactId in the pom.xml
18+
#update_version:
19+
# @git checkout $(BRANCH_NAME)
20+
# @git pull
21+
# @if [ -z "$(TAG_NUMBER)" ]; then \
22+
# echo "Error: No tag specified. Usage: make update_version <tag_number>"; \
23+
# exit 1; \
24+
# fi
25+
# @echo "Updating version to $(TAG_NUMBER) for artifactId $(ARTIFACT_ID) in $(POM_FILE)..."
26+
# # Remove prefix 'v' for version if it starts with 'v'
27+
# @VERSION=$$(echo "$(TAG_NUMBER)" | sed 's/^v//'); \
28+
# echo "Updating version to $$VERSION for artifactId $(ARTIFACT_ID) in $(POM_FILE)..."; \
29+
# awk -v version="$$VERSION" 'BEGIN {updated=0} \
30+
# /<artifactId>$(ARTIFACT_ID)<\/artifactId>/ {print; getline; sub(/<version>.*<\/version>/, "<version>" version "</version>"); updated=1} \
31+
# {print} \
32+
# END {if (!updated) {exit 1}}' $(POM_FILE) > $(POM_FILE).tmp && mv $(POM_FILE).tmp $(POM_FILE); \
33+
# if [ $$? -ne 0 ]; then \
34+
# echo "Error: Could not find artifactId $(ARTIFACT_ID) in $(POM_FILE)."; \
35+
# exit 1; \
36+
# fi
37+
# @echo "Version updated to $(TAG_NUMBER) for artifactId $(ARTIFACT_ID)."
38+
39+
# Increment version number
40+
increment_version:
41+
@latest_tag=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
42+
if [ "$$latest_tag" = "v0.0.0" ]; then \
43+
echo "Tags not found! Using default version v0.0.0"; \
44+
else \
45+
echo "Tags found: $$latest_tag"; \
46+
fi; \
47+
version=$$(echo "$$latest_tag" | sed 's/^v//'); \
48+
echo "Incrementing after version $$version"; \
49+
set -- $$(echo "$$version" | tr '.' ' '); \
50+
major=$$1; minor=$$2; patch=$$3; \
51+
echo "Current version: Major:$$major | Minor:$$minor | Patch:$$patch"; \
52+
new_patch=$$((patch + 1)); \
53+
TAG_NUMBER="v$$major.$$minor.$$new_patch"; \
54+
echo "New tag: $$TAG_NUMBER"; \
55+
echo "$$TAG_NUMBER" > $(TAG_NUMBER_FILE);
56+
57+
58+
# Commit the changes with the given message
59+
commit_changes:
60+
@$(call check_tag_number) \
61+
rm $(TAG_NUMBER_FILE); \
62+
git add .; \
63+
git commit -m "updated to $$TAG_NUMBER"; \
64+
echo "Changes committed with tag $$TAG_NUMBER."; \
65+
echo "$$TAG_NUMBER" > $(TAG_NUMBER_FILE);
66+
67+
# Create a git tag with the given tag number
68+
create_tag:
69+
@$(call check_tag_number) \
70+
git tag "$$TAG_NUMBER"; \
71+
echo "Tag $$TAG_NUMBER created.";
72+
73+
74+
# Push the changes to the origin branch
75+
push_changes:
76+
@git pull origin $(BRANCH_NAME)
77+
@git status
78+
@git push -u origin $(BRANCH_NAME)
79+
@echo "Changes pushed to branch $(BRANCH_NAME)."
80+
81+
# Push all tags to the remote repository
82+
push_tags:
83+
@git push --tags
84+
@echo "All tags pushed to remote."
85+
86+
# Clean up
87+
clean:
88+
@echo "Cleaning up..."
89+
@git reset --hard HEAD
90+
@echo "Cleanup done."
91+
@rm $(TAG_NUMBER_FILE);
92+
93+
94+
# Help message
95+
help:
96+
@echo "Usage:"
97+
@echo " make update_version <tag_number>"
98+
@echo "Targets:"
99+
@echo " all Updates version, commits changes, creates a tag, and pushes changes."
100+
@#echo " update_version Updates the version in pom.xml."
101+
@echo " commit_changes Commits the changes with a message."
102+
@echo " create_tag Creates a git tag."
103+
@echo " push_changes Pushes changes to the origin branch."
104+
@echo " push_tags Pushes all tags to the remote repository."
105+
@echo " clean Resets changes to HEAD."
106+
107+
# Handle arguments for the update_version target
108+
%:
109+
@:
110+
111+
define check_tag_number
112+
@if [ -f $(TAG_NUMBER_FILE) ]; then \
113+
TAG_NUMBER=$$(cat $(TAG_NUMBER_FILE)); \
114+
if [ -n "$$TAG_NUMBER" ]; then \
115+
echo "Using tag number from file $(TAG_NUMBER_FILE): $$TAG_NUMBER"; \
116+
else \
117+
echo "Error: $(TAG_NUMBER_FILE) is empty. Run 'make increment_version' first."; \
118+
exit 0; \
119+
fi \
120+
else \
121+
echo "Error: $(TAG_NUMBER_FILE) file not found. Run 'make increment_version' first."; \
122+
exit 0; \
123+
fi;
124+
endef

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy