2020-04-23 23:03:11 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Exit immediately when a command fails.
|
|
|
|
set -e
|
|
|
|
# Make sure exit code are respected in a pipeline.
|
|
|
|
set -o pipefail
|
|
|
|
# Treat unset variables as an error an exit immediately.
|
|
|
|
set -u
|
|
|
|
|
|
|
|
INITIAL_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
|
|
GIT_CHANGES=$(git status --porcelain)
|
|
|
|
DIFF_WITH_ONE_LINE_CHANGE="1 file changed, 1 insertion(+), 1 deletion(-)"
|
2020-05-06 12:18:51 +03:00
|
|
|
GIT_REMOTE="${GIT_REMOTE:-git@github.com:mozilla/addons-frontend.git}"
|
2020-07-08 16:39:58 +03:00
|
|
|
LOG_FILE="l10n-extraction.log"
|
2020-04-23 23:03:11 +03:00
|
|
|
|
|
|
|
info() {
|
|
|
|
local message="$1"
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "INFO: $message"
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
local message="$1"
|
|
|
|
|
|
|
|
echo "ERROR: $message"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
run_l10n_extraction() {
|
|
|
|
local app="$1"
|
|
|
|
local branch="$app-locales"
|
|
|
|
|
2020-07-08 16:39:58 +03:00
|
|
|
info "Starting l10n extraction for $app"
|
|
|
|
|
2020-04-23 23:03:11 +03:00
|
|
|
# Detect local (uncommitted) changes.
|
|
|
|
if [[ ! -z "$GIT_CHANGES" ]]; then
|
|
|
|
error "You have local changes, therefore this script cannot continue."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Switch to the `master` branch if we are not on it already.
|
|
|
|
if [[ "$INITIAL_GIT_BRANCH" != "master" ]]; then
|
|
|
|
git checkout master
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure the 'master' branch is up-to-date.
|
|
|
|
git pull "$GIT_REMOTE" master
|
|
|
|
|
2020-07-08 16:39:58 +03:00
|
|
|
# Update dependencies
|
|
|
|
yarn >> "$LOG_FILE" 2>&1
|
|
|
|
|
2020-04-23 23:03:11 +03:00
|
|
|
# Ensure the branch to extract the locales is clean.
|
|
|
|
if [[ $(git branch --list "$branch") ]]; then
|
|
|
|
info "Deleting branch '$branch' because it already exists"
|
|
|
|
git branch -D "$branch"
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Creating and switching to branch '$branch'"
|
|
|
|
git checkout -b "$branch"
|
|
|
|
|
2020-07-08 16:39:58 +03:00
|
|
|
info "Extracting locales (this can take several minutes)"
|
|
|
|
NODE_APP_INSTANCE="$app" bin/extract-locales >> "$LOG_FILE" 2>&1
|
2020-04-23 23:03:11 +03:00
|
|
|
|
|
|
|
local git_diff_stat
|
|
|
|
git_diff_stat=$(git diff --shortstat)
|
|
|
|
|
|
|
|
if [[ -z "$git_diff_stat" ]] || [[ "$git_diff_stat" == *"$DIFF_WITH_ONE_LINE_CHANGE"* ]]; then
|
2020-07-08 16:39:58 +03:00
|
|
|
info "No locale changes for $app, nothing to update, ending process for $app"
|
2020-04-23 23:03:11 +03:00
|
|
|
git checkout -- .
|
|
|
|
git checkout "$INITIAL_GIT_BRANCH"
|
|
|
|
git branch -d "$branch"
|
2020-04-28 19:18:39 +03:00
|
|
|
return
|
2020-04-23 23:03:11 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
git commit -a -m "Extract $app locales"
|
|
|
|
|
2020-07-08 16:39:58 +03:00
|
|
|
info "Merging locales"
|
|
|
|
NODE_APP_INSTANCE="$app" bin/merge-locales >> "$LOG_FILE" 2>&1
|
2020-04-23 23:03:11 +03:00
|
|
|
|
|
|
|
git commit -a -m "Merge $app locales"
|
|
|
|
|
|
|
|
# We use force-push in case the branch already exists.
|
|
|
|
git push -f "$GIT_REMOTE" "$branch"
|
|
|
|
|
|
|
|
git checkout "$INITIAL_GIT_BRANCH"
|
|
|
|
git branch -D "$branch"
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
echo " You can now open the link below to submit your Pull Request:"
|
|
|
|
echo " https://github.com/mozilla/addons-frontend/pull/new/$branch"
|
|
|
|
echo ""
|
|
|
|
echo "----------------------------------------------------------------------"
|
|
|
|
}
|
|
|
|
|
2020-07-08 16:39:58 +03:00
|
|
|
# Clear log file
|
|
|
|
echo "" > "$LOG_FILE"
|
|
|
|
|
2020-04-23 23:03:11 +03:00
|
|
|
run_l10n_extraction "amo"
|
|
|
|
run_l10n_extraction "disco"
|