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

App version with pure Go Git and SemVer libraries #93

Conversation

arcticicestudio
Copy link
Owner

Resolves #92

Previously the version of the application was determined by calling
`git` commands in a new shell process. This works in most cases,
but might fail if Git is not installed on the running system.
To prevent further enlargement of the required development environment
setup dependencies by adding more checks for external dependencies,
the `go-git` library v4 [1] (`github.com/src-d/go-git/v4`) has been
added:
"A highly extensible Git implementation in pure Go"

It allows to interact with the project repository and extrac required
information like the latest tag and commit of the current branch to
assemble the application version. To simplify the processing and parsing
of the version, the `semver` library v3 [2]
(`github.com/Masterminds/semver/v3`) has also been added.

The new `getAppVersionFromGit()` function assembles the version of the
application from the metadata of the Git repository.
It searches for the latest "SemVer" [3] compatible version tag in the
current branch and falls back to the default version from the
application configuration if none is found.
If at least one tag is found but it is not the latest commit of the
current branch, the build metadata will be appended, consisting of the
amount of commits ahead and the shortened reference hash (8 digits) of
the latest commit from the current branch.
The function is a early implementation of the Git `describe` command
because support in `go-git` [1] has not been implemented yet. See the
full compatibility comparison documentation with Git [4] as well as the
proposed Git `describe` command implementation [5] for more details.

[1]: https://github.com/src-d/go-git/v4
[2]: https://github.com/Masterminds/semver/v3
[3]: https://semver.org
[4]: https://github.com/src-d/go-git/blob/master/COMPATIBILITY.md
[5]: src-d/go-git#816

Epic GH-33
GH-92
…data

The function implemented in the parent commit returned a string which
results in loss of addiional data when used for other tasks.

To allow to use the version metadata for other tasks, like adding more
information to the compiled binary artifact, the function now returns a
custom struct that is composed of a `semver.Version` struct and
additional fields that stores Git related information:

- `GitCommitHash` (type `plumbing.Hash`) - The latest commit hash of the
  current branch.
- `GitCommitsAhead` (type `int`) - The count of commits ahead to the
  latest Git tag from the current branch.
- `GitLatestVersionTag` (type `plumbing.Reference`) - The latest Git
  version tag in the current branch.

Epic GH-33
GH-92
@arcticicestudio arcticicestudio merged commit 532e680 into epic/gh-33-the-way-to-go Oct 18, 2019
0.4.0 automation moved this from Review & PR to Done Oct 18, 2019
@arcticicestudio arcticicestudio deleted the improvement/gh-92-app-version-pure-go-git-and-semver-libs branch October 18, 2019 11:18
svengreb pushed a commit that referenced this pull request Oct 18, 2019
Previously the `info` command printed more detailed application
information compared to the compact and machine-friendly `--version`
global flag. The name of command was not optimal as it could give the
impression that it provides more "info"rmation about one or more
snowblocks that might be passed as argument(s). Therefore the command
has been renamed to `version` which also matches the naming of many
other Go CLI apps like Kubernetes [1] `kubectl` [2].

To also enhance the provided information the command now prints more
application version details using the function implemented in GH-93.

[1]: https://kubernetes.io
[2]: https://github.com/kubernetes/kubernetes/tree/master/pkg/kubectl

Epic GH-33
Relates to GH-93
GH-94
arcticicestudio added a commit that referenced this pull request Oct 18, 2019
Previously the `info` command printed more detailed application
information compared to the compact and machine-friendly `--version`
global flag. The name of command was not optimal as it could give the
impression that it provides more "info"rmation about one or more
snowblocks that might be passed as argument(s). Therefore the command
has been renamed to `version` which also matches the naming of many
other Go CLI apps like Kubernetes [1] `kubectl` [2].

To also enhance the provided information the command now prints more
application version details using the function implemented in GH-93.

[1]: https://kubernetes.io
[2]: https://github.com/kubernetes/kubernetes/tree/master/pkg/kubectl

Epic GH-33
Relates to GH-93
Resolves GH-94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
0.4.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants