pipeline {
    agent any 
    stages {
        stage('Install Dependencies') {
            when {
                branch 'master'
            }
            steps {
                echo 'Installing Dependencies'
                sh '''curl -fsSL https://typst.community/typst-install/install.sh | sh'''
            }
        }
        stage('Build') {
            when {
                branch 'master'
            }
            steps {
                echo 'Building'
                sh "#!/bin/bash \n" + 
                '''export TYPST_INSTALL="/home/jenkins/.typst"\n''' +
                '''export PATH="$TYPST_INSTALL/bin:$PATH"\n''' +
                '''./render.sh'''
            }
        }
        // stage('Deploy') { 
        //     when {
        //         branch 'master'
        //     }
        //     steps {
        //         echo 'Deploying'
        //         sshagent(['jenkins-ssh-key']) {
        //             sh '''ssh airflow@clover "cd ~/airflow/dags && git fetch origin master && git reset --hard origin/master"''' 
        //         }
        //     }
        // }
    }

    post {
        always {
            archiveArtifacts artifacts: 'out/*.pdf', fingerprint: true
        }
    }
}