jami-docs/_build/Jenkinsfile.i18n

138 lines
5.8 KiB
Plaintext

// 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}
git config --local core.hooksPath .git/hooks
curl -Lo .git/hooks/commit-msg https://review.jami.net/tools/hooks/commit-msg
chmod +x .git/hooks/commit-msg
git add locales
git commit --author "${GIT_USER_NAME} <${GIT_USER_EMAIL}>" -m'i18n: automatic bump'
git push ${GIT_PUSH_URL} HEAD:refs/for/master
"""
}
}
}
}
}
}
}
}