pipeline {

  agent {
    kubernetes {
      inheritFrom 'basic'
      defaultContainer 'python'
      yaml """
        apiVersion: v1
        kind: Pod
        spec:
          containers:
          - name: python
            image: python:3.14-slim
            command: ["cat"]
            tty: true
            resources:
              limits:
                memory: "4096Mi"
                cpu: "2000m"
              requests:
                memory: "4096Mi"
                cpu: "1000m"
      """    }
  }
    
  options {
    quietPeriod(2)
    parallelsAlwaysFailFast()
    timeout(time: 1, unit: 'HOURS') // 1 week
    buildDiscarder(logRotator(numToKeepStr: '16'))
    disableConcurrentBuilds(abortPrevious: true)
  }

  environment {
    HOME = "${WORKSPACE}"
  }

  stages {
    stage('Build module') {
      steps {
          sh ('''
          set +x
	        id
          export PATH=$PATH:$HOME/.local/bin
          pip install hatch
          hatch build
          pip install dist/eclipse_care-*-py3-none-any.whl
          ''')
      }
    }
    stage('Build docs') {
      steps {
          sh ('''
          set +x
	        export PATH=$PATH:$HOME/.local/bin
	        hatch run docs:build
          ''')
      }
    }
    stage('Run tests') {
      steps {
        withCredentials([file(credentialsId: 'ECARE_CONF_FILE', variable: 'ECARE_CONF_FILE')]) {
          // available as an env variable, but will be masked if you try to print it out any which way
          // note: single quotes prevent Groovy interpolation; expansion is by Bourne Shell, which is what you want
            sh ('''
            set +x
	          export PATH=$PATH:$HOME/.local/bin
            cp $ECARE_CONF_FILE ./
	          hatch test --cover
            ''')
        }
      }
    }
  }
  
  post {
    always {
      archiveArtifacts artifacts: 'site/**/*.*', fingerprint: true
      }
  }

}
