GH-2290 - Add script to automate dependency upgrades.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,4 +8,5 @@ target/
|
||||
*.orig
|
||||
.springBeans
|
||||
credentials.yml
|
||||
etc/updates.txt
|
||||
changelog.txt
|
||||
|
||||
7
etc/mappings.txt
Normal file
7
etc/mappings.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
jackson-bom=Jackson
|
||||
junit=JUnit
|
||||
kotlin=Kotlin
|
||||
logback=Logback
|
||||
mockk=Mockk
|
||||
reactor-bom=Reactor
|
||||
spring=Spring Framework
|
||||
143
etc/update-dependencies.sh
Executable file
143
etc/update-dependencies.sh
Executable file
@@ -0,0 +1,143 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
mapping_file="${SCRIPT_DIR}/mappings.txt"
|
||||
mvn_output_file="${SCRIPT_DIR}/updates.txt"
|
||||
|
||||
# Check if version type is provided
|
||||
if [ -z "$1" ] || [[ ! "$1" =~ ^(bugfix|minor|major)$ ]]; then
|
||||
echo "Usage: $0 <bugfix|minor|major>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check GH milestones extension installed
|
||||
if [ -z $(gh extension list | grep "^gh milestone") ]; then
|
||||
echo "gh milestones extension not installed. Install via: gh extension install valeriobelli/gh-milestone."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# Set Maven flags based on version type
|
||||
case "$1" in
|
||||
"bugfix")
|
||||
update_flags="-DallowMinorUpdates=false"
|
||||
;;
|
||||
"minor")
|
||||
update_flags="-DallowMajorUpdates=false"
|
||||
;;
|
||||
"major")
|
||||
update_flags=""
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Detect target version
|
||||
#
|
||||
|
||||
# Output local version
|
||||
localVersion=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | sed -e "s/-SNAPSHOT//")
|
||||
remoteVersions=$(gh milestone list --json title --jq ".[].title")
|
||||
|
||||
# Match against GitHub milestones (select the last match, to make sure we use the direct next version in case of multiple milestones)
|
||||
targetVersion=$(gh milestone list --json title --jq ".[].title" | grep "^$localVersion" | tail -1)
|
||||
|
||||
if [ -z $targetVersion ]; then
|
||||
echo "No target version detected"
|
||||
exit 1;
|
||||
else
|
||||
echo "Detected target version $targetVersion."
|
||||
fi
|
||||
|
||||
#
|
||||
# List possible updates
|
||||
#
|
||||
./mvnw versions:display-property-updates -q \
|
||||
$update_flags \
|
||||
-Dversions.outputFile="$mvn_output_file"
|
||||
|
||||
matches_found=0
|
||||
|
||||
# Process the output file with the regex
|
||||
while IFS= read -r line; do
|
||||
|
||||
if [[ $line =~ \$\{([[:alnum:]-]+)\.version\}[[:space:]\.]*([0-9]+\.[0-9]+\.[0-9]+.*)[[:space:]]\-\>[[:space:]]([0-9]+\.[0-9]+\.[0-9]+.*) ]]; then
|
||||
|
||||
# On first match
|
||||
if [ $matches_found -eq 0 ]; then
|
||||
|
||||
|
||||
#
|
||||
# Detect target version
|
||||
#
|
||||
|
||||
# Output local version
|
||||
localVersion=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | sed -e "s/-SNAPSHOT//")
|
||||
remoteVersions=$(gh milestone list --json title --jq ".[].title")
|
||||
|
||||
# Match against GitHub milestones (select the last match, to make sure we use the direct next version in case of multiple milestones)
|
||||
targetVersion=$(gh milestone list --json title --jq ".[].title" | grep "^$localVersion" | tail -1)
|
||||
|
||||
if [ -z $targetVersion ]; then
|
||||
echo "No target version detected"
|
||||
exit 1;
|
||||
else
|
||||
echo "Detected target version $targetVersion."
|
||||
fi
|
||||
fi
|
||||
|
||||
matches_found=$((matches_found + 1))
|
||||
|
||||
echo "Processing line: $line"
|
||||
|
||||
property_name="${BASH_REMATCH[1]}"
|
||||
old_version="${BASH_REMATCH[2]}"
|
||||
new_version="${BASH_REMATCH[3]}"
|
||||
|
||||
# Look up the mapping directly
|
||||
mapping=$(grep "^${property_name}=" "$mapping_file" | cut -d '=' -f2)
|
||||
|
||||
if [ -n "$mapping" ]; then
|
||||
|
||||
creationResult=$(gh issue create \
|
||||
--title "Upgrade ${mapping} to ${new_version}" \
|
||||
--body "" \
|
||||
--label "in: infrastructure,type: dependency-upgrade" \
|
||||
--assignee "@me" \
|
||||
--milestone "${targetVersion}")
|
||||
|
||||
# Create GitHub issue and capture the issue number
|
||||
issue_title="Upgrade ${mapping} to ${new_version}"
|
||||
issue_number=$(echo $creationResult | grep -o '[0-9]*$')
|
||||
|
||||
echo "Created GitHub issue GH-${issue_number} - ${issue_title}."
|
||||
|
||||
# Update the version using Maven versions plugin
|
||||
./mvn versions:set-property -q \
|
||||
-DgenerateBackupPoms=false \
|
||||
-Dproperty=${property_name}.version \
|
||||
-DnewVersion=${new_version}
|
||||
|
||||
echo "Updated ${property_name}.version from ${old_version} to ${new_version}."
|
||||
|
||||
# Commit the change with the issue number
|
||||
git add pom.xml
|
||||
git commit -m "GH-${issue_number} - Update ${mapping} to ${new_version}."
|
||||
|
||||
# Push changes to remote
|
||||
git push
|
||||
|
||||
# Close the issue
|
||||
gh issue close ${issue_number}
|
||||
|
||||
echo "Pushed changes and closed issue GH-${issue_number}"
|
||||
echo "---"
|
||||
else
|
||||
echo "Warning: No mapping found for property: $property_name"
|
||||
fi
|
||||
fi
|
||||
done < "$mvn_output_file"
|
||||
|
||||
if [ $matches_found -eq 0 ]; then
|
||||
echo "No version updates found for $1 updates."
|
||||
fi
|
||||
|
||||
# Clean up temporary file
|
||||
rm "$mvn_output_file"
|
||||
Reference in New Issue
Block a user