addons-frontend/bin/run-l10n-extraction

103 строки
2.6 KiB
Plaintext
Исходник Обычный вид История

#!/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}"
LOG_FILE="l10n-extraction.log"
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"
info "Starting l10n extraction for $app"
# 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
# Update dependencies
yarn >> "$LOG_FILE" 2>&1
# 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"
info "Extracting locales (this can take several minutes)"
NODE_APP_INSTANCE="$app" bin/extract-locales >> "$LOG_FILE" 2>&1
local git_diff_stat
git_diff_stat=$(git diff --shortstat)
if [[ -z "$git_diff_stat" ]] || [[ "$git_diff_stat" == *"$DIFF_WITH_ONE_LINE_CHANGE"* ]]; then
info "No locale changes for $app, nothing to update, ending process for $app"
git checkout -- .
git checkout "$INITIAL_GIT_BRANCH"
git branch -d "$branch"
return
fi
git commit -a -m "Extract $app locales"
info "Merging locales"
NODE_APP_INSTANCE="$app" bin/merge-locales >> "$LOG_FILE" 2>&1
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 "----------------------------------------------------------------------"
}
# Clear log file
echo "" > "$LOG_FILE"
run_l10n_extraction "amo"
run_l10n_extraction "disco"