/*  This is intended to test the dev & master branches of the gr-api project,
    where the tests are entirely self contained
*/

pipeline {
    agent any

    triggers {
        cron('H */6 * * *')
        pollSCM('H */3 * * *')
    }

    options {
        skipDefaultCheckout()
    }

    environment {
        DATA_SRC = "${env.WORKSPACE}/mnt/"
        VENV = "${env.WORKSPACE}/amt-jb-venv"
    }

    stages {

        stage('setup') {
            steps {
                deleteDir()

                withCredentials([file(
                    credentialsId: '971e1f48-09ce-4446-9155-a52c1adb6249',
                    variable: 'ENV_TEST_FILE')]) {
                    sh 'cp $ENV_TEST_FILE .env.test'
                }
                sh "/usr/local/bin/python3.14 -m venv ${VENV}"
                sh "${VENV}/bin/pip install -U setuptools wheel pip"
                sh "${VENV}/bin/pip install -r requirements.txt"
                sh "${VENV}/bin/pip install django"
            }
        }

        stage('tests') {
            steps {
                sh '$VENV/bin/pytest tests/test_postgres.py -vs'
            }
        }

    }
    post {
        always {
            echo 'One way or another, I have finished'
            deleteDir() /* clean up our workspace */
        }
    }
}
