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

Add CMP release to version outputs #77

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

havan
Copy link
Member

@havan havan commented Dec 4, 2024

This PR adds protocol release label from buf.build to the compiled binary. It also makes the build process more explicit by providing information about the build to the stdout.

I've also updated how the git_tag is build with git describe, explanation below.

Example -v output:

❯ ./build/camino-messenger-bot -v
camino-messenger-bot version v10.1.0-22-g8a20f6e-dirty (git: 8a20f6e)

libs:
  buf.build protocolbuffers : v1.34.2-20240924170438-a97744087df6.2 (release-10)
  buf.build grpc            : v1.5.1-20240924170438-a97744087df6.1 (release-10)
  camino-messenger-contracts: v0.0.0-20241024152339-d7c3c6e5c377

Here we see the version is v10.1.0-22-g8a20f6e-dirty (git: 8a20f6e), which means:

  • the last tag that exists before the current HEAD is v10.1.0
  • 22 commits happened after that tag, the -22 part (this is only added if the current HEAD does not have a tag)
  • now it's SHA 8a20f6e which comes from git (the -g part before the SHA) (only if there is no tag for current HEAD)
  • at compilation time the working directory was dirty (had uncommitted changes) (the -dirty part)
  • (git: 8a20f6e) this part is always added, even if current HEAD has a specific tag, in which case the version would be only the tag (if no dirty), ie: v10.1.0

This process ensures that we can identify for pretty much all the cases that can affect the binary. Previously it was always setting the version to tag name even if you had commits after that and the dirty workdir was not used at all.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced versioning information displayed in the application, now showing more comprehensive version details.
    • Introduced a new script to resolve protocol release labels from dependencies, improving version tracking.
  • Improvements

    • Build script now provides clearer feedback during the build process, enhancing user experience.
    • Updated methods for retrieving git tags to ensure accuracy even with uncommitted changes.
    • Enhanced logging for protocol versions, providing additional context in log entries.
  • Chores

    • Updated Dockerfile to use bash for script execution, improving compatibility with script constructs.

Copy link

coderabbitai bot commented Dec 4, 2024

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to versioning and logging in the camino_messenger_bot application. The Version field is changed to provide a more comprehensive version representation, and logging statements are enhanced to include additional context about protocol versions. New variables for protocol releases are introduced, and a new script is added to resolve protocol version labels from a dependency URI. The build script is also improved for better user feedback and readability.

Changes

File Change Summary
cmd/camino_messenger_bot.go Updated Version field from version.AppVersion to version.FullVersion. Enhanced logging for protocol versions to include additional context with CMP release versions.
internal/version/version.go Added new variables: BufBuildPBCMPRelease, BufBuildGRPCCMPRelease, and FullVersion. Updated FullVersion construction using fmt.Sprintf for detailed version output.
scripts/build.sh Reformatted command-line parsing, added echo statements for build process feedback, improved readability of CAMINOBOT_PATH handling, and constructed build command as a variable for better visibility.
scripts/constants.sh Updated git_tag definition to include the --dirty option. Added new variables grpc_release and protocolbuffers_release for resolving protocol releases.
scripts/resolve_protocol_release.sh New script to resolve labels from buf.build for specified dependency URIs, including error handling for missing values.

Possibly related PRs

  • Print protocol version in log #76: The changes in this PR also modify the cmd/camino_messenger_bot.go file, specifically focusing on logging and versioning, which directly relates to the updates made in the main PR regarding version information and logging output.

Suggested reviewers

  • VjeraTurk

Poem

🐇 In the code where bunnies hop,
Versioning now takes a top,
Logs are clearer, paths are bright,
Protocols dance in the moonlight.
With each build, a joyful cheer,
For changes made, we hold so dear! 🥕


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@coderabbitai coderabbitai bot changed the title add cmp release to version pkg @coderabbitai add cmp release to version pkg Update versioning and logging in camino_messenger_bot application Dec 4, 2024
Copy link

@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: 3

🧹 Outside diff range and nitpick comments (2)
scripts/resolve_protocol_release.sh (1)

25-30: Consider making the hash extraction more robust.

The grep pattern for extracting the short hash might be too rigid.

Consider using a more flexible pattern:

-short_hash=$(grep -E "$dep_path" "$go_mod_path" | grep -oP '(\w{12})(?=\.)' || echo "")
+short_hash=$(grep -E "$dep_path" "$go_mod_path" | grep -oE '[a-f0-9]{12,}' | head -n1 || echo "")
internal/version/version.go (1)

36-47: Consider improving the version string format.

While the version string is comprehensive, it could be more readable.

