Skip to content

Commit

Permalink
Merge pull request #21 from jorgetutor/fb-update-git-author
Browse files Browse the repository at this point in the history
Update helper: added help and author param
  • Loading branch information
rsanzante committed May 17, 2021
2 parents 7557a09 + 12eaf50 commit 92b4968
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions bin/update-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
# Vars:
set -e

function show_help() {
cat << EOF
Update composer packages.
Update includes:
- Commit current configuration not exported (Drupal +8).
- Identify updatable composer packages (outdated + minor versions)
- For each package try to update and commit it (recovers previous state if fails)
Usage: ${0##*/} [--author=Name <user@example.com>]
-h|--help Show this help and exit.
--author Overrides default Git author name. Example Name <user@example.com>
EOF
}

function composer_update_outdated() {
DRUPAL_VERSION=$1

Expand Down Expand Up @@ -43,13 +61,37 @@ function composer_update_outdated() {
git add config
fi

git commit -m "UPDATE - $c" --author="$author" -n || echo "No changes to commit"
git commit -m "UPDATE - $c" "$author_commit" -n || echo "No changes to commit"
echo -e "\n\n"
done
}

author=${1:-"SCRIPTHOR <user@example.com>"}
drush=${drush:-vendor/bin/drush}
## Defaults:
author_commit=""
drush="vendor/bin/drush"

# Process script options.
#########################
for i in "$@"
do
case "${i}" in
-h|--help)
show_help # Display a usage synopsis.
exit
;;
--author=*)
author="${i#*=}"
echo "GIT author will be overrided with: $author"
author_commit="--author=\"$author\""
;;
-?*|*)
printf 'ERROR: Unknown option: %s\n' "$1" >&2
show_help
exit 1
;;
esac
shift
done

# Get the packages to be updated (direct dependencies): outdated, minor version only
packages_to_update=$(composer show -omND)
Expand All @@ -67,7 +109,7 @@ if [[ $DRUPAL_VERSION -gt 8 ]]; then
echo "Consolidating configuration (drush cex + git add):"
# estabilize current config (do not commit not exported config assiciated to a module):
drush cex -y
git add config && git commit -m "CONFIG - Consolidate current config stored in database" --author="$author" -n || echo "No changes to commit"
git add config && git commit -m "CONFIG - Consolidate current config stored in database" "$author_commit" -n || echo "No changes to commit"

echo "Clearing cache"
drush cr
Expand Down

0 comments on commit 92b4968

Please sign in to comment.