pipeline {
    agent {
        node {
            label 'devenv'
        }
    }
    triggers {
        cron('H/10 * * * *')
    }
    stages {
        stage('Test devenv') {
            steps {
                sh 'devenv test'
            }
        }
        stage('Parallel Build and Deploy') {
            parallel {
                stage('Android') {
                    stages {
                        stage('Build') {
                            steps {
                                sh 'devenv shell flutter build apk'
                            }
                        }
                        stage('Deploy') {
                            steps {
                                echo 'Push to f-droid not yet implemented, archiving instead'
                                archiveArtifacts artifacts: 'build/app/outputs/apk/release/app-release.apk'
                            }
                        }
                    }
                }
                stage('Web') {
                    stages {
                        stage('Build') {
                            steps {
                                sh 'devenv shell flutter build web --release'
                                sh 'docker build -t harbor.julian-mutter.de/sheetless/sheetless-frontend .'
                            }
                        }
                        stage('Deploy') {
                            steps {
                                withDockerRegistry([credentialsId: 'harbor-login-julian', url: 'https://harbor.julian-mutter.de']) {
                                    sh 'docker push harbor.julian-mutter.de/sheetless/sheetless-frontend'
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
