Skip to content

Commit 414d526

Browse files
committed
Add get_next_tag_based_release function
1 parent 76bd14d commit 414d526

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

README.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,28 @@ version=$( strip_snapshot_suffix "1.2.3-SNAPSHOT" )
206206
version=$( strip_snapshot_suffix "1.2.3.BUILD-SNAPSHOT" )
207207
----
208208

209+
==== get_next_milestone_release / get_next_rc_release
210+
Get the next milestone or release candidate version based on a given version and existing git tags.
211+
These methods allow preview releases to be published, without needing to directly store the release number.
212+
213+
For example, given a repository with the following tags:
214+
215+
[source]
216+
----
217+
$ git tag --list
218+
v1.0.0.M1
219+
v1.0.0.M2
220+
v1.0.0.M3
221+
----
222+
223+
The following call will set `next` to `1.0.0.M4`.
224+
225+
[source,bash]
226+
----
227+
next=$( get_next_milestone_release "1.0.0.BUILD-SNAPSHOT")
228+
----
229+
230+
TIP: Version numbers in the form `1.0.0-SNAPSHOT` and `1.0.0.BUILD-SNAPSHOT` are both supported
231+
209232
=== Contributing
210233
See link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] for details of how to contribute.

concourse-java.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ set_revision_to_pom() {
5555
sed -ie "s|<revision>.*</revision>|<revision>${1}</revision>|" pom.xml > /dev/null
5656
}
5757

