pipeline {
    agent { label 'ephemeral-linux-gpu' }
    options {
        // The Build GPU stage depends on the image from the Push CPU stage
        disableConcurrentBuilds()
    }
    environment {
        GIT_COMMIT_SHORT = sh(returnStdout: true, script:"git rev-parse --short=7 HEAD").trim()
        GIT_COMMIT_SUBJECT = sh(returnStdout: true, script:"git log --format=%s -n 1 HEAD").trim()
        GIT_COMMIT_AUTHOR = sh(returnStdout: true, script:"git log --format='%an' -n 1 HEAD").trim()
        GIT_COMMIT_SUMMARY = "`<https://github.com/Kaggle/docker-python/commit/${GIT_COMMIT}|${GIT_COMMIT_SHORT}>` ${GIT_COMMIT_SUBJECT} - ${GIT_COMMIT_AUTHOR}"
    }

    stages {
        stage('Build') {
            steps {
                sh '''#!/bin/bash
                set -exo pipefail
                
                cd tensorflow-whl/
                ./build | ts
                '''
            }
        }
        stage('Push') {
            steps {
                sh '''#!/bin/bash
                set -exo pipefail

                cd tensorflow-whl/
                ./push ${GIT_BRANCH}-staging
                '''
            }
        }
    }
}
