-
Notifications
You must be signed in to change notification settings - Fork 224
build/git-version: Only call 'git' once #951
build/git-version: Only call 'git' once #951
Conversation
Can one of the admins verify this patch? |
3 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Simplify the logic from 04848d1 (Add release build process, 2016-05-27, kubernetes-retired#47) to: * Move from Bash to a generic POSIX shell. This makes the script more portable (it will work on POSIX systems without Bash). It does mean we need to drop the 'set' (which is not in POSIX [1]), but that's not a major problem because: * We can use &&-chaining instead of 'set -e'. * We do only have the one locally-defined variable, so we don't need 'set -u'. * The simpler logic has no pipes, so 'set -o pipefail' would no longer matter. * Replace the previous multiple Git calls with a single call to 'git describe'. * Use --dirty so we can drop the previous diff call. * Drop --tags, because we don't want to use lightweight (non-annotated) tags. We want to use annotated tags, because we want to use signed release tags. There's no code check for tag signatures here, but RELEASING.md requests 'tag -s vX.Y.Z', which will create signed, annotated tags. * Git's SHA-1 hashes are 40 hex digits, but I've used --abbrev=100 to get unabbreviated hashes even in the face of future hash transitions [2]. This is a bit of a hack compared to the previous approach, because at some point Git may have >100-char hashes. But if that happens, it will be far enough in the future that I think the simplification we get here is worth it (and this constant is easy to bump if we need to). * The new call always returns the most recent tag, and (for commits which are not exact tag matches) also includes the abbreviated commit. To isolate the hash (and possible dirty-mark) for commits that are not exact tags, I use POSIX's ${parameter##[word]} prefix-pattern removal [3]. Exact tags are unlikely to include '-g' (unless it is in the tag itself), so for them the prefix-removal is a no-op. Again, this is a bit of a hack, since a tag might include '-g', but I think that's unlikely enough (as mentioned above, RELEASING.md requests vX.Y.Z for tags) that the simplification we get here is worth it. [1]: http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html [2]: https://github.com/git/git/blob/v2.16.3/Documentation/technical/hash-function-transition.txt [3]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
193ce7c
to
3b0431f
Compare
ok to test |
fi | ||
|
||
echo $VERSION | ||
DESCRIPTION=$(git describe --abbrev=100 --dirty) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has an extra && at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has an extra && at the end
Yup, that's the &&
-chaining I mention in the initial post. It ensured that the script exits with a non-zero exit code if for some reason the subshell here does. You can test that behavior by calling the script from outside of aa Git repo (e.g. from /
) and confirming its non-zero exit code.
Simplify the logic from #47 to:
Move from Bash to a generic POSIX shell. This makes the script more portable (it will work on POSIX systems without Bash). It does mean we need to drop the
set
(which is not in POSIX), but that's not a major problem because:&&
-chaining instead ofset -e
.set -u
.set -o pipefail
would no longer matter.Replace the previous multiple Git calls with a single call to
git describe
.Use
--dirty
so we can drop the previousdiff
call.Drop
--tags
, because we don't want to use lightweight (non-annotated) tags. We want to use annotated tags, because we want to use signed release tags. There's no code check for tag signatures here, butRELEASING.md
requeststag -s vX.Y.Z
, which will create signed, annotated tags.Git's SHA-1 hashes are 40 hex digits, but I've used
--abbrev=100
to get unabbreviated hashes even in the face of future hash transitions. This is a bit of a hack compared to the previous approach, because at some point Git may have >100-char hashes. But if that happens, it will be far enough in the future that I think the simplification we get here is worth it (and this constant is easy to bump if we need to).The new call always returns the most recent tag, and (for commits which are not exact tag matches) also includes the abbreviated commit. To isolate the hash (and possible dirty-mark) for commits that are not exact tags, I use POSIX's
${parameter##[word]}
prefix-pattern removal. Exact tags are unlikely to include-g
(unless it is in the tag itself), so for them the prefix-removal is a no-op. Again, this is a bit of a hack, since a tag might include-g
, but I think that's unlikely enough (as mentioned above,RELEASING.md
requestsvX.Y.Z
for tags) that the simplification we get here is worth it.Fixes #132.