-
Notifications
You must be signed in to change notification settings - Fork 56
Try to automate some of the translation updates #87
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#! /usr/bin/env bash | ||
|
||
CWD=`pwd` | ||
DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
cd $DIRECTORY | ||
|
||
function log() { | ||
if [[ -n $1 ]];then | ||
printf "\033[0;36m\n$1\n\033[0m" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might be able to use # Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset (from SO) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting... |
||
fi | ||
} | ||
|
||
function quit() { | ||
if [[ -n $1 ]];then | ||
printf "\033[0;31m\n\n$1\n\n\033[0m" | ||
fi | ||
cd $CWD | ||
exit | ||
} | ||
|
||
function repo_checkout_master() { | ||
if [[ -n $1 ]];then | ||
log "checking out master for '$1'" | ||
cd $DIRECTORY | ||
cd "workspace-zen/$1/" | ||
DIRTY=`git status --porcelain` | ||
|
||
if [[ -n $DIRTY ]]; then | ||
quit "$1 has unstaged / uncommitted changes, please fix and try again" | ||
fi | ||
fi | ||
} | ||
|
||
# Update the translations repo if we are able | ||
repo_checkout_master 'cp-translations' | ||
|
||
TRANSLATIONS_VERSION=$(cat package.json \ | ||
| grep version \ | ||
| head -1 \ | ||
| awk -F: '{ print $2 }' \ | ||
| sed 's/[ ",^]//g') | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, you could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, okay - so found out I can do |
||
log "cp-translations is version $TRANSLATIONS_VERSION" | ||
|
||
REPOS=("cp-events-service" "cp-dojos-service" "cp-users-service" "cp-zen-frontend") | ||
|
||
for repo in ${REPOS[@]}; do | ||
printf "\033[0;33m\n\nUpdating $repo\n\033[0m" | ||
|
||
repo_checkout_master $repo | ||
|
||
PACKAGE_VERSION=$(cat package.json \ | ||
| grep cp-translations \ | ||
| head -1 \ | ||
| awk -F: '{ print $2 }' \ | ||
| sed 's/[ ",^]//g') | ||
|
||
log "$repo uses version $PACKAGE_VERSION" | ||
|
||
#if it doesn't match, we need to create a branch, update version, commit and push | ||
if [[ "$TRANSLATIONS_VERSION" != "$PACKAGE_VERSION" ]]; then | ||
log "Updating cp-translations for cp-events-service" | ||
escaped_lhs=$(printf '%s\n' "\"cp-translations\": \"^$PACKAGE_VERSION\"" | sed 's:[][\\/.^$*]:\\&:g') | ||
escaped_rhs=$(printf '%s\n' "\"cp-translations\": \"^$TRANSLATIONS_VERSION\"" | sed 's:[\\/&]:\\&:g;$!s/$/\\/') | ||
|
||
sed -i '' -e "s/$escaped_lhs/$escaped_rhs/g" package.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's a possibility of running the update inside the Docker container, but outside would result in potential mismatches in yarn.lock to do with the platform right? Maybe will check / investigate, ta. |
||
|
||
BRANCH="update-translations-$TRANSLATIONS_VERSION" | ||
git add package.json | ||
git checkout -b $BRANCH | ||
git commit -m "Update cp-translations to $TRANSLATIONS_VERSION" | ||
git push -u origin $BRANCH | ||
git checkout master | ||
# git push origin --delete $BRANCH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably remove these commented out lines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Yeah, was in there for testing :) ] |
||
# git branch -D $BRANCH | ||
fi | ||
done | ||
|
||
log "Finished" | ||
exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to use
-eu
to catch commands exiting non-zero, and undefined variables.