meta: version from git support. #1260

Merged
merged 10 commits into from Apr 19, 2017

Conversation

Projects
None yet
3 participants
Collaborator

sergiusens commented Apr 17, 2017

If version: git is set, snapcraft will determine
the version using git and its tags.

Signed-off-by: Sergio Schvezov sergio.schvezov@canonical.com

meta: version from git support.
If `version: git` is set, snapcraft will determine
the version using git and tags.

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>

I think it's fine, although I recommend tightening up the regexp a little bit.

snapcraft/internal/sources/_git.py
+ '--always']).decode(sys.getfilesystemencoding()).strip()
+ return '0+git.{}'.format(output)
+
+ m = re.search(r'(?P<tag>.*)-(?P<revs_ahead>.*)-g(?P<commit>.*)',
@chipaca

chipaca Apr 18, 2017

Member

to avoid surprises I'd suggest anchoring this at both ends (i.e. start it with ^, end it with $). Also if revs_ahead is expected to be a number, you want \d+, not .*. Also nothing here should be .*; you want at least one char, and they should all be non-whitespace probably (so \S+), and I suspect commit is expected to be hexadecimal so [0-9a-fA-F]+.

@sergiusens

sergiusens Apr 18, 2017

Collaborator

thanks, this is exactly why I wanted you to review!

@chipaca

chipaca Apr 18, 2017

Member

hah! you know me too well 😁

@sergiusens

sergiusens Apr 18, 2017

Collaborator

For the tag, it can be anything but whitespace, so I stole our regex in place from schema/snapcraft.yaml which for version is ^[a-zA-Z0-9.+~-]*$

+ parts:
+ nil:
+ plugin: nil
+ """), file=f)
@elopio

elopio Apr 19, 2017

Member

Almost all the other tests use an existing yaml instead of writing one. Is there a reason here to do it differently?

@sergiusens

sergiusens Apr 19, 2017

Collaborator

Because there are no files aside from snapcraft.yaml added. I've been finding it a pain to easily troubleshoot these split ones when they break.

A few problems I found testing this:

When I don't have a tag, this message is printed:
fatal: No names found, cannot describe anything.

The error message is not terrible, but it has no context at all. And it says fatal. I would put a warning with more information explaining that this is while trying to set the version, and without the word fatal.

When the snap is not in a git repository, I get this error:
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Command '['git', '-C', '/tmp/local-plugin', 'describe', '--tags', '--dirty', '--always']' returned non-zero exit status 128

That error should explain that the git keyword can only be used when the snapcraft.yaml is in a git repo.

And finally, PR should be accompanied by a pr in snappy-docs explaining the new feature.

snapcraft/internal/sources/_git.py
+ def generate_version(cls, *, source_dir=None):
+ """Return the latest git tag from PWD or defined source_dir.
+
+ The output depends on the use of annotated tags, an will return
@elopio

elopio Apr 19, 2017

Member

typo: an -> and

@sergiusens

sergiusens Apr 19, 2017

Collaborator

fixed

snapcraft/internal/sources/_git.py
+ output = subprocess.check_output([
+ 'git', '-C', source_dir, 'describe',
+ '--dirty']).decode(sys.getfilesystemencoding()).strip()
+ except subprocess.CalledProcessError:
@elopio

elopio Apr 19, 2017

Member

It would be nice to add a comment here about what does this exception mean.

@sergiusens

sergiusens Apr 19, 2017

Collaborator

done

snapcraft/tests/sources/test_git.py
+ def test_version(self):
+ if self.tag:
+ self.output_mock.return_value = self.return_value.encode('utf-8')
+ else:
@elopio

elopio Apr 19, 2017

Member

I would prefer to move the no-tag case to a different test, to avoid the if block here.

@sergiusens

sergiusens Apr 19, 2017

Collaborator

done

Collaborator

sergiusens commented Apr 19, 2017

And finally, PR should be accompanied by a pr in snappy-docs explaining the new feature

This is what the forum post is for 😉

Collaborator

sergiusens commented Apr 19, 2017

fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Command '['git', '-C', '/tmp/local-plugin', 'describe', '--tags', '--dirty', '--always']' returned non-zero exit status 128

is fixed

Collaborator

sergiusens commented Apr 19, 2017

When I don't have a tag, this message is printed:

fatal: No names found, cannot describe anything.

this is no longer shown

Member

elopio commented Apr 19, 2017

@sergiusens: I don't think that this is enough:
fatal: Not a git repository (or any of the parent directories): .git

It's not mentioning that the error comes from the version field. My first reaction would be to check the parts, not the version. And as the parts are likely to come from git, I would find myself confused for a while.

I'm pretty happy with the rest, and tested it enough. So I'll leave my +1. But please consider extending the message.

@sergiusens sergiusens added this to the 2.29 milestone Apr 19, 2017

@sergiusens sergiusens merged commit 1a936f4 into snapcore:master Apr 19, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@sergiusens sergiusens deleted the sergiusens:version-from-git branch Apr 19, 2017

elopio added a commit that referenced this pull request Apr 27, 2017

meta: version from git support. (#1260)
If `version: git` is set, snapcraft will determine
the version using git and tags.

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment