Skip to content

Commit 6cb07e6

Browse files
committed
GH-2291 - Add script to automate dependency upgrades.
1 parent 0546150 commit 6cb07e6

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ target/
99
.flattened-pom.xml
1010
.springBeans
1111
credentials.yml
12+
etc/updates.txt

Diff for: etc/mappings.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
jackson-bom=Jackson
2+
junit=JUnit
3+
kotlin=Kotlin
4+
logback=Logback
5+
mockk=Mockk
6+
reactor-bom=Reactor
7+
spring=Spring Framework

Diff for: etc/update-dependencies.sh

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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}/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+
# Detect target version
33+
#
34+
35+
# Output local version
36+
localVersion=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | sed -e "s/-SNAPSHOT//")
37+
remoteVersions=$(gh milestone list --json title --jq ".[].title")
38+
39+
# Match against GitHub milestones (select the last match, to make sure we use the direct next version in case of multiple milestones)
40+
targetVersion=$(gh milestone list --json title --jq ".[].title" | grep "^$localVersion" | tail -1)
41+
42+
if [ -z $targetVersion ]; then
43+
echo "No target version detected"
44+
exit 1;
45+
else
46+
echo "Detected target version $targetVersion."
47+
fi
48+
49+
#
50+
# List possible updates
51+
#
52+
./mvnw versions:display-property-updates -q \
53+
$update_flags \
54+
-Dversions.outputFile="$mvn_output_file"
55+
56+
matches_found=0
57+
58+
# Process the output file with the regex
59+
while IFS= read -r line; do
60+
61+
if [[ $line =~ \$\{([[:alnum:]-]+)\.version\}[[:space:]\.]*([0-9]+\.[0-9]+\.[0-9]+.*)[[:space:]]\-\>[[:space:]]([0-9]+\.[0-9]+\.[0-9]+.*) ]]; then
62+
63+
# On first match
64+
if [ $matches_found -eq 0 ]; then
65+
66+
67+
#
68+
# Detect target version
69+
#
70+
71+
# Output local version
72+
localVersion=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | sed -e "s/-SNAPSHOT//")
73+
remoteVersions=$(gh milestone list --json title --jq ".[].title")
74+
75+
# Match against GitHub milestones (select the last match, to make sure we use the direct next version in case of multiple milestones)
76+
targetVersion=$(gh milestone list --json title --jq ".[].title" | grep "^$localVersion" | tail -1)
77+
78+
if [ -z $targetVersion ]; then
79+
echo "No target version detected"
80+
exit 1;
81+
else
82+
echo "Detected target version $targetVersion."
83+
fi
84+
fi
85+
86+
matches_found=$((matches_found + 1))
87+
88+
echo "Processing line: $line"
89+
90+
property_name="${BASH_REMATCH[1]}"
91+
old_version="${BASH_REMATCH[2]}"
92+
new_version="${BASH_REMATCH[3]}"
93+
94+
# Look up the mapping directly
95+
mapping=$(grep "^${property_name}=" "$mapping_file" | cut -d '=' -f2)
96+
97+
if [ -n "$mapping" ]; then
98+
99+
creationResult=$(gh issue create \
100+
--title "Upgrade ${mapping} to ${new_version}" \
101+
--body "" \
102+
--label "in: infrastructure,type: dependency-upgrade" \
103+
--assignee "@me" \
104+
--milestone "${targetVersion}")
105+
106+
# Create GitHub issue and capture the issue number
107+
issue_title="Upgrade ${mapping} to ${new_version}"
108+
issue_number=$(echo $creationResult | grep -o '[0-9]*$')
109+
110+
echo "Created GitHub issue GH-${issue_number} - ${issue_title}."
111+
112+
# Update the version using Maven versions plugin
113+
./mvn versions:set-property -q \
114+
-DgenerateBackupPoms=false \
115+
-Dproperty=${property_name}.version \
116+
-DnewVersion=${new_version}
117+
118+
echo "Updated ${property_name}.version from ${old_version} to ${new_version}."
119+
120+
# Commit the change with the issue number
121+
git add pom.xml
122+
git commit -m "GH-${issue_number} - Update ${mapping} to ${new_version}."
123+
124+
# Push changes to remote
125+
git push
126+
127+
# Close the issue
128+
gh issue close ${issue_number}
129+
130+
echo "Pushed changes and closed issue GH-${issue_number}"
131+
echo "---"
132+
else
133+
echo "Warning: No mapping found for property: $property_name"
134+
fi
135+
fi
136+
done < "$mvn_output_file"
137+
138+
if [ $matches_found -eq 0 ]; then
139+
echo "No version updates found for $1 updates."
140+
fi
141+
142+
# Clean up temporary file
143+
rm "$mvn_output_file"

0 commit comments

Comments
 (0)