Consider using a more structured format:

-	FullVersion = fmt.Sprintf("%s (git: %s)\n\nlibs:\n  %s: %s (%s)\n  %s: %s (%s)\n  %s: %s",
+	FullVersion = fmt.Sprintf(`Version: %s
+Git Commit: %s
+
+Dependencies:
+  Protocol Buffers:
+    Commit: %s
+    Release: %s
+  gRPC:
+    Commit: %s
+    Release: %s
+  Contracts:
+    Commit: %s`,
 		AppVersion,
 		AppGitCommit,
-		"buf.build protocolbuffers ",
 		BufBuildPBCommit,
 		BufBuildPBCMPRelease,
-		"buf.build grpc            ",
 		BufBuildGRPCCommit,
 		BufBuildGRPCCMPRelease,
-		"camino-messenger-contracts",
 		ContractsGitCommit,
 	)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 77eb70d and 8a20f6e.

📒 Files selected for processing (5)
  • cmd/camino_messenger_bot.go (2 hunks)
  • internal/version/version.go (2 hunks)
  • scripts/build.sh (1 hunks)
  • scripts/constants.sh (1 hunks)
  • scripts/resolve_protocol_release.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/build.sh

[warning] 32-32: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


[warning] 37-37: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


[warning] 44-44: git_tag is referenced but not assigned.

(SC2154)


[warning] 45-45: git_commit is referenced but not assigned.

(SC2154)


[warning] 46-46: protocolbuffers_release is referenced but not assigned.

(SC2154)


[warning] 47-47: grpc_release is referenced but not assigned.

(SC2154)

scripts/constants.sh

[warning] 11-11: git_tag appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 14-14: grpc_release appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 15-15: protocolbuffers_release appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (9)
scripts/resolve_protocol_release.sh (1)

8-17: LGTM: Input validation and path setup is well-implemented.

The script properly validates input arguments and sets up paths correctly.

scripts/constants.sh (1)

11-11: LGTM: Good addition of --dirty flag.

The --dirty flag helps track uncommitted changes in the working directory.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 11-11: git_tag appears unused. Verify use (or export if used externally).

(SC2034)

internal/version/version.go (1)

13-14: LGTM: Clear naming for protocol release variables.

The new variables follow the existing naming convention and clearly indicate their purpose.

scripts/build.sh (4)

16-23: LGTM! Clean and clear argument parsing.

The command-line argument parsing is well-structured with appropriate error handling for unknown options.


51-52: LGTM! Proper version information injection.

The new LDFLAGS correctly inject the protocol buffer and gRPC CMP release information into the binary.


57-63: LGTM! Improved build command visibility.

The build command construction and execution is now more transparent, making it easier to debug build issues.


43-47: Verify version variables are properly defined.

The script references several version-related variables that should be defined in constants.sh.

Let's verify the variable definitions:

✅ Verification successful

Let me check the actual content of constants.sh to verify the variable definitions.


All version variables are properly defined

The variables used in the echo statements are correctly defined in constants.sh:

  • git_commit and git_tag are set using git commands with fallback values
  • protocolbuffers_release and grpc_release are set using the resolve_protocol_release.sh script
  • DEBUG appears to be an environment variable, which is a common practice
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if version variables are properly defined in constants.sh

# Find and check constants.sh content
echo "Checking constants.sh for variable definitions..."
fd -t f "constants.sh" -x grep -l "git_tag\|git_commit\|protocolbuffers_release\|grpc_release"

Length of output: 226


Script:

#!/bin/bash
# Check the content of constants.sh for these specific variables
echo "Content of constants.sh:"
cat ./scripts/constants.sh | grep -A 1 -E "(DEBUG|git_tag|git_commit|protocolbuffers_release|grpc_release)"

Length of output: 572

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 44-44: git_tag is referenced but not assigned.

(SC2154)


[warning] 45-45: git_commit is referenced but not assigned.

(SC2154)


[warning] 46-46: protocolbuffers_release is referenced but not assigned.

(SC2154)


[warning] 47-47: grpc_release is referenced but not assigned.

(SC2154)

cmd/camino_messenger_bot.go (2)

19-19: LGTM! Enhanced version information.

Using FullVersion provides more comprehensive version information, which is beneficial for debugging and support.


62-63: LGTM! Improved version logging.

The logging now includes CMP release information alongside commit hashes, providing better context about the protocol versions in use.

scripts/resolve_protocol_release.sh Outdated Show resolved Hide resolved
scripts/constants.sh Outdated Show resolved Hide resolved
scripts/build.sh Show resolved Hide resolved
Copy link

@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

🧹 Outside diff range and nitpick comments (2)
Dockerfile (1)

Line range hint 1-1: Fix incorrect Go version in base image

The base image golang:1.23.1-alpine3.20 specifies a non-existent Go version. The latest Go version is 1.21.x.

Apply this diff to fix the version:

-FROM golang:1.23.1-alpine3.20 AS build-stage
+FROM golang:1.21.5-alpine3.20 AS build-stage
scripts/constants.sh (1)

4-4: Export the SCRIPT_DIR variable for external use.

Since this variable is used to resolve paths in other scripts, it should be exported.

-SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
+export SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8a20f6e and f75cebe.

📒 Files selected for processing (3)
  • Dockerfile (1 hunks)
  • scripts/constants.sh (1 hunks)
  • scripts/resolve_protocol_release.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/resolve_protocol_release.sh
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/constants.sh

[warning] 9-9: current_branch appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 12-12: git_commit appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 13-13: git_tag appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 16-16: grpc_release appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 17-17: protocolbuffers_release appears unused. Verify use (or export if used externally).

(SC2034)

🔇 Additional comments (4)
Dockerfile (2)

11-11: LGTM: Package additions are appropriate

Adding git is required for submodule operations, and the addition of these packages in a single layer helps minimize the image size.


13-13: Verify if bash is required for the build script

While the change from sh to bash works, consider if bash-specific features are actually needed. Using sh could potentially reduce the image size if bash features aren't necessary.

Let's check if the build script uses bash-specific features:

✅ Verification successful

Let me check the complete content of the build script to better understand its usage of bash features.


Let me check the content of the constants.sh file as well since it's sourced by build.sh.


Bash is required for the build script

The build script uses several bash-specific features that are not available in POSIX sh:

  • [[ conditional expressions for argument parsing
  • ${BASH_SOURCE[0]} array variable for script path resolution
  • set -euo pipefail in constants.sh
  • Process substitution with &>/dev/null
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if build.sh uses bash-specific features

# Look for bash-specific syntax in build.sh
echo "Checking for bash-specific features in build.sh:"
rg -n '(\[\[|\]\]|declare\s|-o pipefail|read\s+-[^r]|<<<|process\s+substitution|\$\{[a-zA-Z_][a-zA-Z0-9_]*:.*\})' ./scripts/build.sh

Length of output: 269


Script:

#!/bin/bash
# Show the complete content of build.sh
cat ./scripts/build.sh

Length of output: 1961


Script:

#!/bin/bash
cat ./scripts/constants.sh

Length of output: 864

scripts/constants.sh (2)

16-17: Export the protocol release variables.

These variables are used externally and need to be exported.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 16-16: grpc_release appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 17-17: protocolbuffers_release appears unused. Verify use (or export if used externally).

(SC2034)


16-17: Verify the resolve_protocol_release.sh script.

Ensure that the referenced script exists and has proper permissions.

✅ Verification successful

Script exists and has correct permissions

The resolve_protocol_release.sh script exists in the scripts directory and has executable permissions (-rwxr-xr-x). The script is properly referenced in constants.sh and is ready to be used.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the script exists and is executable
if [ -f "${SCRIPT_DIR}/resolve_protocol_release.sh" ]; then
    ls -l "${SCRIPT_DIR}/resolve_protocol_release.sh"
else
    echo "Error: resolve_protocol_release.sh not found"
    exit 1
fi

Length of output: 149


Script:

#!/bin/bash
# First, let's find the script location using fd
fd resolve_protocol_release.sh

# Let's also check the scripts directory structure
ls -la scripts/

Length of output: 956

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 16-16: grpc_release appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 17-17: protocolbuffers_release appears unused. Verify use (or export if used externally).

(SC2034)

scripts/constants.sh Show resolved Hide resolved
@havan havan requested a review from evlekht December 4, 2024 20:32
internal/version/version.go Outdated Show resolved Hide resolved
@havan havan changed the title add cmp release to version pkg Update versioning and logging in camino_messenger_bot application Add cmp release to version outputs Dec 4, 2024
@havan havan changed the title Add cmp release to version outputs Add CMP release to version outputs Dec 4, 2024
@havan
Copy link
Member Author

havan commented Dec 4, 2024

@coderabbitai ignore

Copy link

coderabbitai bot commented Dec 4, 2024

✅ Actions performed

Reviews paused.

@chain4travel chain4travel deleted a comment from coderabbitai bot Dec 4, 2024
@chain4travel chain4travel deleted a comment from coderabbitai bot Dec 4, 2024
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.

2 participants