DEV_AWS_PROFILE = "twitch-extensions-configuration-dev"
PROD_AWS_PROFILE = "twitch-extensions-configuration-prod"
AWS_REGION = "us-west-2"

pipeline {
    agent any

    options {
        disableConcurrentBuilds()
        timeout(time: 10, unit: "MINUTES")
        ansiColor('xterm')
        timestamps()
    }

    stages {
        stage("lint") {
            steps {
                sh "make lint-docker"
            }
        }
        stage("test") {
            steps {
                sh "make test-docker"
            }
        }

        // Merging into develop branch starts a deploy to dev environment
        stage("deploy-develop") {
            when { branch "develop" }
            steps {
                withAWS(credentials: DEV_AWS_PROFILE, region: AWS_REGION) {
                    sh "make deploy-dev-jenkins"
                }
            }
        }

        // Merging into master branch starts a deploy to prod environment
        stage("deploy-production") {
            when { branch "master" }
            steps {
                withAWS(credentials: PROD_AWS_PROFILE, region: AWS_REGION) {
                    sh "make deploy-prod-jenkins"
                }
            }
        }
    }
}
