@Library('eo-jenkins-lib@main') import eo.Utils

pipeline {
    agent any
    options { disableConcurrentBuilds() }
    stages {
        stage('Help Check') {
            steps {
                script {
                     sh '(cd help/fr/ && if [ $(yelp-build html *.page 2>&1 | wc -c) -ne 0 ]; then exit 1; fi)'
                     sh 'git clean -xdf'
                }
            }
        }
        stage('Packaging') {
            steps {
                script {
                    if (env.JOB_NAME == 'publik-base-theme' && env.GIT_BRANCH == 'origin/main') {
                        sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder -d buster,bullseye publik-base-theme'
                    } else if (env.GIT_BRANCH.startsWith('hotfix/')) {
                        sh "sudo -H -u eobuilder /usr/local/bin/eobuilder -d buster,bullseye --branch ${env.GIT_BRANCH} --hotfix publik-base-theme"
                    }
                }
            }
        }
    }
    post {
        always {
            script {
                utils = new Utils()
                utils.mail_notify(currentBuild, env, 'ci+jenkins-publik-base-theme@entrouvert.org')
            }
        }
        success {
            cleanWs()
        }
    }
}
