Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ HTTPS_GIT := https://github.com/cosmos/cosmos-sdk.git
DOCKER := $(shell which docker)
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)

# Subdirectories for tagging
SUBDIR_PREFIXES := api core errors store x/circuit x/evidence x/feegrant x/nft x/tx x/upgrade

# process build tags
build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
Expand Down Expand Up @@ -481,3 +484,44 @@ localnet-start: localnet-stop localnet-build-env localnet-build-nodes
localnet-debug: localnet-stop localnet-build-dlv localnet-build-nodes

.PHONY: localnet-start localnet-stop localnet-debug localnet-build-env localnet-build-dlv localnet-build-nodes

###############################################################################
### Tagging ###
###############################################################################

# tag-client creates and pushes the special client tag with v2.0.0- prefix
# Usage: make tag-client TAG=v1.2.3 (creates client/v2.0.0-v1.2.3)
tag-client:
ifndef TAG
$(error TAG is required. Usage: make tag-client TAG=v1.2.3)
endif
@echo "Fetching latest tags from origin..."
@git fetch origin --tags
@echo "Creating client tag for $(TAG)..."
@client_tag="client/v2.0.0-$(TAG)"; \
echo "Creating tag: $$client_tag"; \
git tag "$$client_tag" $(TAG); \
echo "Pushing tag: $$client_tag"; \
git push origin "$$client_tag"
@echo "Successfully created and pushed client tag for $(TAG)"

Comment on lines +492 to +507
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

tag-client is not idempotent and lacks basic validation

Running the target twice hard-fails (git tag / git push), and it will happily create a tag even when $(TAG) is missing locally / remotely.

@@
-	@echo "Fetching latest tags from origin..."
-	@git fetch origin --tags
-	@echo "Creating client tag for $(TAG)..."
-	@client_tag="client/v2.0.0-$(TAG)"; \
-	echo "Creating tag: $$client_tag"; \
-	git tag "$$client_tag" $(TAG); \
-	echo "Pushing tag: $$client_tag"; \
-	git push origin "$$client_tag"
+	@echo "Verifying tag $(TAG) exists in origin…"
+	@git fetch --quiet origin "refs/tags/$(TAG):refs/tags/$(TAG)" || \
+		( echo "Tag $(TAG) not found in origin" && exit 1 )
+	@client_tag="client/v2.0.0-$(TAG)"; \
+	if git rev-parse -q --verify "$$client_tag" >/dev/null; then \
+		echo "Tag $$client_tag already exists — skipping"; \
+	else \
+		echo "Creating tag: $$client_tag"; \
+		git tag -a "$$client_tag" -m "Auto-generated client tag for $(TAG)" $(TAG); \
+		echo "Pushing tag: $$client_tag"; \
+		git push origin "$$client_tag"; \
+	fi

Benefits: repeatable runs, clear error message, no local-branch pollution, traceable annotated tag.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# tag-client creates and pushes the special client tag with v2.0.0- prefix
# Usage: make tag-client TAG=v1.2.3 (creates client/v2.0.0-v1.2.3)
tag-client:
ifndef TAG
$(error TAG is required. Usage: make tag-client TAG=v1.2.3)
endif
@echo "Fetching latest tags from origin..."
@git fetch origin --tags
@echo "Creating client tag for $(TAG)..."
@client_tag="client/v2.0.0-$(TAG)"; \
echo "Creating tag: $$client_tag"; \
git tag "$$client_tag" $(TAG); \
echo "Pushing tag: $$client_tag"; \
git push origin "$$client_tag"
@echo "Successfully created and pushed client tag for $(TAG)"
# tag-client creates and pushes the special client tag with v2.0.0- prefix
# Usage: make tag-client TAG=v1.2.3 (creates client/v2.0.0-v1.2.3)
tag-client:
ifndef TAG
$(error TAG is required. Usage: make tag-client TAG=v1.2.3)
endif
@echo "Verifying tag $(TAG) exists in origin…"
@git fetch --quiet origin "refs/tags/$(TAG):refs/tags/$(TAG)" || \
( echo "Tag $(TAG) not found in origin" && exit 1 )
@client_tag="client/v2.0.0-$(TAG)"; \
if git rev-parse -q --verify "$$client_tag" >/dev/null; then \
echo "Tag $$client_tag already exists — skipping"; \
else \
echo "Creating tag: $$client_tag"; \
git tag -a "$$client_tag" -m "Auto-generated client tag for $(TAG)" $(TAG); \
echo "Pushing tag: $$client_tag"; \
git push origin "$$client_tag"; \
fi
@echo "Successfully created and pushed client tag for $(TAG)"
🤖 Prompt for AI Agents
In the Makefile from lines 492 to 507, the tag-client target is not idempotent
and lacks validation, causing failures if run multiple times or if the TAG does
not exist locally or remotely. To fix this, add checks to verify that the TAG
exists locally before creating the client tag, and check if the client tag
already exists to avoid duplicate creation. Use annotated tags instead of
lightweight tags for traceability, and handle errors gracefully with clear
messages. Also, ensure the tag push only happens if the tag creation succeeds,
making the process repeatable and safe.

