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

--version points to git hash #756

Closed
wants to merge 1 commit into from
Closed

Conversation

dougsland
Copy link
Collaborator

@dougsland dougsland commented Feb 6, 2025

Today ramalama just share version 0.5.5 (as example) but don't tell users and developer which commit it's using.

Resolves: #754

Summary by Sourcery

Update the version reporting to use the Git commit hash if available, falling back to a file-based version if not in a Git repository.

New Features:

  • Add the ability to determine the version from the git hash.

Enhancements:

  • Improve version reporting to provide more context.

Copy link
Contributor

sourcery-ai bot commented Feb 6, 2025

Reviewer's Guide by Sourcery

The PR updates the version reporting mechanism to display git commit information by reading a version file, rather than relying on package metadata. The changes include refactoring in the version.py file to read the version from a configuration file and adding logic in the install.sh file to generate this version file based on git describe output.

Sequence diagram for version reporting mechanism

sequenceDiagram
    actor User
    participant PrintVersion as print_version()
    participant VersionFunc as version()
    participant FS as FileSystem

    User->>PrintVersion: Run 'ramalama --version'
    PrintVersion->>VersionFunc: Call version()
    VersionFunc->>FS: Check if version file exists
    alt File exists
        FS-->>VersionFunc: Return file content
        VersionFunc-->>PrintVersion: Return version string
    else File does not exist
        VersionFunc-->>PrintVersion: Return error message with file path
    end
    PrintVersion->>User: Print "ramalama version <version>"
Loading

File-Level Changes

Change Details Files
Refactored version retrieval logic in the main codebase.
  • Removed dependency on importlib.metadata to fetch package version.
  • Introduced new constants for configuration directory and version file path.
  • Updated the version() function to read version information from ~/.config/ramalama/version, and return an error message if the file is missing.
  • Modified the print_version function to utilize the new version() implementation.
ramalama/version.py
Added version file setup functionality in the installation script.
  • Implemented a new setup_version_file function in install.sh to create the configuration directory and version file.
  • Added logic to use git commands (git rev-parse and git describe) to determine the git commit and tag information.
  • Formatted the version string from git output to include version and commit hash details.
  • Ensured that the version file is written with the version obtained from git, and printed confirmation to the console.
  • Called setup_version_file from the main installation flow.
install.sh

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @dougsland - I've reviewed your changes - here's some feedback:

Overall Comments:

  • In setup_version_file, assign a default version when not in a git repository to avoid writing an empty string to the version file.
  • Consider handling cases where the regex match fails so that unexpected git describe formats don't lead to unformatted version strings.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

install.sh Show resolved Hide resolved
ramalama/version.py Outdated Show resolved Hide resolved
ramalama/version.py Outdated Show resolved Hide resolved
Today ramalama just share version 0.5.5 (as example) but
don't tell users and developer which commit it's using.

Resolves: containers#754
Signed-off-by: Douglas Schilling Landgraf <[email protected]>
@@ -100,6 +100,29 @@ check_platform() {
return 0
}

setup_version_file() {
Copy link
Member

Choose a reason for hiding this comment

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

This would not work in the pypi install, rpm install, or any install that does not use the install.sh.

Copy link
Member

@engelmi engelmi Feb 7, 2025

Choose a reason for hiding this comment

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

Could we simply use a setup.py.in with a placeholder for the version, i.e. version=@VERSION@, which we can replace at build-time? This could then be used by all means to install ramalama by simply adding this prepare step. Additionally, the version would be hard-coded and uses the git hash only for non-release builds. We use that approach for example in BlueChi
WDYT? @dougsland @rhatdan

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@engelmi I like the idea but maybe we will close this one. WDYT @rhatdan @engelmi ?

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2025

In order to get PRs merged, you need to modify the tests to make sure they pass.

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2025

Why do you care about a git hash? We should be only cutting releases, and then you can go to github.com and look up the release which will point at the github hash?

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2025

@dougsland
Copy link
Collaborator Author

dougsland commented Feb 7, 2025

Why do you care about a git hash? We should be only cutting releases, and then you can go to github.com and look up the release which will point at the github hash?

It's generally useful to include version details in the --version flag so users when visit the release page and can match the commit or just locally via git. Additionally, during development, having the version information helps track which patch is being used, especially when working with multiple patches. After all, when developing it always says v0.5.5 which is not really correct it's release v0.5.5 + current git commit. However, I am okay to close this, if you and guys decide, it's just something I found during my tests+development.

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2025

If you are developing you can just do git log?

@rhatdan rhatdan closed this Feb 7, 2025
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.

ramalama version do not show git hash and date
3 participants