pipeline {
    agent any

    options {
        ansiColor('xterm')
        disableConcurrentBuilds()
        timestamps()
    }

    parameters {
        string(name: 'SHARED_LIBRARIES_VERSION', defaultValue: 'master', description: 'The version of the Jenkins shared libraries to use. Can be a branch, tag, Git revision or PR ref (e.g. pull/PR_NUMBER/merge).')
    }

    triggers {
        issueCommentTrigger('.*retest this please.*')
    }

    stages {
        stage('Load Shared Libraries') {
            steps {
                library "jenkins-global-libraries@${params.SHARED_LIBRARIES_VERSION}"
            }
        }

        stage('Compliance Checks') {
            steps {
                script {
                    complianceChecks()
                }
            }
        }

        stage('Unit Tests and Style Checks') {
            steps {
                script {
                    sh "docker compose run --rm --build lint-and-test"
                }
            }
        }

        stage('Static Application Security Tests') {
            steps {
                script {
                    echo "Running Static App Security Tests"
                    sastTests
                }
            }
        }
    }

    post {
        cleanup {
            cleanWs()
        }
    }
}
