#!/usr/bin/env groovy
properties(
    [
        pipelineTriggers([[$class: "tv.justin.jenkins.twitchgithub.GitHubPushTrigger"]]),
    ]
)

pipeline {
  agent any
  options {
    timestamps()
    ansiColor('xterm')
    quietPeriod(30)
  }
  stages {
    stage("Verify code") {
      agent any
      environment {
        ENVIRONMENT = "unittests"
      }
      stages {
        stage("Print debug info") {
          steps {
            script {
              currentBuild.displayName = env.GIT_COMMIT[0..6] + " #" + env.BUILD_NUMBER
            }
            sh 'git clean -ffdx'
            sh 'env'
            sh 'docker --version'
          }
        }
        stage("Lint") {
          steps {
            sh 'make lint-check'
          }
        }
        stage("Unit Test") {
          steps {
            sh 'make test'
          }
        }
      }
    }
    stage("Deploy Pypi") {
      agent any
      environment {
        TWITCH_PYPI_INTERNAL_PASSWORD = credentials('dta_tools_deploy')
        TWITCH_PYPI_INTERNAL_USERNAME = 'dta_tools'
        ENVIRONMENT = "production"
      }
      when {
        buildingTag()
      }
      steps {
        sh 'make deploy'
      }
    }
  }
}