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

rebar_git_resource may produce incorrect versions #2235

Closed
max-au opened this issue Feb 20, 2020 · 3 comments
Closed

rebar_git_resource may produce incorrect versions #2235

max-au opened this issue Feb 20, 2020 · 3 comments

Comments

@max-au
Copy link
Contributor

max-au commented Feb 20, 2020

rebar supports {vsn, git} in myapp.app.src file, which is converted into actual version here:
https://github.com/erlang/rebar3/blob/master/src/rebar_git_resource.erl#L345-L355

However it is possible that git tag is not myapp-1.2.3. It is also possible that git tag contains directory separators. Hence https://github.com/erlang/rebar3/blob/master/src/rebar_git_resource.erl#L338 produces something exotic, for example:

063ecc4f (tag: myrepo/myapp/063eca9) Commit message 3
a3a268c1 (tag: myrepo/myapp/a3a26ae) Commit message 2
76543210 (tag: myrepo/myapp/1234567) Commit message 1

This will generate myapp.app file containing {vsn, "myrepo/myapp/063eca9"} - with slashes in application version. Then, relx will generate a release with sub-folders myrepo/myapp, and a single directory 063eca9 containing actual app.

There are at least 3 possible fixes to this:

  1. If git tag does not form valid semver, replace it with 0.0.0 (current default behaviour if git fails to fetch tags).
  2. If git tag contains slashes, strip everything but keep only the last portion. This will replace myrepo/myapp/063eca9 with just 063eca9
  3. Replace characters that are not expected in vsn with dots - for example, transform "myrepo/myapp/063eca9" into "myrepo.myapp.063eca9

Out of these 3, last one looks to keep most information available. Are there any more options?

@tsloughter
Copy link
Collaborator

There may be a better git way of doing this as well now.

I don't remember why we even use that line instead of just git describe --tags --abbrev=0 which we fallback to on nomatch...

@max-au
Copy link
Contributor Author

max-au commented Feb 21, 2020

It there are no objections, I'd be happy to remove regex, and the whole call to
git -c color.ui=false log --oneline --no-walk --tags --decorate

It's rather slow and does not seem to help much. Also I can't find any documentation on how {vsn, git} is supposed to work.

Also, I found one example of even more exotic case: https://github.com/tomas-abrahamsson/gpb/blob/master/src/gpb.app.src#L24
Not sure if it's supported, but quite interesting case.

@ferd
Copy link
Collaborator

ferd commented Feb 21, 2020

Yeah that's a supported format:

rebar3/src/rebar_utils.erl

Lines 742 to 743 in 8ff256d

{cmd, CmdString} ->
cmd_vsn_invoke(CmdString, rebar_app_info:dir(AppInfo));
however since it's an arbitrary command, we pick the string, trim it, and leave it at that

I'm fine more or less getting rid of the slow line (git -c color.ui=false log --oneline --no-walk --tags --decorate) and attached regexes, we'll be going through a major release candidate period for the next release so if there's a time to do it, it's as good as any.

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

3 participants