Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: version for tags with -arabica, -mocha, -rc suffixes #3977

Merged
merged 4 commits into from
Oct 16, 2024

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Oct 15, 2024

Closes #3933

Testing

$ git checkout v2.2.0-mocha
$ make debug-version
GIT_TAG: v2.2.0-mocha
VERSION: 2.2.0-mocha
$ git tag --delete v2.2.0-mocha
Deleted tag 'v2.2.0-mocha' (was d3f8b2997)
$ make debug-version
GIT_TAG: v2.2.0-arabica
VERSION: 2.2.0-arabica
$ git tag --delete v2.2.0-arabica
Deleted tag 'v2.2.0-arabica' (was d3f8b2997)
$ make debug-version
GIT_TAG: v2.2.0-rc0
VERSION: 2.2.0-rc0
$ git tag --delete v2.2.0-rc0
Deleted tag 'v2.2.0-rc0' (was d3f8b2997)
$ make debug-version
GIT_TAG: v2.1.2-4-gd3f8b2997
VERSION: 2.1.2-4-gd3f8b2997

@rootulp rootulp self-assigned this Oct 15, 2024
@rootulp rootulp marked this pull request as ready for review October 15, 2024 19:19
@rootulp rootulp requested a review from a team as a code owner October 15, 2024 19:19
@rootulp rootulp requested review from staheri14, ninabarbakadze, cmwaters, evan-forbes and rach-id and removed request for a team October 15, 2024 19:19
@rootulp rootulp changed the title fix: version for -arabica, -mocha, -rc fix: version for tags with -arabica, -mocha, -rc suffixes Oct 15, 2024
Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

📝 Walkthrough

Walkthrough

The changes in the Makefile focus on improving the method of determining the VERSION variable by utilizing the GIT_TAG variable. This new approach executes git tag commands to prioritize specific tag formats, including various semantic versioning tags. A fallback mechanism to git describe --tags is also implemented. Additionally, a new .PHONY target called debug-version has been added to print the values of GIT_TAG and VERSION.

Changes

File Change Summary
Makefile Replaced VERSION variable determination with GIT_TAG derived from specific git tag commands; added debug-version target to print GIT_TAG and VERSION.

Assessment against linked issues

Objective Addressed Explanation
Fix the version command to report correct version for -arabica and -mocha tags (#3933)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
Makefile (2)

1-16: Improved versioning logic, consider minor optimization

The new GIT_TAG definition effectively addresses the version reporting issue by prioritizing specific tag formats. The fallback mechanism ensures robustness.

Consider using head -n1 instead of multiple grep commands to potentially improve performance:

-GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-mocha$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-arabica$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]*$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(beta)$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(alpha)$$' \
-    || git describe --tags)
+GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-mocha|-arabica|-rc[0-9]*|-beta|-alpha)?$$' | head -n1 \
+    || git describe --tags)

This change combines all the patterns into a single grep command and uses head -n1 to select the first matching tag, potentially improving performance while maintaining the same functionality.


276-280: Useful debug-version target added

The new debug-version target provides a convenient way to verify the GIT_TAG and VERSION values, which is helpful for debugging version-related issues.

Consider adding a separator between the two echo commands for better readability of the output:

 debug-version:
 	@echo "GIT_TAG: $(GIT_TAG)"
+	@echo "------------------------"
 	@echo "VERSION: $(VERSION)"
 .PHONY: debug-version

This change will make it easier to distinguish between the two values in the output.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b1f43f5 and 0aad2de.

📒 Files selected for processing (1)
  • Makefile (2 hunks)
🧰 Additional context used
🔇 Additional comments (2)
Makefile (2)

17-17: Correct VERSION derivation from GIT_TAG

The VERSION variable is correctly derived from GIT_TAG by removing the leading 'v'. This ensures that the version is reported in the expected format.


Line range hint 1-280: Overall improvements to version handling and debugging

The changes in this Makefile effectively address the version reporting issues mentioned in the PR objectives. The new GIT_TAG variable provides a robust method for determining the correct version tag, while the VERSION variable ensures the proper format. The addition of the debug-version target enhances maintainability by providing an easy way to verify version information.

These modifications significantly improve the reliability and accuracy of version reporting in the celestia-appd application, aligning well with the goals outlined in issue #3933.

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request primarily involve modifications to the Makefile, enhancing the versioning logic. The method for deriving the VERSION variable has been updated to utilize the GIT_TAG variable, which fetches the latest Git tag for the current commit. A new target, debug-version, has been introduced to print the GIT_TAG and VERSION values, facilitating easier debugging of version information.

Changes

File Change Summary
Makefile Updated versioning logic to derive VERSION from GIT_TAG. Added debug-version target to print GIT_TAG and VERSION.

Assessment against linked issues

