diff --git a/.gitignore b/.gitignore index 36c014977..ae0c3932b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ target/ .flattened-pom.xml .springBeans credentials.yml +etc/updates.txt diff --git a/etc/mappings.txt b/etc/mappings.txt new file mode 100644 index 000000000..1ea188107 --- /dev/null +++ b/etc/mappings.txt @@ -0,0 +1,7 @@ +jackson-bom=Jackson +junit=JUnit +kotlin=Kotlin +logback=Logback +mockk=Mockk +reactor-bom=Reactor +spring=Spring Framework diff --git a/etc/update-dependencies.sh b/etc/update-dependencies.sh new file mode 100755 index 000000000..9c5d50bc8 --- /dev/null +++ b/etc/update-dependencies.sh @@ -0,0 +1,144 @@ +#!/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 " + exit 1 +fi + +milestone_extension_installed=$(gh extension list | grep "^gh milestone") +# Check GH milestones extension installed +if [ -z "$milestone_extension_installed" ]; 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" \ No newline at end of file