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

RFC: shards version to obtain current version defined in shard.yml #147

Closed
luislavena opened this issue Jan 21, 2017 · 7 comments
Closed

Comments

@luislavena
Copy link
Contributor

For some libraries I define VERSION constant to help me obtain version information at runtime of the components used by other tools.

The issue I found is that on every release, I have to update version.cr, shard.yml and match with the tag used in Git.

Was thinking that could be possible to introduce a way to read shard.yml (provided by shards itself) so a macro can be used to generate the VERSION constant.

Not sure about the name of the command, but if approved I can send a pull request to introduce it.

Thank you. ❤️ ❤️ ❤️

@Sija
Copy link
Contributor

Sija commented Jan 21, 2017

Sth like this? :)

module Foo
  VERSION = begin
    YAML.parse(File.read(File.join(__DIR__, "../..", "shard.yml")))["version"].as_s
  end
end

@luislavena
Copy link
Contributor Author

luislavena commented Jan 21, 2017 via email

@mverzilli
Copy link

I think it's a valuable addition. @ysbaddaden, would you be against adding this?

@ysbaddaden
Copy link
Contributor

ysbaddaden commented Jan 30, 2017

No strong opinion. That would allow something like:

module Wonderful
  VERSION = {{ `shards version` }}
end

Thought, how to be sure that the folder the command is run in, is the one with the expected shard.yml? Won't it usually be the main project's folder? This is fine for the project, but that will fail for libraries installed under lib. This is the only issue I foresee.

Or maybe the following would work, granted that the command would search the parent folders recursively for a shard.yml file:

module Wonderful
  VERSION = {{ `shards version __DIR__` }}
end

@luislavena
Copy link
Contributor Author

Thank you @ysbaddaden for taking the time to look into this.

Really didn't put a lot of thought into the idea, which got exposed by the issue you described for libs (and what could be a problem).

I think that shards version __DIR__ is a nice a nice solution!

Will you accept such contribution? Will try to find some time to hack on this during the weekend.

Thank you.

❤️ ❤️ ❤️

@ysbaddaden
Copy link
Contributor

Please do ❤️

@luislavena
Copy link
Contributor Author

Done!, submitted #148.

Cheers! 😸

f-fr pushed a commit to f-fr/shards that referenced this issue Jan 2, 2021
Sometimes is useful to obtain the current version string of the
library/project you're working on, either to help you determine if
was bumped (when preparing for a new release) or when integrating
it within the library's `VERSION` constant (through macros).

This change introduces `version` command for such purpose, allowing
you retrieve from current directory (by default) or be able to
provide a different path.

Usage example

    module Foo
      VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}
    end

Resulting in a `Foo::VERSION` matching the `version` defined in
`shard.yml`.

Fixes crystal-lang#147
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

No branches or pull requests

4 participants