Objective Addressed Explanation
Fix the version command to report correct version for -arabica and -mocha tags (#3933)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b1f43f5 and 0aad2de.

📒 Files selected for processing (1)
  • Makefile (2 hunks)
🧰 Additional context used
🔇 Additional comments (2)
Makefile (2)

276-280: Approved: Addition of debug-version target

The debug-version target is a useful addition that allows developers to easily check the GIT_TAG and VERSION values. The implementation is correct and follows standard Makefile practices.


10-16: Verify tag matching patterns for completeness

Ensure that the consolidated regular expression accurately matches all intended tag formats and maintains the priority order. There could be edge cases where certain tags might not be matched correctly.

You can test the regular expression with various tag examples to confirm it captures all desired formats:

This script helps verify that all intended tag formats are matched and unintended ones are excluded.

✅ Verification successful

Tag patterns are correctly matched and prioritized

All intended tag formats are accurately matched by the regular expression, and unintended tags are appropriately excluded.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Test the consolidated regular expression against sample tags.

tags=(
  "v2.2.0"
  "v2.2.0-mocha"
  "v2.2.0-arabica"
  "v2.2.0-rc0"
  "v2.2.0-beta"
  "v2.2.0-alpha"
  "v2.2.0-unknown"
)

for tag in "${tags[@]}"; do
  echo "$tag" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-mocha|-arabica|-rc[0-9]+|-beta|-alpha)?$$' && echo "Matched: $tag"
done

Length of output: 1360


Script:

#!/bin/bash
# Description: Test the consolidated regular expression against sample tags.

tags=(
  "v2.2.0"
  "v2.2.0-mocha"
  "v2.2.0-arabica"
  "v2.2.0-rc0"
  "v2.2.0-beta"
  "v2.2.0-alpha"
  "v2.2.0-unknown"
)

for tag in "${tags[@]}"; do
  if echo "$tag" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-mocha|-arabica|-rc[0-9]+|-beta|-alpha)?$' > /dev/null; then
    echo "Matched: $tag"
  else
    echo "Did not match: $tag"
  fi
done

Length of output: 1351

Comment on lines +1 to +16
# GIT_TAG is an environment variable that is set to the latest git tag on the
# current commit with the following example priority: v2.2.0, v2.2.0-mocha,
# v2.2.0-arabica, v2.2.0-rc0, v2.2.0-beta, v2.2.0-alpha. If no tag points to the
# current commit, git describe is used. The priority in this command is
# necessary because `git tag --sort=-creatordate` only works for annotated tags
# with metadata. Git tags created via GitHub releases are not annotated and do
# not have metadata like creatordate. Therefore, this command is a hacky attempt
# to get the most recent tag on the current commit according to Celestia's
# testnet versioning scheme + SemVer.
GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-mocha$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-arabica$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]*$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(beta)$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(alpha)$$' \
|| git describe --tags)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Suggestion: Consolidate git tag commands for efficiency

Currently, the GIT_TAG variable is assigned by invoking git tag --points-at HEAD multiple times, which can be inefficient. Consider capturing the output once and applying all necessary filters in a single command.

Here's a proposed modification:

-GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-mocha$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-arabica$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]*$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(beta)$$' \
-    || git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(alpha)$$' \
+GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname \
+    | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-mocha|-arabica|-rc[0-9]+|-beta|-alpha)?$$' \
     || git describe --tags)

This approach reduces the number of times git tag is called and consolidates the pattern matching into a single grep command.

📝 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
# GIT_TAG is an environment variable that is set to the latest git tag on the
# current commit with the following example priority: v2.2.0, v2.2.0-mocha,
# v2.2.0-arabica, v2.2.0-rc0, v2.2.0-beta, v2.2.0-alpha. If no tag points to the
# current commit, git describe is used. The priority in this command is
# necessary because `git tag --sort=-creatordate` only works for annotated tags
# with metadata. Git tags created via GitHub releases are not annotated and do
# not have metadata like creatordate. Therefore, this command is a hacky attempt
# to get the most recent tag on the current commit according to Celestia's
# testnet versioning scheme + SemVer.
GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-mocha$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-arabica$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]*$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(beta)$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(alpha)$$' \
|| git describe --tags)
# GIT_TAG is an environment variable that is set to the latest git tag on the
# current commit with the following example priority: v2.2.0, v2.2.0-mocha,
# v2.2.0-arabica, v2.2.0-rc0, v2.2.0-beta, v2.2.0-alpha. If no tag points to the
# current commit, git describe is used. The priority in this command is
# necessary because `git tag --sort=-creatordate` only works for annotated tags
# with metadata. Git tags created via GitHub releases are not annotated and do
# not have metadata like creatordate. Therefore, this command is a hacky attempt
# to get the most recent tag on the current commit according to Celestia's
# testnet versioning scheme + SemVer.
GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-mocha|-arabica|-rc[0-9]+|-beta|-alpha)?$$' \
|| git describe --tags)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you want to do this ^

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The proposed command won't use the priority we want (v2.2.0, v2.2.0-mocha, v2.2.0-alpha, etc)

Copy link
Member

@rach-id rach-id left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. It seems like the regex could be consolidated

Comment on lines +1 to +16
# GIT_TAG is an environment variable that is set to the latest git tag on the
# current commit with the following example priority: v2.2.0, v2.2.0-mocha,
# v2.2.0-arabica, v2.2.0-rc0, v2.2.0-beta, v2.2.0-alpha. If no tag points to the
# current commit, git describe is used. The priority in this command is
# necessary because `git tag --sort=-creatordate` only works for annotated tags
# with metadata. Git tags created via GitHub releases are not annotated and do
# not have metadata like creatordate. Therefore, this command is a hacky attempt
# to get the most recent tag on the current commit according to Celestia's
# testnet versioning scheme + SemVer.
GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-mocha$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-arabica$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]*$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(beta)$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(alpha)$$' \
|| git describe --tags)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you want to do this ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

celestia-appd version reports incorrect version for -arabica and -mocha tags
4 participants