pipeline {
	agent {
		label 'windows'
	}
    stages {
        stage('Prepare') {
            steps {
                    
                    bat "git branch"
                    bat encoding: 'UTF-8', script:'chcp 65001 & opm install osparser'
                    bat encoding: 'UTF-8', script:'chcp 65001 & opm install cmdline'
                    bat encoding: 'UTF-8', script:'chcp 65001 & opm install asserts'
                    bat encoding: 'UTF-8', script:'chcp 65001 & opm install osparser'
                    bat encoding: 'UTF-8', script:'chcp 65001 & opm install coloratos'
                    bat encoding: 'UTF-8', script:'if exist Melezh rd /s /q Melezh'
                    bat encoding: 'UTF-8', script:'chcp 65001 & git clone https://github.com/bayselonarrend/Melezh'
            }
        }

        stage('Build') {
            steps {
                    bat encoding: 'UTF-8', script:'chcp 65001 & oscript ./ci/os/main.os'
                    bat encoding: 'UTF-8', script:'chcp 65001 & oscript ./ci/os/docs_main.os'
            }
        }

        stage('Local update'){
            steps {
                powershell encoding: 'UTF-8', script:'cd ./src/ru/OInt; opm build; opm install -f oint-1.30.0.ospx; del oint-1.30.0.ospx'
                powershell encoding: 'UTF-8', script:'cd ./src/ru/cli; opm build; opm install -f oint-cli-1.30.0.ospx; del oint-cli-1.30.0.ospx'
            }

        }

        stage('Update GIT') {
            steps {
                script {
                    
                    withCredentials([gitUsernamePassword(credentialsId: 'gitmain', gitToolName: 'Default')]) {
                        bat "git config user.email vitaly.the.alpaca@gmail.com"
                        bat 'git config user.name "Vitaly the Alpaca (bot)"'
                        bat "git config --global core.ignorecase true"
                        bat "git add ."
                        bat 'git commit -m "Main build (Jenkins)"'
                        bat "git push origin HEAD:main"
                    }
                        
                    
                }
            }
        }
    }
}