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

Kamal::Git.version now uses git describe #409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hey-leon
Copy link

@hey-leon hey-leon commented Aug 3, 2023

Why change Kamal::Git.version?

Currently container names can get very long with - service, role, destination, sha and even possible uncommited changes. This can make them hard to read or compare.

Looking for feedback before finalising this PR

The tests are not passing but I am wondering if there is interest in this change or maybe an alternative one that would simply shorten the sha - e.g. git rev-parse --short HEAD

Description

Previously Kamal::Git.version used rev-parse to retrieve the current commits full sha. While this works it currently creates a very long version name. This PR changes it to use git describe, which will use a tag if it exists, suffix with an abberviated commit sha if there are new commits, and lastly suffix it the same as before if their are uncommited changes. Some e.g.

  • No tags, no uncommited changes: '12er34d5'
  • No tags, uncommited-changes: '12er34d5_uncommited_23494aa9'
  • Tags, no new commits, no uncommited changes: '1.2.3'
  • Tags, new commits, no uncommited changes: '1.2.3-12er34d5'
  • Tags, new commits, uncommited changes: '1.2.3-12er34d5_uncommited_23494aa9'

Further reading: https://git-scm.com/docs/git-describe


"#{`git rev-parse HEAD`.strip}#{uncommitted_suffix}"
if system("git describe")
`git describe --always --dirty='-dirty-#{SecureRandom.hex(8)}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

git describe doesn't treat untracked files as dirty, could we check for them and append the dirty- suffix manually?

Copy link
Author

Choose a reason for hiding this comment

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

Great call out @djmb. I will amend this.

@hey-leon hey-leon changed the title Mrsk::Configuration#git_version now uses git describe Kamal::Git#version now uses git describe Oct 6, 2023
@hey-leon hey-leon changed the title Kamal::Git#version now uses git describe Kamal::Git.version now uses git describe Oct 6, 2023
@hey-leon
Copy link
Author

hey-leon commented Oct 6, 2023

This has been revised to update the new Kamal::Git module

@xiaohui-zhangxh
Copy link
Contributor

need this to be merged, then we can ping the correct container's hostname

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.

3 participants