https://github.com/hugopl/version_from_shard
A macro to declare the VERSION constant from the value found in shard.yml, so you don't need to write the same version number in multiple places.
https://github.com/hugopl/version_from_shard
crystal versioning
Last synced: about 2 months ago
JSON representation
A macro to declare the VERSION constant from the value found in shard.yml, so you don't need to write the same version number in multiple places.
- Host: GitHub
- URL: https://github.com/hugopl/version_from_shard
- Owner: hugopl
- License: mit
- Created: 2019-10-28T19:44:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T20:08:30.000Z (about 2 years ago)
- Last Synced: 2025-02-26T16:04:47.307Z (2 months ago)
- Topics: crystal, versioning
- Language: Crystal
- Homepage:
- Size: 18.6 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

# Version From Shard
A macro to declare the VERSION constant from the value found in `shard.yml`, so you don't need to write the same version number in multiple places.
*⚠ Words of advise ⚠*
I had been using this shard in multiple projects of mine, however nowadays I see that is more pratical to just do:
```Crystal
module MyShard
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }}
end
```The only difference is that you wont have the in between version numbers like `1.0.0+1.g2dd5299`, however for the sake of having less dependencies in my projects I'm starting to remove this dependency from all my projects.
What's this means? This means that soon this project will be archived in github.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
version_from_shard:
github: hugopl/version_from_shard
```2. Run `shards install`
## Usage
```crystal
require "version_from_shard"module MyAwesomeApp
VersionFromShard.declare
endputs MyAwesomeApp::VERSION # Should print the version value found in shard.yml, e.g. "1.0.0"
```If you are developing a library is necessary to pass \_\_DIR__ to the declare macro, otherwise when compiling a
application using your library it will show the version of the application instead the version of your library.
So, on libraries do:```crystal
module MyAwesomeLib
VersionFromShard.declare(__DIR__)
end# Then, the App code can safely do:
puts "Awesome app v#{MyAwesomeApp::VERSION} using awesome lib v#{MyAwesomeLib::VERSION}"
```When compiling a development version, i.e. not a tagged commit, the version will try to
use `git describe --tags` output (ignoring tag prefixes) for the version string. If git isn't
found or someone is compiling the project from a tarball, normal version will be used.Example:
You have `version: 1.0.0` on your shard.yml file but your master branch is 1 commit ahead of the tag named `v1.0.0` that you released yesterday, in this case VersionFromShard.declare will declare a VERSION constant with the value `1.0.0+1.g2dd5299`, assuming `2dd5299` is the current commit hash, note the `g` prefix, that means git.
## About Semantic Version
[This issue](https://github.com/semver/semver/issues/200) summarize the problems with semantic version and nightly builds
when you don't know yet if the final version of your software will increase a major, minor or patch version.## Development
Suggestions are welcome.
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Hugo Parente Lima](https://github.com/hugopl) - creator and maintainer