mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Handle branches master and 1.7.x in crowdin jenkins
This commit is contained in:
@@ -6,71 +6,84 @@
|
||||
|
||||
import groovy.json.JsonSlurper;
|
||||
|
||||
// TODO refactor this after ZNC 1.7 is released, because we'll need many branches
|
||||
def upstream_user = 'znc'
|
||||
def upstream_repo = 'znc'
|
||||
def upstream_branch = 'master'
|
||||
def my_user = 'znc-jenkins'
|
||||
def my_repo = 'znc'
|
||||
def my_branch = 'l10n_master'
|
||||
def branches = ['master', '1.7.x']
|
||||
|
||||
timestamps {
|
||||
node {
|
||||
timeout(time: 30, unit: 'MINUTES') {
|
||||
stage('WsCleanup') {
|
||||
cleanupWs()
|
||||
}
|
||||
def tasks = [:]
|
||||
def crowdin_cli = "java -jar ${tool 'crowdin-cli'}/crowdin-cli.jar --config .ci/crowdin.yml"
|
||||
stage('Checkout') {
|
||||
step([$class: 'WsCleanup'])
|
||||
checkout([$class: 'GitSCM', branches: [[name: "*/${upstream_branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', recursiveSubmodules: true]], userRemoteConfigs: [[credentialsId: '6ef10f80-20dc-4661-af45-52a6e1e15749', name: 'upstream', url: "github.com:${upstream_user}/${upstream_repo}.git"]]])
|
||||
}
|
||||
stage('Prepare strings') {
|
||||
dir("build") {
|
||||
sh "cmake .."
|
||||
sh 'make translation'
|
||||
}
|
||||
sh 'rm -rf build/'
|
||||
sh 'git status'
|
||||
}
|
||||
stage('Crowdin') {
|
||||
withCredentials([string(credentialsId: '11c7e2b4-f990-4670-98a4-c89d2a5a2f43', variable: 'CROWDIN_API_KEY')]) {
|
||||
withEnv(['CROWDIN_BASE_PATH='+pwd()]) {
|
||||
sh "$crowdin_cli upload sources --branch ${upstream_branch}"
|
||||
// sh "$crowdin_cli upload translations --branch ${upstream_branch}"
|
||||
sh "$crowdin_cli download --branch ${upstream_branch}"
|
||||
}
|
||||
}
|
||||
sh 'LANG=en_US.utf8 find . -name "*.po" -exec msgfilter -i "{}" -o "{}.replacement" .ci/cleanup-po.pl ";"'
|
||||
sh 'find . -name "*.po" -exec mv "{}.replacement" "{}" ";"'
|
||||
}
|
||||
stage('Push') {
|
||||
sh 'git config user.name "ZNC-Jenkins"'
|
||||
sh 'git config user.email jenkins@znc.in'
|
||||
sh 'git status'
|
||||
sh 'git add .'
|
||||
try {
|
||||
sh 'git commit -m "Update translations from Crowdin"'
|
||||
} catch(e) {
|
||||
echo 'No changes found'
|
||||
return
|
||||
}
|
||||
sh "git remote add my github.com:${my_user}/${my_repo}.git"
|
||||
// TODO simplify when https://issues.jenkins-ci.org/browse/JENKINS-28335 is fixed
|
||||
withCredentials([sshUserPrivateKey(credentialsId: '6ef10f80-20dc-4661-af45-52a6e1e15749', keyFileVariable: 'GITHUB_KEY')]) {
|
||||
sh 'echo ssh -i $GITHUB_KEY -l git -o StrictHostKeyChecking=no \\"\\$@\\" > run_ssh.sh'
|
||||
sh 'chmod +x run_ssh.sh'
|
||||
withEnv(['GIT_SSH=run_ssh.sh']) {
|
||||
sh "git push my HEAD:refs/heads/${my_branch} -f"
|
||||
}
|
||||
}
|
||||
// Create pull request if it doesn't exist yet
|
||||
withCredentials([string(credentialsId: '7a2546ae-8a29-4eab-921c-6a4803456dce', variable: 'GITHUB_OAUTH_KEY')]) {
|
||||
def headers = [[maskValue: true, name: 'Authorization', value: "token ${env.GITHUB_OAUTH_KEY}"], [maskValue: false, name: 'Accept', value: 'application/vnd.github.v3+json'], [maskValue: false, name: 'User-Agent', value: 'https://github.com/znc/znc/blob/master/.ci/Jenkinsfile.crowdin']]
|
||||
def pulls = httpRequest consoleLogResponseBody: true, customHeaders: headers, url: "https://api.github.com/repos/${upstream_user}/${upstream_repo}/pulls?head=${my_user}:${my_branch}&base=${upstream_branch}"
|
||||
pulls = new JsonSlurper().parseText(pulls.content)
|
||||
if (!pulls) {
|
||||
httpRequest consoleLogResponseBody: true, customHeaders: headers, url: "https://api.github.com/repos/${upstream_user}/${upstream_repo}/pulls", httpMode: 'POST', requestBody: '{"head":"'+my_user+':'+my_branch+'","base":"'+upstream_branch+'","title":"Update translations","body":"From https://crowdin.com/project/znc-bouncer"}'
|
||||
for (def branch in branches) {
|
||||
def upstream_branch = branch
|
||||
def my_branch = "l10n_${branch}"
|
||||
tasks[branch] = {
|
||||
stage(upstream_branch) {
|
||||
dir(upstream_branch) {
|
||||
stage('Checkout') {
|
||||
checkout([$class: 'GitSCM', branches: [[name: "*/${upstream_branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption', recursiveSubmodules: true]], userRemoteConfigs: [[credentialsId: '6ef10f80-20dc-4661-af45-52a6e1e15749', name: 'upstream', url: "github.com:${upstream_user}/${upstream_repo}.git"]]])
|
||||
}
|
||||
stage('Prepare strings') {
|
||||
dir("build") {
|
||||
sh 'pwd'
|
||||
sh "cmake .."
|
||||
sh 'make translation'
|
||||
}
|
||||
sh 'rm -rf build/'
|
||||
sh 'git status'
|
||||
}
|
||||
stage('Crowdin') {
|
||||
withCredentials([string(credentialsId: '11c7e2b4-f990-4670-98a4-c89d2a5a2f43', variable: 'CROWDIN_API_KEY')]) {
|
||||
withEnv(['CROWDIN_BASE_PATH='+pwd()]) {
|
||||
sh "$crowdin_cli upload sources --branch ${upstream_branch}"
|
||||
// sh "$crowdin_cli upload translations --branch ${upstream_branch}"
|
||||
sh "$crowdin_cli download --branch ${upstream_branch}"
|
||||
}
|
||||
}
|
||||
sh 'LANG=en_US.utf8 find . -name "*.po" -exec msgfilter -i "{}" -o "{}.replacement" .ci/cleanup-po.pl ";"'
|
||||
sh 'find . -name "*.po" -exec mv "{}.replacement" "{}" ";"'
|
||||
}
|
||||
stage('Push') {
|
||||
sh 'git config user.name "ZNC-Jenkins"'
|
||||
sh 'git config user.email jenkins@znc.in'
|
||||
sh 'git status'
|
||||
sh 'git add .'
|
||||
try {
|
||||
sh 'git commit -m "Update translations from Crowdin"'
|
||||
} catch(e) {
|
||||
echo 'No changes found'
|
||||
return
|
||||
}
|
||||
sh "git remote add my github.com:${my_user}/${my_repo}.git"
|
||||
// TODO simplify when https://issues.jenkins-ci.org/browse/JENKINS-28335 is fixed
|
||||
withCredentials([sshUserPrivateKey(credentialsId: '6ef10f80-20dc-4661-af45-52a6e1e15749', keyFileVariable: 'GITHUB_KEY')]) {
|
||||
sh 'echo ssh -i $GITHUB_KEY -l git -o StrictHostKeyChecking=no \\"\\$@\\" > run_ssh.sh'
|
||||
sh 'chmod +x run_ssh.sh'
|
||||
withEnv(['GIT_SSH=run_ssh.sh']) {
|
||||
sh "git push my HEAD:refs/heads/${my_branch} -f"
|
||||
}
|
||||
}
|
||||
// Create pull request if it doesn't exist yet
|
||||
withCredentials([string(credentialsId: '7a2546ae-8a29-4eab-921c-6a4803456dce', variable: 'GITHUB_OAUTH_KEY')]) {
|
||||
def headers = [[maskValue: true, name: 'Authorization', value: "token ${env.GITHUB_OAUTH_KEY}"], [maskValue: false, name: 'Accept', value: 'application/vnd.github.v3+json'], [maskValue: false, name: 'User-Agent', value: 'https://github.com/znc/znc/blob/master/.ci/Jenkinsfile.crowdin']]
|
||||
def pulls = httpRequest consoleLogResponseBody: true, customHeaders: headers, url: "https://api.github.com/repos/${upstream_user}/${upstream_repo}/pulls?head=${my_user}:${my_branch}&base=${upstream_branch}"
|
||||
pulls = new JsonSlurper().parseText(pulls.content)
|
||||
if (!pulls) {
|
||||
httpRequest consoleLogResponseBody: true, customHeaders: headers, url: "https://api.github.com/repos/${upstream_user}/${upstream_repo}/pulls", httpMode: 'POST', requestBody: '{"head":"'+my_user+':'+my_branch+'","base":"'+upstream_branch+'","title":"Update translations","body":"From https://crowdin.com/project/znc-bouncer"}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parallel tasks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user