pipeline {
    agent {
        kubernetes {
            label "liquidata-inc-ld-build"
        }
    }
    stages {
        stage('Run sqllogictests against Dolt commits') {
            environment {
                PATH = "${pwd()}/.ci_bin/node_modules/.bin:${env.PATH}"
                TMPDIR = "${pwd()}/tempDir"
                DOLT_ROOT_PATH="${pwd()}/tempRoot"
                DOLT_CREDS = credentials("system-account-dolthub-creds")
                TMP_TESTING_DIR = "${pwd()}/tempTesting"
                TMP_CSV_DIR = "${pwd()}/tempCSV"
            }
            steps {
                sh "rm -rf tempDolt"
                sh "rm -rf $TMPDIR && mkdir $TMPDIR"
                sh "rm -rf $TMP_CSV_DIR && mkdir $TMP_CSV_DIR"
                sh "rm -rf $DOLT_ROOT_PATH && mkdir $DOLT_ROOT_PATH"
                dir ("sqllogictest") {
                    git url: "https://github.com/dolthub/sqllogictest.git"
                }
                dir ("tempDolt") {
                    git url: "https://github.com/dolthub/dolt.git"
                }
                dir ("benchmark/sqllogictest_tester") {
                    sh "nice ./run_tester.sh ./tester.vars"
                }
            }
        }
    }
    post {
        always {
            node ("liquidata-inc-ld-build") {
                cleanWs() // cleanup
            }
        }
        failure {
             emailext body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}",
                to: "$TEST_WATCHERS",
                subject: "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"
        }
    }
}
