99 строки
2.5 KiB
Bash
Executable File
99 строки
2.5 KiB
Bash
Executable File
#!/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 and 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(-)"
|
|
GIT_REPO_NAME=addons-linter
|
|
GIT_REMOTE="${GIT_REMOTE:-git@github.com:mozilla/$GIT_REPO_NAME.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 branch="$GIT_REPO_NAME-locales-$(date -u --iso-8601=date)"
|
|
|
|
info "Starting l10n extraction"
|
|
|
|
# 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
|
|
npm i >> "$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)"
|
|
npm run 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, nothing to update, ending process"
|
|
git checkout -- .
|
|
git checkout "$INITIAL_GIT_BRANCH"
|
|
git branch -d "$branch"
|
|
return
|
|
fi
|
|
|
|
info "Merging locales"
|
|
./scripts/merge-locales >> "$LOG_FILE" 2>&1
|
|
|
|
git commit -a -m "Extract and merge locales ($(date -u --iso-8601=date))" --no-verify
|
|
|
|
git push "$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/$GIT_REPO_NAME/pull/new/$branch"
|
|
echo ""
|
|
echo "----------------------------------------------------------------------"
|
|
}
|
|
|
|
# Clear log file
|
|
echo "" > "$LOG_FILE"
|
|
|
|
run_l10n_extraction
|