pipeline {
  agent none
  options {
    disableConcurrentBuilds()
    buildDiscarder(logRotator(numToKeepStr: '8', daysToKeepStr: '20'))
  }
  stages {
    stage('GPU Testing') {
      parallel {
        stage('NDTensorsCUDAExt julia-1.10') {
	        options {
            timeout(time: 45, unit: 'MINUTES')
          }
          agent {
            dockerfile {
              label 'gpu&&v100'
              filename 'Dockerfile'
              dir 'jenkins'
              additionalBuildArgs  '--build-arg JULIA=1.10'
              args '--gpus "device=1"'
            }
          }
          environment {
            HOME = pwd(tmp:true)
            OMP_NUM_THREADS = 4
            JULIA_NUM_THREADS = 4
          }
          steps {
            sh '''
              julia -e 'using Pkg; Pkg.activate(temp=true); Pkg.Registry.update(); Pkg.update(); Pkg.develop(path="./NDTensors"); Pkg.develop(path="."); Pkg.test("NDTensors"; test_args=["cuda"])'
            '''
          }
        }
        stage('NDTensorscuTENSORExt julia-1.10') {
	        options {
            timeout(time: 45, unit: 'MINUTES')
          }
          agent {
            dockerfile {
              label 'gpu&&v100'
              filename 'Dockerfile'
              dir 'jenkins'
              additionalBuildArgs  '--build-arg JULIA=1.10'
              args '--gpus "device=1"'
            }
          }
          environment {
            HOME = pwd(tmp:true)
            OMP_NUM_THREADS = 4
            JULIA_NUM_THREADS = 4
          }
          steps {
            sh '''
              julia -e 'using Pkg; Pkg.activate(temp=true); Pkg.Registry.update(); Pkg.update(); Pkg.develop(path="./NDTensors"); Pkg.develop(path="."); Pkg.test("NDTensors"; test_args=["cutensor"])'
            '''
          }
        }
        stage('NDTensorsMetalExt Julia-1.10'){
          options {
            timeout(time: 45, unit: 'MINUTES')
          }
          agent {
            label 'm1'
          }
          environment{
            PATH="${env.HOME}/.juliaup/bin:${env.PATH}"
            PLATFORM = 'macos'
          }
          steps{
            sh '''
              juliaup update
            '''
            sh '''
              julia -e 'using Pkg; Pkg.activate(temp=true); Pkg.develop(path="./NDTensors"); Pkg.develop(path="."); Pkg.test("NDTensors"; test_args=["metal"])'
            '''
          }
        }
      }
    }
  }
}
