Skip to content

Instantly share code, notes, and snippets.

@mkordas
Last active August 29, 2015 14:15
Show Gist options
  • Save mkordas/a6fa7e672b9aea6d9079 to your computer and use it in GitHub Desktop.
Save mkordas/a6fa7e672b9aea6d9079 to your computer and use it in GitHub Desktop.
Script to update dependencies
#!/bin/sh
git checkout master
git reset --hard upstream/master
mvn versions:display-plugin-updates > updates_output.txt
#mvn versions:display-dependency-updates >> updates_output.txt
dos2unix updates_output.txt
grep ' -> ' updates_output.txt > to_update.txt
while read line; do
arr=($line)
dependency=${arr[1]}
if [[ $line == *". "* ]]
then
current_version=${arr[3]}
updated_version=${arr[5]}
else
current_version=${arr[2]}
updated_version=${arr[4]}
fi
count=$(grep -Fc ">$current_version<" pom.xml)
if [ $count == 0 ]
then
echo "ERROR - Count for $line is '$count'."
else
sanitized_dependency=`echo $dependency | tr ".\-:" "___"`
branch_name="update_$sanitized_dependency"
git checkout -b $branch_name
git reset --hard upstream/master >/dev/null
if [ $count == 1 ]
then
sed -i "s/>$current_version</>$updated_version</" pom.xml
else
current_version_escaped=`echo $current_version | sed 's/\./\\\\./g'`
artifact_id=`echo $dependency | cut -d \: -f 2`
echo $artifact_id
perl -0777 -i -pe "s/($artifact_id.*?)>$current_version_escaped/\$1>$updated_version/s" pom.xml
fi
mvn verify > /dev/null
build_status=$?
if [ $build_status -ne 0 ]
then
echo "ERROR - Maven build failed when $dependency updated to to $updated_version"
git branch -D $branch_name
else
git commit -a -m"Update $dependency to $updated_version, issue #644"
echo "INFO - Updated $dependency from $current_version to $updated_version"
fi
fi
done < to_update.txt
git checkout master
git reset --hard upstream/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment