tools: add repo-version to print a package version from git references#1009
tools: add repo-version to print a package version from git references#1009
Conversation
I would find the no-argument behavior surprising, expecting it to use the current directory rather than Daemon's directory. |
Hmm, right, this would also remove the need for a wrapper in Unvanquished repo. |
09fe590 to
f0ede7a
Compare
Now using the current directory. |
f0ede7a to
f7420aa
Compare
9c2562c to
7ab89e6
Compare
|
My original code was purposed to also handles the cases when:
And to provide fallbacks to them. The reason why I want that is that such permissivity is useful in Urcheon, and at some point I want this code to be exactly the same in Urcheon (I'll replace current Urcheon version code with this one, as it is more mature and less convoluted). So I finally made the script erroring on Git errors, and made it not sending Git error message to We may want to check for the directory always being a repository in the Unvanquished release script, so having this code aborting on error and printing errors is fine. Same if one day we wire it into cmake to embed the result as internal game version string. |
tools/repo-version/repo-version
Outdated
|
|
||
| parser = argparse.ArgumentParser(description="Print repository version string") | ||
|
|
||
| parser.add_argument("-p", "--permissive", dest="is_permissive", help="ignore Git errors", action="store_true") |
There was a problem hiding this comment.
Why would you want to ignore/silence Git errors? It would seem the script can't do anything useful if Git doesn't work.
There was a problem hiding this comment.
If Git doesn't work, and if the script is allowed to continue, it produces a version string using current date with same syntax (using 0 as fallback tag and commit).
By using similar code in Urcheon I can generate versioned dpkdir of a work-in-progress folder even before committing the very first changes, and the fallback version string is compatible with what will be produced once there is a git repository, and once there is a git tag.
Example:
0-20240408-050944+dirty: not a git repository yet, or git repository but no commit yet (date is world date).0-20240408-051101-2bdab49: git repository with committed data but not tag (date is latest commit date).0-20240408-051101-2bdab49+dirty: git repository with committed data but not tag, with uncommitted change (date is latest commit date).0.54.1: git repository, tag is current commit.0.54.1+dirty: git repository, tag is current commit, with uncommitted change.0.54.1-20240408-051101-2bdab49: git repository, untagged commits since latest tag (date is latest commit date).0.54.1-20240408-051101-2bdab49+dirty: git repository, untagged commits since latest tag, with uncommitted change (date is latest commit date).
There was a problem hiding this comment.
I forgot to mention that “Git not working“ is assumed to mean “This directory is not a git repository”, not that Git is not installed. I may add a dedicated check for when Git is not installed at all (like by calling git -v).
There was a problem hiding this comment.
The script now tests if Git is available and working. The --permissive option can only continue on the fallback compute if Git is failing because the directory is not a git repository yet (the reason why there is a fallback).
0c435e4 to
480e4bd
Compare
|
I renamed the tool to I finally ported and improved the complete dirt detection code from Urcheon.
The second feature means doing this I added a |
052017d to
8136de3
Compare
| def isDirtyGit(self): | ||
| if self.is_whole: | ||
| # Git prints the Git repository root directory. | ||
| git_show_toplevel_string, git_show_toplevel_returncode = \ |
There was a problem hiding this comment.
Wouldn't it be easier to omit the git diff final argument instead of having to look up the repository root?
tools/dir-version/dir-version
Outdated
|
|
||
| parser.add_argument("-p", "--permissive", dest="is_permissive", help="ignore Git errors", action="store_true") | ||
| parser.add_argument("-q", "--quiet", dest="is_quiet", help="silence Git errors", action="store_true") | ||
| parser.add_argument("-w", "--whole", dest="is_whole", help="look for dirt in whole repository", action="store_true") |
There was a problem hiding this comment.
I think it is a bad default to depend on the current directory within the repository. What is the use case for that anyway?
There was a problem hiding this comment.
Use case: https://github.com/UnvanquishedAssets/UnvanquishedTestAssets/tree/master/pkg
I can make it non-default, but I need the feature to be there.
There was a problem hiding this comment.
OK, please make it non-default. The subdirectory use case seems second-class because tags are only made at the whole-repository scope, so it may be common to have different tags with identical content.
There was a problem hiding this comment.
Behavior is reversed. By default it now uses the whole repository for computing dirtiness, but can only look for subdirectory dirtiness when using --local.
I'm not very happy with the local name, but current would be confusing as it may give the false idea it's for the folder the script is called from, not the given folder on command line. Suggestions welcome.
| @@ -0,0 +1,151 @@ | |||
| #! /usr/bin/env python3 | |||
8136de3 to
e590eff
Compare
|
Some things I'm still thinking about:
I'm not happy with the original git-version/GitVersion because it was confusing it may provide the version of Git itself, but I'm not happy with repo-version/RepoVersion or dir-version/DirVersion because this is a tool to compute a Git-based version (with a non-Git optional fallback) for a source directory. Git is always required even when the directory is not tracked by Git (to know it's not tracked by Git).
|
|
I would name the tool |
373ac19 to
38d7a7b
Compare
Now renamed |
|
Well, in fact I dislike version-string, as it doesn't tell the version string of what. Actually my initial name of repo-version wasn't bad. |
38d7a7b to
817f6cf
Compare
|
I renamed it |
59e11e9 to
f983698
Compare
This is an extraction and a port to Python of the
printVersionfunction from therelease-scripts/build-releasescript, the produced version string is usable for dpk archives, but also fr other things like unizip or the symbols zip for which we expect to have the same version string of the game dpk.This is a standalone re-implementation of what is done in Urcheon for computing dpk version strings.
This is usable in two ways:
Without argument:
This prints the version string for the current directory.
With argument:
tools/repo-version/repo-version 'path/to/some/other/repository'This prints the version string for the given repository path passed as argument.
This script is stored in Dæmon repository because I want a common place for it. We may even use it when doing nightly builds of the engine only, or things like that.