pipeline {
    agent any
    stages {
        stage('install_requirements') {
            steps {
                sh """
                    [ -d venv ] && rm -rf venv

                    virtualenv -p python3 venv
                    . venv/bin/activate

                    pip install --upgrade pip isort
                    pip install -r requirements.txt
                """
            }
        }
        stage('tests') {
            parallel {
                stage('syntax checking using editorconfig-checker') {
                    steps {
                        sh """
                            wget -Oec-linux-amd64.tar.gz https://github.com/editorconfig-checker/editorconfig-checker/releases/latest/download/ec-linux-amd64.tar.gz
                            tar -xzf ec-linux-amd64.tar.gz && rm ec-linux-amd64.tar.gz
                            bin/ec-linux-amd64 -no-color -exclude '^bin/'
                        """
                    }
                }
                stage('config and metadata determinism') {
                    steps {
                        sh """
                            . venv/bin/activate

                            export BW_VAULT_DUMMY_MODE=1
                            export BW_PASS_DUMMY_MODE=1
                            bw test --metadata-determinism 3 --config-determinism 3
                        """
                    }
                }
                stage('bw test -i') {
                    steps {
                        sh """
                            . venv/bin/activate

                            bw test --ignore-missing-faults

                            export BW_VAULT_DUMMY_MODE=1
                            export BW_PASS_DUMMY_MODE=1
                            bw test
                        """
                    }
                }
            }
        }
    }
    post {
        always {
            sh """
                rm -rf venv
                rm -rf bin
            """
        }
    }
}