Skip to content
Snippets Groups Projects
Commit b761f7b6 authored by Amin Bandali's avatar Amin Bandali
Browse files

misc: add Jenkins pipeline for automated translation updates

* .gitignore: Ignore GNU gettext *.mo binary files.
* Makefile: New tx-pull and tx-push rules for pulling translations
from and pushing translation source strings to Transifex using their
tx tool.
* _build/Dockerfile.i18n: New Dockerfile for docs-i18n pipeline, to
push and pull translation sources/strings on a weekly basis.
* _build/Jenkinsfile.18n: New Jenkinsfile defining the docs-i18n
pipeline.

Change-Id: I945e9d087ef559f18ee1f9afd8f5035d6c35c737
parent 9e5631f1
No related branches found
No related tags found
No related merge requests found
_build/out
# GNU gettext binary files
*.mo
......@@ -9,6 +9,7 @@
CMD ?= sphinx-build
AUTOBUILD_CMD ?= sphinx-autobuild
INTL_CMD ?= sphinx-intl
TX_CMD ?= tx
OPTS ?=
SRC = .
OUT = _build/out
......@@ -17,6 +18,9 @@ RSYNC_OPTS ?= --verbose --archive --recursive --delete
# Translation languages (other than English)
LANGS = fr fa
space = $() $()
comma = ,
LANGS_commasep = $(subst $(space),$(comma),$(LANGS))
# default rule
help:
......@@ -49,6 +53,13 @@ po: gettext po-pre
$(INTL_CMD) update -p "$(OUT)"/gettext -l $$l; \
done
tx-pull:
# $(TX_CMD) pull -aft --minimum-perc=1
$(TX_CMD) pull -ftl $(LANGS_commasep)
tx-push:
$(TX_CMD) push -s
deploy:
rsync $(RSYNC_OPTS) "$(OUT)"/html/ "$(RSYNC_DEST)"
for l in $(LANGS); do \
......@@ -65,4 +76,4 @@ deploy:
$(OPTS); \
done
.PHONY: gettext-pre po-pre po deploy
.PHONY: gettext-pre po-pre po tx-pull tx-push deploy
FROM debian:bullseye-slim
ARG UID=1000
ARG GID=1000
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get clean
RUN apt-get update && \
apt-get install -y -o Acquire::Retries=10 \
curl \
make \
python3-pip
RUN groupadd -g "${GID}" jenkins && \
useradd --create-home --no-log-init -u "${UID}" -g "${GID}" jenkins
USER jenkins
RUN mkdir -p "/home/jenkins/.local/bin" && \
cd "/home/jenkins/.local/bin" && \
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
ENV PATH="/home/jenkins/.local/bin:${PATH}"
RUN pip3 install Sphinx sphinx-intl sphinx-rtd-theme myst-parser
// Copyright (C) 2022 Savoir-faire Linux Inc.
//
// Author: Amin Bandali <amin.bandali@savoirfairelinux.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Automatic update of jami-docs translations.
// Configuration globals.
def REPO_NAME = 'jami-docs'
def JENKINS_SSH_KEY = '35cefd32-dd99-41b0-8312-0b386df306ff'
def TRANSIFEX_API_TOKEN = 'a43e3c1e-1fb5-4778-8bdf-84173584aa6c'
def DOCKER_IMAGE = "docs-i18n:${BUILD_ID}"
def DOCKER_FILE = '_build/Dockerfile.i18n'
pipeline {
agent {
label 'translator'
}
triggers {
cron('H H * * 1')
}
options {
ansiColor('xterm')
}
parameters {
string(name: 'GERRIT_REFSPEC',
defaultValue: 'refs/heads/master',
description: 'The Gerrit refspec to fetch.')
}
environment {
GIT_REPO_NAME = 'jami-docs'
GIT_USER_NAME = 'Jenkins'
GIT_USER_EMAIL = 'jenkins@ring-packaging.cx'
GIT_PUSH_URL = "ssh://jenkins@review.jami.net:29420/${GIT_REPO_NAME}"
GIT_CLONE_URL = "https://review.jami.net/${GIT_REPO_NAME}"
}
stages {
stage('Workspace previous left-over cleanup') {
steps {
script {
sh 'git checkout -- .'
sh 'git clean -xdf'
}
}
}
stage('Build docs-i18n docker image') {
steps {
script {
def jenkinsUID = sh(returnStdout: true, script: 'id -u jenkins').replaceAll("\n", '').trim()
def jenkinsGID = sh(returnStdout: true, script: 'id -g jenkins').replaceAll("\n", '').trim()
def docker_args =
["--build-arg UID=${jenkinsUID}",
"--build-arg GID=${jenkinsGID}",
"-f ${DOCKER_FILE} ."].join(' ')
docker.build(DOCKER_IMAGE, docker_args)
}
}
}
stage('Run docs-i18n docker image') {
steps {
script {
def pwd = pwd()
def docker_args = "-t -v ${pwd}:/${GIT_REPO_NAME}:rw -e BATCH_MODE=1"
docker.image(DOCKER_IMAGE).withRun(docker_args) { container ->
def run_cmd = { cmd ->
sh "set +x; docker exec -t ${container.id} /bin/sh -c '${cmd}'"
}
stage('Write ~/.transifexrc') {
withCredentials(
[string(credentialsId: TRANSIFEX_API_TOKEN,
variable: 'TX_API_TOKEN')]) {
run_cmd("""
echo "" > ~/.transifexrc
echo "[https://www.transifex.com]" >> ~/.transifexrc
echo "api_hostname = https://api.transifex.com" >> ~/.transifexrc
echo "hostname = https://www.transifex.com" >> ~/.transifexrc
echo "token = ${TX_API_TOKEN}" >> ~/.transifexrc
echo "password = ${TX_API_TOKEN}" >> ~/.transifexrc
echo "username = api" >> ~/.transifexrc
echo "rest_hostname = https://rest.api.transifex.com" >> ~/.transifexrc
""")
}
}
stage('Copy our message.pot_t into Sphinx') {
// Needed because of this Sphinx bug:
// https://github.com/sphinx-doc/sphinx/issues/10832
run_cmd("""
cp -p ${GIT_REPO_NAME}/_templates/message.pot_t \$(python3 -m site --user-site)/sphinx/templates/gettext/
""")
}
stage('Push pot sources and pull po translations') {
run_cmd("""
cd ${GIT_REPO_NAME}
make gettext
make tx-push
make tx-pull
""")
}
stage('Send translation changes patch to Gerrit') {
sshagent(credentials: [JENKINS_SSH_KEY]) {
sh """
git config user.name ${GIT_USER_NAME}
git config user.email ${GIT_USER_EMAIL}
scp -p -P 29420 jenkins@review.jami.net:hooks/commit-msg .git/hooks/
git add locales
git commit -m'i18n: automatic bump'
git push ${GIT_PUSH_URL} HEAD:refs/for/master
"""
}
}
}
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment