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

The binaries built by the release action include the commit hash in their version #38

Closed
ejpcmac opened this issue Sep 28, 2024 · 1 comment
Labels
A:CLI Area: CLI T:Bug Type: Bug
Milestone

Comments

@ejpcmac
Copy link
Owner

ejpcmac commented Sep 28, 2024

Problem description

If I run a binary downloaded from the release page and print its short version, I get the following:

$ ./git-z-0.2.1-x86_64-unknown-linux-musl -V
git-z 0.2.1+e0e62f1

Expected behaviour

In releases, the short version should not contain the Git revision.

Analysis

In the different build jobs of the release action, the Git repository is cloned using actions/checkout@v4 without any parameter. By default, this only does a shallow clone, which does not include tags. Hence, the build.rs is not able to check whether the build is made from a tag matching the version, and the revision is then included.

Solution

Set fetch-tags: true in the parameters for actions/checkout@v4 for the build-bin, build-deb and build-msi jobs.

^ This solution makes the fetch fail. Replacing it with fetch-depth: 0 makes the build work again, but… does still include the hash.

Second round of analysis

When fetching the repository with fetch-depth: 0 on a tag, the action does the following:

  /usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
  From https://github.com/ejpcmac/git-z
   * [new branch]      develop    -> origin/develop
   * [new branch]      main       -> origin/main
   * [new tag]         v0.1.0     -> v0.1.0
   * [new tag]         v0.2.0     -> v0.2.0
   * [new tag]         v0.2.1     -> v0.2.1
   * [new tag]         v0.2.2     -> v0.2.2
  /usr/bin/git tag --list v0.2.2
  v0.2.2
  /usr/bin/git rev-parse refs/tags/v0.2.2
  2efee1538e1e9a6d61c458b2a1242c32e09f4651
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules origin +45b8aee6cc9d596ce882ee66dd26106e469e1e08:refs/tags/v0.2.2
  From https://github.com/ejpcmac/git-z
   t [tag update]      45b8aee6cc9d596ce882ee66dd26106e469e1e08 -> v0.2.2

Is is then updating the tag so it directly points to the commit, instead of being an annotated tag. This only occurs if the action is triggered on a tag.

I have reproduced the last command locally, and then ran git describe. I am getting the following:

v0.2.1-34-g45b8aee

Thanks to this comment, I have discovered that we can do git describe --tags:

v0.2.2

Second solution

Updating the build.rs to run git describe --tags instead of git describe should fix the issue.

@ejpcmac ejpcmac added this to the git-z 0.2.2 milestone Sep 28, 2024
@ejpcmac ejpcmac added A:CLI Area: CLI T:Bug Type: Bug labels Sep 28, 2024
@ejpcmac ejpcmac moved this from Backlog to Preparation in ejpcmac’s personal OSS work Dec 5, 2024
@ejpcmac ejpcmac moved this from Preparation to Ongoing in ejpcmac’s personal OSS work Dec 5, 2024
ejpcmac added a commit that referenced this issue Dec 5, 2024
The `build.rs` includes the commit hash by default in the version, but
omits it when git-z is built exactly from a release tag. However, tags
were not fetched in the release builds, making them include the commit
hash even for releases.

Refs: #38
@ejpcmac ejpcmac moved this from Ongoing to In Review in ejpcmac’s personal OSS work Dec 5, 2024
@ejpcmac ejpcmac moved this from In Review to Solved in ejpcmac’s personal OSS work Dec 7, 2024
@ejpcmac ejpcmac closed this as completed Dec 8, 2024
@ejpcmac
Copy link
Owner Author

ejpcmac commented Dec 8, 2024

Actually this is not solved 😭

$ ./git-z-0.2.2-x86_64-unknown-linux-musl -V
git-z 0.2.2+45b8aee

@ejpcmac ejpcmac reopened this Dec 8, 2024
@ejpcmac ejpcmac modified the milestones: git-z 0.2.2, git-z 0.2.3 Dec 8, 2024
@ejpcmac ejpcmac moved this from Input to Backlog in ejpcmac’s personal OSS work Dec 8, 2024
@ejpcmac ejpcmac moved this from Backlog to Preparation in ejpcmac’s personal OSS work Feb 19, 2025
ejpcmac added a commit that referenced this issue Feb 19, 2025
The build.rs includes the commit hash by default in the version, but
omits it when git-z is built exactly from a release tag. This is done by
comparing the current version with the output of `git describe`.
However, `git describe` works only with annotated tags, but the GitHub
action used for the release replaces the annotated tag with a
lightweight tag to the same revision.

Using `git describe --tags` should fix the issue.

Refs: #38
@ejpcmac ejpcmac moved this from Preparation to Ongoing in ejpcmac’s personal OSS work Feb 19, 2025
@ejpcmac ejpcmac moved this from Ongoing to In Review in ejpcmac’s personal OSS work Feb 19, 2025
@ejpcmac ejpcmac moved this from In Review to Solved in ejpcmac’s personal OSS work Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:CLI Area: CLI T:Bug Type: Bug
Projects
Status: Solved
Development

No branches or pull requests

1 participant