-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate version stamp at build time. (#7)
Inspects git tags to find the largest stamped version that is an ancestor of the current commit. That is used as the version for the build.
- Loading branch information
Showing
5 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
for tag in $(git tag) ; do | ||
if git merge-base --is-ancestor ${tag} HEAD; then | ||
echo ${tag} | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#! /bin/bash | ||
|
||
export revision="$(git rev-parse HEAD)" | ||
revision="$(git rev-parse HEAD)" | ||
|
||
if ! [[ -z "$(git status --short)" ]]; then | ||
export revision="${revision}-modified" | ||
revision="${revision}-modified" | ||
fi | ||
|
||
echo "${revision}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
version=$(./ancestors.sh | ./max-version.pl) | ||
revision=$(./get-revision.sh) | ||
|
||
|
||
if [[ $(git rev-parse ${version}) != ${revision} ]]; then | ||
version="${version}-modified" | ||
fi | ||
|
||
echo ${version} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#! /usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
my $maxMajor = 0; | ||
my $maxMinor = 0; | ||
my $maxPatch = 0; | ||
my $maxTag = ""; | ||
|
||
while(my $row = <STDIN>) { | ||
if ($row =~ /^[vV]?(?<major>\d+)(?:\.(?<minor>\d+))?(?:\.(?<patch>\d+))?(?:-(?<tag>\S+))?$/) { | ||
my $currentMajor = int($+{major}); | ||
my $currentMinor = int($+{minor}); | ||
my $currentPatch = int($+{patch}); | ||
my $currentTag = $+{tag}; | ||
|
||
if (not defined $currentMinor) { | ||
$currentMinor = 0; | ||
} | ||
|
||
if (not defined $currentPatch) { | ||
$currentPatch = 0; | ||
} | ||
|
||
if (not defined $currentTag) { | ||
$currentTag = ""; | ||
} | ||
|
||
if ($currentMajor > $maxMajor) { | ||
$maxMajor = $currentMajor; | ||
$maxMinor = $currentMinor; | ||
$maxPatch = $currentPatch; | ||
$maxTag = $currentTag; | ||
next; | ||
} elsif ($currentMajor < $maxMajor) { | ||
next; | ||
} | ||
|
||
if ($currentMinor > $maxMinor) { | ||
$maxMinor = $currentMinor; | ||
$maxPatch = $currentPatch; | ||
$maxTag = $currentTag; | ||
next; | ||
} elsif ($currentMinor < $maxMinor) { | ||
next; | ||
} | ||
|
||
if ($currentPatch > $maxPatch) { | ||
$maxPatch = $currentPatch; | ||
$maxTag = $currentTag; | ||
next; | ||
} elsif ($currentPatch < $maxPatch) { | ||
next; | ||
} | ||
|
||
if ($currentTag eq "" and $maxTag ne "") { | ||
$maxTag = $currentTag; | ||
next; | ||
} elsif ($maxTag eq "" and $currentTag ne ""){ | ||
next; | ||
} elsif ($currentTag gt $maxTag) { | ||
$maxTag = $currentTag; | ||
next | ||
} elsif ($currentTag le $maxTag) { | ||
next; | ||
} | ||
} | ||
} | ||
|
||
my $formatted = "v${maxMajor}.${maxMinor}.${maxPatch}"; | ||
if ($maxTag ne "") { | ||
$formatted = $formatted . "-${maxTag}"; | ||
} | ||
|
||
print($formatted . "\n"); |