1 + | |
2 + | $casaBranchHint=$ARGV[0]; |
3 + | $headGrep="-mas-"; |
4 + | $tagid="mas"; |
5 + | |
6 + | $debug=1; |
7 + | print "headGrep: $headGrep\n" if $debug; |
8 + | print "tagId: $tagid\n" if $debug; |
9 + | |
10 + | |
11 + | |
12 + | |
13 + | |
14 + | if ($casaBranchHint) { |
15 + | print "Branch hint provided: $casaBranchHint\n" if $debug; |
16 + | if ($casaBranchHint =~ "^(feature|bugfix).*CAS.*") { |
17 + | @splat = split '/', $casaBranchHint; |
18 + | print "Splat: @splat\n" if $debug; |
19 + | $headGrep = "@splat[0]-@splat[1]"; |
20 + | } elsif ($casaBranchHint =~ "^CAS-.*" ) { |
21 + | $headGrep = $casaBranchHint; |
22 + | } elsif ($casaBranchHint =~ ".*release.*" ) { |
23 + | $headGrep = $casaBranchHint; |
24 + | $tagid="rel"; |
25 + | } elsif ($casaBranchHint =~ "^bambooprtest.*" ) { |
26 + | $headGrep = "bambooprtest"; |
27 + | } |
28 + | } else { |
29 + | print "No branch hint available $casaBranchHint\n" if $debug; |
30 + | |
31 + | } |
32 + | print "headGrep: $headGrep\n" if $debug; |
33 + | |
34 + | |
35 + | $branch = `git rev-parse --abbrev-ref HEAD`; |
36 + | chomp($branch); |
37 + | print "Current branch: $branch\n" if $debug; |
38 + | |
39 + | |
40 + | if ( $branch eq "HEAD") { |
41 + | print "Detached head.\n" if $debug; |
42 + | $headTag = `git tag --points-at HEAD | grep -- $headGrep`; |
43 + | print "Head tag: $headTag\n" if $debug; |
44 + | |
45 + | |
46 + | |
47 + | |
48 + | |
49 + | |
50 + | |
51 + | |
52 + | $casaVersionDesc = $headTag; |
53 + | print("Version Description: $casaVersionDesc\n") if $debug; |
54 + | |
55 + | |
56 + | |
57 + | $forkpoint = `git merge-base master $branch`; |
58 + | print("Default Fork Point: $forkpoint\n") if $debug; |
59 + | if ($casaBranchHint =~ ".*release.*") { |
60 + | $forkpoint=`git merge-base $casaBranchHint $branch`; |
61 + | } |
62 + | print("Fork Point: $forkpoint\n") if $debug; |
63 + | |
64 + | $headTag=`git describe --abbrev=0 --tags --match='[0-9]*.[0-9]*.[0-9]*-mas-[0-9]*' \$(git rev-parse $forkpoint)`; |
65 + | if ($tagid eq "rel") { |
66 + | $headTag=`git describe --abbrev=0 --tags --match='[0-9]*.[0-9]*.[0-9]*-rel-[0-9]*' \$(git rev-parse $forkpoint)`; |
67 + | } |
68 + | chomp($headTag); |
69 + | print("headTag: $headTag\n") if $debug; |
70 + | |
71 + | @splat = split '-',$headTag; |
72 + | if ($casaVersionDesc =~".*-$tagid-.*") { |
73 + | print "$splat[-1]\n"; |
74 + | } |
75 + | else { |
76 + | print "$splat[-1];$casaVersionDesc\n"; |
77 + | } |
78 + | } |
79 + | elsif ($branch eq "master") { |
80 + | |
81 + | $masterTag=`git tag --points-at HEAD | grep -- -mas-`; |
82 + | $headCommit=`git rev-parse HEAD`; |
83 + | $casaVersionDesc=""; |
84 + | if (!$masterTag) { |
85 + | $headCommit=`git rev-parse HEAD`; |
86 + | $masterTag=`git describe --abbrev=0 --match='[0-9]*.[0-9]*.[0-9]*-mas-[0-9]*'`; |
87 + | $needsId=1 |
88 + | } |
89 + | chomp($masterTag); |
90 + | $casaVersionDesc = "ID $headCommit"; |
91 + | chomp($casaVersionDesc); |
92 + | @splat = split '-',$masterTag; |
93 + | if ($needsId) { |
94 + | print "$splat[-1];$casaVersionDesc\n" |
95 + | } |
96 + | else { |
97 + | print "$splat[-1];\n" |
98 + | } |
99 + | } |
100 + | elsif ($branch =~ ".*release.*") { |
101 + | print("Release branch\n") if $debug; |
102 + | $relTag=`git tag --points-at HEAD | grep -- -rel-`; |
103 + | $headCommit=`git rev-parse HEAD`; |
104 + | $casaVersionDesc=""; |
105 + | if (!$relTag) { |
106 + | $headCommit=`git rev-parse HEAD`; |
107 + | $relTag=`git describe --abbrev=0 --match='[0-9]*.[0-9]*.[0-9]*-rel-[0-9]*'`; |
108 + | $needsId=1 |
109 + | } |
110 + | chomp ($relTag); |
111 + | $casaVersionDesc = "ID $headCommit"; |
112 + | chomp($casaVersionDesc); |
113 + | @splat = split '-',$relTag; |
114 + | if ($needsId) { |
115 + | print "$splat[-1];$casaVersionDesc\n" |
116 + | } |
117 + | else { |
118 + | print "$splat[-1];\n" |
119 + | } |
120 + | } |
121 + | else { |
122 + | $tagMatcher = $branch; |
123 + | if ($tagMatcher =~ "/") { |
124 + | $tagMatcher =~ s/\//-/; |
125 + | } |
126 + | print "tagMatcher: $tagMatcher\n" if $debug; |
127 + | $branchTag=`git tag --points-at HEAD | grep -- -$tagMatcher-`; |
128 + | $headCommit=`git rev-parse HEAD`; |
129 + | $casaVersionDesc=""; |
130 + | $needsId=0; |
131 + | if (!$branchTag) { |
132 + | $headCommit=`git rev-parse HEAD`; |
133 + | $branchTag=`git describe --abbrev=0 --match='[0-9]*.[0-9]*.[0-9]*-$tagMatcher-[0-9]*'`; |
134 + | $needsId=1 |
135 + | } |
136 + | chomp ($branchTag); |
137 + | $casaVersionDesc = "ID $headCommit"; |
138 + | chomp($casaVersionDesc); |
139 + | if ($needsId) { |
140 + | print ";$casaVersionDesc\n" |
141 + | } |
142 + | else { |
143 + | print ";$branchTag\n" |
144 + | } |
145 + | |
146 + | } |