# tag-subdirs creates and pushes tags with subdir prefixes for a given tag
# Usage: make tag-subdirs TAG=v1.2.3
# NOTE: This also automatically creates the special client tag
tag-subdirs: tag-client
ifndef TAG
$(error TAG is required. Usage: make tag-subdirs TAG=v1.2.3)
endif
@echo "Fetching latest tags from origin..."
@git fetch origin --tags
@echo "Creating and pushing subdir tags for $(TAG)..."
@for prefix in $(SUBDIR_PREFIXES); do \
new_tag="$$prefix/$(TAG)"; \
echo "Creating tag: $$new_tag"; \
git tag "$$new_tag" $(TAG); \
echo "Pushing tag: $$new_tag"; \
git push origin "$$new_tag"; \
done
Comment on lines +518 to +524
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle pre-existing sub-dir tags to make the rule idempotent

Running the rule twice currently hard-fails on git tag or git push if the tag already exists.
Guard against it and add simple annotation for traceability:

-		new_tag="$$prefix/$(TAG)"; \
-		echo "Creating tag: $$new_tag"; \
-		git tag "$$new_tag" $(TAG); \
-		echo "Pushing tag: $$new_tag"; \
-		git push origin "$$new_tag"; \
+		new_tag="$$prefix/$(TAG)"; \
+		if git rev-parse -q --verify "$$new_tag" >/dev/null; then \
+			echo "Tag $$new_tag already exists – skipping"; \
+		else \
+			echo "Creating tag: $$new_tag"; \
+			git tag -a "$$new_tag" -m "Auto-generated subdir tag for $$prefix $(TAG)" $(TAG); \
+			echo "Pushing tag: $$new_tag"; \
+			git push origin "$$new_tag"; \
+		fi; \

This keeps the target repeatable and prevents accidental failures in CI.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@for prefix in $(SUBDIR_PREFIXES); do \
new_tag="$$prefix/$(TAG)"; \
echo "Creating tag: $$new_tag"; \
git tag "$$new_tag" $(TAG); \
echo "Pushing tag: $$new_tag"; \
git push origin "$$new_tag"; \
done
@for prefix in $(SUBDIR_PREFIXES); do \
new_tag="$$prefix/$(TAG)"; \
if git rev-parse -q --verify "$$new_tag" >/dev/null; then \
echo "Tag $$new_tag already exists – skipping"; \
else \
echo "Creating tag: $$new_tag"; \
git tag -a "$$new_tag" -m "Auto-generated subdir tag for $$prefix $(TAG)" $(TAG); \
echo "Pushing tag: $$new_tag"; \
git push origin "$$new_tag"; \
fi; \
done
🤖 Prompt for AI Agents
In the Makefile around lines 504 to 510, the current tag creation and push
commands fail if the tag already exists, making the rule non-idempotent. Modify
the script to first check if the tag "$$new_tag" already exists using git tag
-l, and only create and push the tag if it does not exist. When creating the
tag, add an annotation with a message for traceability. This will prevent errors
on repeated runs and ensure the rule is repeatable and safe for CI environments.

@echo "Successfully created and pushed all subdir tags for $(TAG)"

.PHONY: tag-subdirs tag-client
Loading