// Autogenerated by build scripts. Do not edit.

pipeline {
  agent {
    node {
      label 'jenkins-agent-web'
      customWorkspace '/workspace'
    }
  }
  options {
    timestamps()
    timeout(time: 15, unit: 'MINUTES')
  }
  environment {
    BRANCH_NAME = "${env.CHANGE_BRANCH ? env.CHANGE_BRANCH : env.BRANCH_NAME}"
    JENKINS_BUILD_NUMBER = "${BUILD_NUMBER}"
    BUILD_NUMBER = "${SHORT_SHA}_${BUILD_NUMBER}"
    COMMIT_SHA = "${GIT_COMMIT}"
    SHORT_SHA = "${GIT_COMMIT.take(7)}"
  }
  stages {
    stage('Stage 1') {
      parallel {
        stage('Install monorepo') {
          steps {
            retry(count: 3) {
              sh 'make monorepo_setup'
            }
          }
        }
        stage('Create reports folder') {
          steps {
            sh 'mkdir libraries/ranges-tracker/reports'
          }
        }
      }
    }
    stage('Stage 2') {
      parallel {
        stage('Lint') {
          steps {
            sh 'bin/run -w /overleaf/libraries/ranges-tracker monorepo npm run lint -- --format json --output-file reports/eslint.json'
          }
          post {
            always {
              sh """
                sed -i 's_"filePath":"/overleaf_"filePath":"/workspace_g' libraries/ranges-tracker/reports/eslint.json
              """
              recordIssues checksAnnotationScope: 'ALL', enabledForFailure: true, failOnError: true, id: 'ranges-tracker-eslint', name: 'ranges-tracker eslint', qualityGates: [[integerThreshold: 1, threshold: 1.0, type: 'TOTAL']], sourceCodeRetention: 'LAST_BUILD', tools: [esLint(pattern: 'libraries/ranges-tracker/reports/eslint.json')]
            }
          }
        }
        stage('Format') {
          steps {
            sh 'bin/run -w /overleaf/libraries/ranges-tracker monorepo npm run format'
          }
        }
        stage('Typecheck') {
          steps {
            sh 'bin/run -w /overleaf/libraries/ranges-tracker monorepo npm run types:check'
          }
        }
        stage('Test') {
          steps {
            retry(count: 3) {
              sh 'bin/run -w /overleaf/libraries/ranges-tracker monorepo npm run test:ci'
            }
          }
        }
      }
    }
  }
  post {
    always {
      junit checksName: 'ranges-tracker test results', testResults: 'libraries/ranges-tracker/reports/junit-*.xml'
    }
    cleanup {
      sh 'rm -rf libraries/ranges-tracker/reports'
      sh 'make clean_jenkins -j10'
    }
  }
}