versionator
versionator
Embeddable versions in crystal applications at compile time. Convention over configuration with git tags.
![Photo of chairs by James Wheeler](https://github.com/dyslexic-degenerate/versionator/raw/master/eric-krull-Ejcuhcdfwrs-unsplash.jpg)
Project Health Status
Quick start
Add the dependency to your shard.yml
and install versionator.
dependencies:
versionator:
github: dyslexic-degenerate/versionator
> shards install
Require versionator and use it to access the version:
require "versionator"
module MyApp
puts "version: #{Versionator.version}"
end
Make sure you have git tags:
> git tag
v1.0.0
v1.0.1
# set one if not (don't forget to push it)
> git tag v1.0.1
Build your application:
> shards build
> ./bin/myapp
version: v1.0.1
Or build your application and embed your custom version:
> VERSIONATOR=x.y.z shards build
> ./bin/myapp
version: x.y.z
Fun Stuff...
Versionator leverages convention over configuration by extracting the current version at compile time directly from git using git describe --tags --dirty
.
For details on git describe
and how it works: https://git-scm.com/docs/git-describe
This versioning technique extracts the most recent tag set using git tag
.
In order for this to work you must have at least one tag set.
Don't forget to git push
and git fetch
your tags.
For example:
# When the most recent tag matches the most recent commit with a clean working tree
> git describe --tags --dirty
v1.0.0
# When the most recent tag matches the most recent commit with a dirty working tree
> git describe --tags --dirty
v1.0.0-dirty
# When the most recent tag is 4 commits behind the most recent commit with a clean working tree
> git describe --tags --dirty
v1.0.0-4-gc3a421b
# When the most recent tag is 4 commits behind the most recent commit with a dirty working tree
> git describe --tags --dirty
v1.0.0-7-gc3a421b-dirty
This versioning technique allows you to get detailed information about the current code being executed within the compiled application.
Common Usage
Leverage git describe --tags --dirty
to provide versioning information. All you need are git tag
's and Versionator.version
.
For example:
> shards build
> ./bin/myapp
v1.0.0-7-gc3a421b-dirty
# sanity check :)
> git describe --tags --dirty
v1.0.0-7-gc3a421b-dirty
When you don't have git for some reason during compilation (not that unusual for release build chains) you can use the VERSIONATOR environment variable to embed the version:
> VERSIONATOR=v1.0.1 shards build
> ./bin/myapp
version: v1.0.1
Contributing
- Fork it (https://github.com/dyslexic-degenerate/versionator/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Dyslexic Degenerate - creator and maintainer
versionator
- 1
- 0
- 0
- 0
- 0
- over 3 years ago
- May 26, 2021
MIT License
Mon, 17 Feb 2025 21:22:07 GMT