pipeline {
    agent any

    environment {
        PHP_VERSION = '8.1'
        COMPOSER_HOME = "${WORKSPACE}/.composer"
        DASHBOARD = '/var/www/lpj'
        WORKDIR =  '/var/www/lpj/Modules/Lpj'
        GIT_SSH_COMMAND = 'ssh -i ~/.ssh/for_gitea -o StrictHostKeyChecking=no'
    }

    stages {
        stage('Checkout') {
            steps {
                dir("${env.DASHBOARD}") {
                    sh "composer update daengdeni/lpj-module:dev-staging"
                }
            }
        }

        stage('Build Assets') {
            steps {
                dir("${env.DASHBOARD}") {
                    sh "npm install"
                    sh "npm run build"
                }
            }
        }
    }

    post {
        always {
            cleanWs()
        }
        success {
            echo 'The pipeline has succeeded!'
        }
        failure {
            echo 'The pipeline has failed.'
        }
    }
}
