pipeline {
    agent any

    options {
        ansiColor('xterm')
        disableConcurrentBuilds()
        timestamps()
        timeout(time: 20, unit: 'MINUTES')
        buildDiscarder(logRotator(numToKeepStr: '60'))
    }

    parameters {
        string(name: 'TAGS', defaultValue: '@songwhip_app_prod', description: 'Playwright prod tags to run')
    }

    triggers {
        parameterizedCron('''
            H/15 * * * * % TAGS=@songwhip_app_prod
            30 6 * * * % TAGS=@songwhip_production_cache
        ''')
        upstream(upstreamProjects: 'theorchard/songwhip-api/master', threshold: hudson.model.Result.SUCCESS)
    }

    stages {
        stage('Load Shared Libraries') {
            steps {
                library "jenkins-global-libraries@master"
            }
        }

        stage('Run Playwright E2E Prod Tests') {
            steps {
                script {
                    playwrightTests(tags: params.TAGS, configEnvironment: 'prod', slackNotificationChannels: ['#prod-e2e-results', '#songwhip-alerts-dev'])
                }
            }
        }
    }
}
