pipeline {
  agent any

  environment {
    CARGO_HOME = '/var/jenkins_home/.cargo'
    CARGO_TARGET_DIR = 'target'

    CARGO_TERM_COLOR = 'always'
  }

  stages {
    stage('Build') {
      steps {
        sh '''
          set -eux
          make ci-domains
        '''
//        withChecks(name: 'Test', includeStage: true) {
//          sh '''
//            set -eux
//            make ci-domains
//          '''
//          recordCoverage(
//            tools: [[parser: 'COBERTURA', pattern: 'target/llvm-cov/cobertura.xml']],
//            sourceCodeRetention: 'LAST_BUILD',
//            enabledForFailure: true,
//            failOnError: false,
//            checksAnnotationScope: 'MODIFIED_LINES',
//            id: 'rust-coverage',
//            name: 'Rust Coverage',
//            checksName: 'Rust Coverage',
//            qualityGates: [
//              [metric: 'LINE',   baseline: 'MODIFIED_LINES', threshold: 0.0],
//              [metric: 'LINE',   baseline: 'PROJECT',        threshold: 0.0],
//              [metric: 'BRANCH', baseline: 'PROJECT',        threshold: 0.0]
//            ]
//          )
//        }
      }
    } // Test

    stage('Reports') {
      steps {
        publishHTML(target: [
          allowMissing: false,
          alwaysLinkToLastBuild: true,
          keepAll: true,
          reportDir: 'target/llvm-cov/html',
          reportFiles: 'index.html',
          reportName: 'Rust Coverage HTML',
          reportTitles: 'Coverage Report'
        ])

        archiveArtifacts artifacts: 'target/llvm-cov/**', fingerprint: true
      }
    } // Reports
  }
}
