1
+ #! /bin/bash
2
+ SCRIPT_DIR=$( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd )
3
+ mapping_file=" ${SCRIPT_DIR} /mappings.txt"
4
+ mvn_output_file=" ${SCRIPT_DIR} /../target/updates.txt"
5
+
6
+ # Check if version type is provided
7
+ if [ -z " $1 " ] || [[ ! " $1 " =~ ^(bugfix| minor| major)$ ]]; then
8
+ echo " Usage: $0 <bugfix|minor|major>"
9
+ exit 1
10
+ fi
11
+
12
+ # Check GH milestones extension installed
13
+ if [ -z " $( gh extension list | grep " ^gh milestone" ) " ]; then
14
+ echo " gh milestones extension not installed. Install via: gh extension install valeriobelli/gh-milestone."
15
+ exit 1;
16
+ fi
17
+
18
+ # Set Maven flags based on version type
19
+ case " $1 " in
20
+ " bugfix" )
21
+ update_flags=" -DallowMinorUpdates=false"
22
+ ;;
23
+ " minor" )
24
+ update_flags=" -DallowMajorUpdates=false"
25
+ ;;
26
+ " major" )
27
+ update_flags=" "
28
+ ;;
29
+ esac
30
+
31
+ #
32
+ # List possible updates
33
+ #
34
+ ./mvnw versions:display-property-updates -q -N \
35
+ $update_flags \
36
+ -Dversions.outputFile=" $mvn_output_file "
37
+
38
+ matches_found=0
39
+
40
+ # Process the output file with the regex
41
+ while IFS= read -r line; do
42
+
43
+ if [[ $line =~ \$\{ ([[:alnum:]-]+)\. version\} [[:space:]\. ]* ([0-9]+\. [0-9]+\. [0-9]+.* )[[:space:]]\-\> [[:space:]]([0-9]+\. [0-9]+\. [0-9]+.* ) ]]; then
44
+
45
+ echo " ---"
46
+ echo " Processing line: $line "
47
+
48
+ property_name=" ${BASH_REMATCH[1]} "
49
+ old_version=" ${BASH_REMATCH[2]} "
50
+ new_version=" ${BASH_REMATCH[3]} "
51
+
52
+ # Skip if new version matches pattern (case insensitive)
53
+ if echo " $new_version " | grep -qiE " (-m[0-9]|-rc[0-9]|alpha|beta)" ; then
54
+ echo " ❌ - Skipping preview version: $new_version ."
55
+ echo " ---"
56
+ continue
57
+ fi
58
+
59
+ # Look up the mapping directly
60
+ mapping=$( grep " ^${property_name} =" " $mapping_file " | cut -d ' =' -f2)
61
+
62
+ if [ -z " $mapping " ]; then
63
+
64
+ echo " ❌ - No mapping found for property: $property_name . Skipping."
65
+ echo " ---"
66
+ continue
67
+ fi
68
+
69
+ # On first match
70
+ if [ $matches_found -eq 0 ]; then
71
+
72
+
73
+ #
74
+ # Detect target version
75
+ #
76
+
77
+ # Output local version
78
+ localVersion=$( ./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | sed ' s/\([0-9]*\.[0-9]*\)\..*/\1/' )
79
+ remoteVersions=$( gh milestone list --json title --jq " .[].title" )
80
+
81
+ # Match against GitHub milestones (select the last match, to make sure we use the direct next version in case of multiple milestones)
82
+ targetVersion=$( gh milestone list --json title --jq " .[].title" | grep " ^$localVersion " | tail -1)
83
+
84
+ if [ -z " $targetVersion " ]; then
85
+ echo " No target version detected"
86
+ exit 1;
87
+ else
88
+ echo " Detected target version $targetVersion ."
89
+ fi
90
+ fi
91
+
92
+ matches_found=$(( matches_found + 1 ))
93
+
94
+ creationResult=$( gh issue create \
95
+ --title " Upgrade ${mapping} to ${new_version} " \
96
+ --body " " \
97
+ --label " in: infrastructure,type: dependency-upgrade" \
98
+ --assignee " @me" \
99
+ --milestone " ${targetVersion} " )
100
+
101
+ # Create GitHub issue and capture the issue number
102
+ issue_title=" Upgrade ${mapping} to ${new_version} "
103
+ issue_number=$( echo $creationResult | grep -o ' [0-9]*$' )
104
+
105
+ echo " Created GitHub issue GH-${issue_number} - ${issue_title} ."
106
+
107
+ # Update the version using Maven versions plugin
108
+ ./mvnw versions:set-property -q \
109
+ -DgenerateBackupPoms=false \
110
+ -Dproperty=${property_name} .version \
111
+ -DnewVersion=${new_version}
112
+
113
+ echo " Updated ${property_name} .version from ${old_version} to ${new_version} ."
114
+
115
+ # Commit the change with the issue number
116
+ git add pom.xml
117
+ git commit -m " GH-${issue_number} - Update ${mapping} to ${new_version} ."
118
+
119
+ # Push changes to remote
120
+ # git push
121
+
122
+ # Close the issue
123
+ # gh issue close ${issue_number}
124
+
125
+ # echo "✅ Pushed changes and closed issue GH-${issue_number}"
126
+ echo " ---"
127
+ fi
128
+ done < " $mvn_output_file "
129
+
130
+ if [ $matches_found -eq 0 ]; then
131
+ echo " No version updates found for $1 updates."
132
+ fi
133
+
134
+ # Clean up temporary file
135
+ # rm "$mvn_output_file"
0 commit comments