Commits

Ville Suoranta authored 1d100f9678f
Versioning updates

scripts/version

Modified
1 1 #!/usr/bin/perl
2 2
3 -open( $gitver, "git tag -l '[0-9]*.[0-9]*.[0-9]*' 2> /dev/null |" );
4 -chomp( @versions = <$gitver> );
5 -close( $gitver );
6 -@versions = grep(/^\d+.\d+.\d$/, @versions);
7 -sort @versions;
8 -print( $versions[$#versions], "\n" );
3 +# This script has to be run within the Git repository. It will inspect the
4 +# state of the current tree/branch in the workspace.
5 +
6 +# Version type is used to select the appropriate grep pattern.
7 +# The idea is to look for either the latest master/release type tag "\d+.\d+.\d+.\d+"
8 +# or CAS-<number>-x tags. Both are required to construct a meaningful number for
9 +# the casatools/tasks wheels
10 +
11 +my $gitbranch=`git rev-parse --abbrev-ref HEAD`;
12 +chomp($gitbranch);
13 +my $last_branch_tag="";
14 +my $last_release_tag="";
15 +if ($gitbranch eq "master" || $gitbranch =~ "release/"){
16 + $last_release_tag=get_last_release_tag ($gitbranch);
17 + $last_branch_tag=$last_release_tag;
18 +} else {
19 + $last_release_tag=get_last_release_tag ($gitbranch);
20 + $last_branch_tag=get_last_branch_tag ($gitbranch);
21 +}
22 +
23 +print ("$last_branch_tag $last_release_tag");
24 +my $headcommit=`git rev-parse HEAD`;
25 +
26 +# No tag at all for branch
27 +if ($last_branch_tag eq "") {
28 + print (" dirty");
29 +# Check if the latest tag is the latest commit
30 +} else {
31 + my $tagcommit=`git rev-list -n 1 $last_branch_tag`;
32 + if ($headcommit ne $tagcommit) {
33 + print (" dirty");
34 + }
35 +}
36 +
37 +print ("\n");
38 +
39 +sub get_last_branch_tag () {
40 + my $gitbranch = shift;
41 + my $branchpattern = qr/^$gitbranch-\d+/;
42 + my $delim="-";
43 + return get_last_tag($gitbranch,$branchpattern,$delim)
44 +}
45 +
46 +sub get_last_release_tag () {
47 + my $gitbranch = shift;
48 + my $branchpattern = qr/^\d+\.\d+\.\d+$/;
49 + my $delim="\\.";
50 + return get_last_tag($gitbranch,$branchpattern,$delim)
51 +}
52 +
53 +sub get_last_tag () {
54 + my $gitbranch = shift;
55 + my $branchpattern = shift;
56 + my $delim = shift;
57 + my @versions;
58 + my @tags;
59 + open( $githashes, "git log --since 2019-10-01 --simplify-by-decoration --pretty='%H' ".$gitbranch." |" );
60 + chomp( @hashes = <$githashes> );
61 + close( $githashes );
62 + foreach ( @hashes ) {
63 + #print "$_\n";
64 + # This distinction was added in case there are multiple release tags. I am not certain that
65 + # this is going to happen in practice.
66 + if ($gitbranch =~ "release/"){
67 + $releaseid=(split('/',$gitbranch))[-1];
68 + $grep_cmd = "git tag -l | grep \"" . "^" .$releaseid . "\" | ";
69 + open( $gitver, "git show-ref --tags -d | grep ^" . $_ . " | sed -e 's,.* refs/tags/,,' | grep " .$releaseid ." |sed -e 's/\\^{}//' 2> /dev/null |" );
70 + chomp( @tags = <$gitver> );
71 + close( $gitver );
72 + }
73 + else{
74 + open( $gitver, "git show-ref --tags -d | grep ^" . $_ . " | sed -e 's,.* refs/tags/,,' | sed -e 's/\\^{}//' 2> /dev/null |" );
75 + chomp( @tags = <$gitver> );
76 + close( $gitver );
77 + }
78 +
79 + #print(@tags);
80 + foreach my $tag (@tags) {
81 + #print("$branchpattern\n");
82 + if(grep(/$branchpattern/, $tag)) {
83 + #print(grep($branchpattern, $tag). "\n");
84 + #print("Pushing $tag\n");
85 + push @versions, $tag;
86 + }
87 + }
88 + # Found one or more matching master/release tags
89 + last if (scalar @versions >= 1);
90 + }
91 + my @sorted =
92 + map { $_->[0] }
93 + sort { $a->[1] cmp $b->[1] }
94 + map { [$_, join '', map { sprintf "%8d", $_ } split $delim, $_] }
95 + @versions;
96 +
97 + return($sorted[$#sorted]);
98 +}

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut