Created
July 21, 2021 12:08
-
-
Save opi/b5ae80d4a2129d63967a5452825c742b to your computer and use it in GitHub Desktop.
D8/D9 : Auto update contrib with composer and Git commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function greenecho { | |
echo "" && echo -e "\e[30;48;5;82m ✔ $1 \e[0m" | |
} | |
function orangeecho { | |
echo "" && echo -e "\e[30;48;5;208m ⚠ $1 \e[0m" | |
} | |
greenecho "Here we are: "$(pwd) | |
# Update sources | |
greenecho "Update sources ..." | |
git pull --quiet origin master | |
greenecho "Check for outdated modules" | |
MODULE_LIST=$(composer outdated drupal/* --no-ansi|grep ' ! '|grep -v ^drupal/core) | |
if [ -n "$MODULE_LIST" ] ; then | |
while read MODULE; do | |
MODULE_NAME=$(echo $MODULE | cut -d' ' -f1 | cut -d'/' -f2) | |
MODULE_VERSION=$(echo $MODULE | awk -F'! ' '{ print $2 }'|cut -d' ' -f1) | |
# if MODULE_VERSION start with 'dev', check for commit hash | |
if [[ $MODULE_VERSION = dev* ]] | |
then | |
MODULE_VERSION_HASH=$(echo $MODULE | awk -F'! ' '{ print $2 }'|cut -d' ' -f2) | |
MODULE_VERSION=$MODULE_VERSION' '$MODULE_VERSION_HASH | |
fi | |
greenecho "Updating $MODULE_NAME to $MODULE_VERSION ..." | |
# Update | |
if composer --quiet update drupal/$MODULE_NAME; then | |
# Commit | |
git add composer.lock | |
git commit -m "[up] $MODULE_NAME $MODULE_VERSION" | |
else | |
# revert changes and warn user | |
git checkout -- composer.lock | |
orangeecho "Error while updating $MODULE_NAME" | |
fi | |
done < <(printf '%s\n' "$MODULE_LIST") | |
greenecho "Push updated sources" | |
# git push origin master | |
else | |
orangeecho "Nothing to update" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment