CI: Setup pushing-translation procedure in CI.

This commit is contained in:
Terry Geng 2020-10-31 20:30:05 +08:00
parent 716b106f6c
commit 5c5120e3d7
No known key found for this signature in database
GPG Key ID: F982F8EA1DF720E7
3 changed files with 82 additions and 5 deletions

View File

@ -17,6 +17,23 @@ steps:
- push
- tag
- name: push-translation
image: debian
environment:
TRADUORA_R_CLIENT:
from_secret: TRADUORA_R_CLIENT
TRADUORA_R_SECRET:
from_secret: TRADUORA_R_SECRET
TRADUORA_W_CLIENT:
from_secret: TRADUORA_W_CLIENT
TRADUORA_W_SECRET:
from_secret: TRADUORA_W_SECRET
GITHUB_API:
from_secret: GITHUB_API
commands:
- apt update && apt install -y git python3-requests hub
- SOURCE_DIR=$(pwd) ./scripts/update_translation_to_server.sh
- name: translate-html
image: python:3
commands:
@ -126,7 +143,7 @@ steps:
from_secret: GITHUB_API
commands:
- apt update && apt install -y git python3-requests hub
- SOURCE_DIR=$(pwd) ./scripts/commit_new_translation.sh
- PUSH=1 SOURCE_DIR=$(pwd) ./scripts/commit_new_translation.sh
node:
location: external

View File

@ -2,20 +2,32 @@
git remote set-url origin https://azlux:$GITHUB_API@github.com/azlux/botamusique/
echo "=> Fetching for bot-traduora branch..."
if git fetch origin bot-traduora; then
echo "==> bot-traduora branch exists"
git branch bot-traduora FETCH_HEAD
CREATE_PR=false
else
echo "==> bot-traduora branch doesn't exist, create one"
git branch bot-traduora
CREATE_PR=true
fi
git checkout bot-traduora
echo "=> Fetching updates from the server..."
$SOURCE_DIR/scripts/sync_translation.py --lang-dir $SOURCE_DIR/lang/ --client $TRADUORA_R_CLIENT --secret $TRADUORA_R_SECRET --fetch
git add lang/*
git status
if GIT_COMMITTER_NAME='Traduora Bot' GIT_COMMITTER_EMAIL='noreply@azlux.fr' git commit -m 'Bot: Update translation' --author "Traduora Bot <noreply@azlux.fr>"; then
git push origin bot-traduora
sleep 2
if $CREATE_PR; then GITHUB_USER="azlux" GITHUB_TOKEN="$GITHUB_API" hub pull-request -m "Bot: TRADUORA Update"; fi
if $PUSH; then
echo "=> Pushing updates to bot-traduora branch..."
if GIT_COMMITTER_NAME='Traduora Bot' GIT_COMMITTER_EMAIL='noreply@azlux.fr' git commit -m 'Bot: Update translation' --author "Traduora Bot <noreply@azlux.fr>"; then
git push origin bot-traduora
sleep 2
if $CREATE_PR; then GITHUB_USER="azlux" GITHUB_TOKEN="$GITHUB_API" hub pull-request -m "Bot: TRADUORA Update"; fi
exit 0
fi
echo "==> There's nothing to push."
exit 0
fi

View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -e
PYTHON=$SOURCE_DIR/venv/bin/python
git remote set-url origin https://azlux:$GITHUB_API@github.com/azlux/botamusique/
git pull origin master
echo "=> Checking if translations in this commit differ from the server..."
git branch testing-translation master
git checkout testing-translation
$PYTHON $SOURCE_DIR/scripts/sync_translation.py --lang-dir $SOURCE_DIR/lang/ --client $TRADUORA_R_CLIENT --secret $TRADUORA_R_SECRET --fetch
if [ -z "$(git diff)" ]; then
echo "==> No difference found."
exit 0
fi
echo "==> Modifications found."
echo "=> Check if the modifications are based on the translations on the server..."
n=1
COMMON_FOUND=false
while [ $n -le 10 ]; do
echo "==> Comparing server's translations with master~$n ($(git show --oneline --quiet master~$n))"
CHANGED_LANG_FILE=$(git diff --name-only master~$n | grep "lang/" || true)
if [ -z "$CHANGED_LANG_FILE" ]; then
COMMON_FOUND=true
break
fi
let n++
done
if [ ! $COMMON_FOUND ]; then
echo "==> CONFLICTS: Previous commits doesn't share the same translations with the server."
echo " There are unmerged translation updates on the server."
echo " Please manually update these changes or wait for the pull request"
echo " created by the translation bot get merged."
exit 1
fi
echo "==> master~$n ($(git show --oneline --quiet master~$n)) shares the same translations with the server."
echo "=> Preparing to push local translation updates to the server..."
$PYTHON $SOURCE_DIR/scripts/sync_translation.py --lang-dir $SOURCE_DIR/lang/ --client $TRADUORA_W_CLIENT --secret $TRADUORA_W_SECRET --push
exit 0