58+
# Get the next milestone release for the given number by inspecting current tags
59+
get_next_milestone_release() {
60+
[[ -n $1 ]] || { echo "missing get_next_milestone_release() version argument" >&2; return 1; }
61+
get_next_tag_based_release "$1" "M"
62+
}
63+
64+
# Get the next RC release for the given number by inspecting current tags
65+
get_next_rc_release() {
66+
[[ -n $1 ]] || { echo "missing get_next_rc_release() version argument" >&2; return 1; }
67+
get_next_tag_based_release "$1" "RC"
68+
}
69+
70+
# Get the next milestone or RC release for the given number by inspecting current tags
71+
get_next_tag_based_release() {
72+
[[ -n $1 ]] || { echo "missing get_next_tag_based_release() version argument" >&2; return 1; }
73+
[[ -n $2 ]] || { echo "missing get_next_tag_based_release() tag type argument" >&2; return 1; }
74+
if [[ $1 =~ ^(.*)\.BUILD-SNAPSHOT$ ]]; then
75+
local join="."
76+
else
77+
local join="-"
78+
fi
79+
local version
80+
local last
81+
version=$( strip_snapshot_suffix "$1" )
82+
git fetch --tags --all > /dev/null
83+
last=$( git tag --list "v${version}${join}${2}*" | sed -E "s/^.*${2}([0-9]+)$/\1/g" | sort -rn | head -n1 )
84+
if [[ -z $last ]]; then
85+
last="0"
86+
fi
87+
last="${version}${join}${2}${last}"
88+
bump_version_number "$last"
89+
}
90+
5891
# Bump version number by incrementing the last numeric, RC or M token
5992
bump_version_number() {
6093
local version=$1

test/get_next_release.bats

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!./test/libs/bats/bin/bats
2+
3+
load 'libs/bats-support/load'
4+
load 'libs/bats-assert/load'
5+
6+
source "$PWD/concourse-java.sh"
7+
8+
@test "get_next_milestone_release() when has no version should fail" {
9+
run get_next_milestone_release
10+
assert [ "$status" -eq 1 ]
11+
assert_output "missing get_next_milestone_release() version argument"
12+
}
13+
14+
@test "get_next_rc_release() when has no version should fail" {
15+
run get_next_rc_release
16+
assert [ "$status" -eq 1 ]
17+
assert_output "missing get_next_rc_release() version argument"
18+
}
19+
20+
@test "get_next_tag_based_release() when has no version should fail" {
21+
run get_next_tag_based_release
22+
assert [ "$status" -eq 1 ]
23+
assert_output "missing get_next_tag_based_release() version argument"
24+
}
25+
26+
@test "get_next_tag_based_release() when has no tag type should fail" {
27+
run get_next_tag_based_release "1.2.3"
28+
assert [ "$status" -eq 1 ]
29+
assert_output "missing get_next_tag_based_release() tag type argument"
30+
}
31+
32+
@test "get_next_milestone_release() when has no tag should return M1" {
33+
repo=$( mock_git_repo )
34+
cd "$repo"
35+
run get_next_milestone_release "1.2.3-SNAPSHOT"
36+
assert_output "1.2.3-M1"
37+
}
38+
39+
@test "get_next_rc_release() when has no tag should return RC1" {
40+
repo=$( mock_git_repo )
41+
cd "$repo"
42+
run get_next_rc_release "1.2.3-SNAPSHOT"
43+
assert_output "1.2.3-RC1"
44+
}
45+
46+
@test "get_next_tag_based_release() when has no tag and dashed should return dashed X1" {
47+
repo=$( mock_git_repo )
48+
cd "$repo"
49+
run get_next_tag_based_release "1.2.3-SNAPSHOT" "X"
50+
assert_output "1.2.3-X1"
51+
}
52+
53+
@test "get_next_tag_based_release() when has no tag and dashed should return dashed X1" {
54+
repo=$( mock_git_repo )
55+
cd "$repo"
56+
run get_next_tag_based_release "1.2.3.BUILD-SNAPSHOT" "X"
57+
assert_output "1.2.3.X1"
58+
}
59+
60+
@test "get_next_tag_based_release() when has tags and dashed should return dashed X tag+1" {
61+
repo=$( mock_git_repo "v1.2.3-X1" "v1.2.3-X3" "v1.2.3-X2" )
62+
cd "$repo"
63+
run get_next_tag_based_release "1.2.3-SNAPSHOT" "X"
64+
assert_output "1.2.3-X4"
65+
}
66+
67+
@test "get_next_tag_based_release() when has tags and dashed should return dot X tag+1" {
68+
repo=$( mock_git_repo "v1.2.3.X1" "v1.2.3.X3" "v1.2.3.X2" )
69+
cd "$repo"
70+
run get_next_tag_based_release "1.2.3.BUILD-SNAPSHOT" "X"
71+
assert_output "1.2.3.X4"
72+
}
73+
74+
@test "get_next_tag_based_release() when has multiple tags should return version match tag+1" {
75+
repo=$( mock_git_repo "v1.5.0.A1" "v1.5.0.A2" "v1.5.0.B1" "v2.0.0.A1" "v2.0.0.B1" "v2.0.0.B2" )
76+
cd "$repo"
77+
run get_next_tag_based_release "1.5.0.BUILD-SNAPSHOT" "A"
78+
assert_output "1.5.0.A3"
79+
run get_next_tag_based_release "1.5.0.BUILD-SNAPSHOT" "B"
80+
assert_output "1.5.0.B2"
81+
run get_next_tag_based_release "2.0.0.BUILD-SNAPSHOT" "A"
82+
assert_output "2.0.0.A2"
83+
run get_next_tag_based_release "2.0.0.BUILD-SNAPSHOT" "B"
84+
assert_output "2.0.0.B3"
85+
}
86+
87+
mock_git_repo() {
88+
local tmpdir=$(mktemp -d $BATS_TMPDIR/gitrepo.XXXXXX) >&2
89+
mkdir -p "$tmpdir" >&2
90+
cd "$tmpdir" >&2
91+
git init >&2
92+
echo "foo" > foo.txt
93+
git add foo.txt >&2
94+
git commit -m'Initial commit' >&2
95+
for tag in "$@"; do
96+
git tag "$tag" >&2
97+
done
98+
echo "$tmpdir"
99+
}

0 commit comments

Comments
 (0)