code.vegaprotocol.io/vega@v0.79.0/Jenkinsfile (about)

     1  /* groovylint-disable DuplicateStringLiteral, LineLength, NestedBlockDepth */
     2  @Library('vega-shared-library') _
     3  
     4  /* properties of scmVars (example):
     5      - GIT_BRANCH:PR-40-head
     6      - GIT_COMMIT:05a1c6fbe7d1ff87cfc40a011a63db574edad7e6
     7      - GIT_PREVIOUS_COMMIT:5d02b46fdb653f789e799ff6ad304baccc32cbf9
     8      - GIT_PREVIOUS_SUCCESSFUL_COMMIT:5d02b46fdb653f789e799ff6ad304baccc32cbf9
     9      - GIT_URL:https://github.com/vegaprotocol/vega.git
    10  */
    11  def scmVars = null
    12  def version = 'UNKNOWN'
    13  def versionHash = 'UNKNOWN'
    14  def commitHash = 'UNKNOWN'
    15  
    16  
    17  pipeline {
    18      agent {
    19          label params.NODE_LABEL
    20      }
    21      options {
    22          skipDefaultCheckout true
    23          timestamps()
    24          timeout(time: isPRBuild() ? 60 : 120, unit: 'MINUTES')
    25          disableConcurrentBuilds(abortPrevious: true)
    26      }
    27      parameters {
    28          string( name: 'SYSTEM_TESTS_BRANCH', defaultValue: 'develop',
    29                  description: 'Git branch, tag or hash of the vegaprotocol/system-tests repository')
    30          string( name: 'VEGACAPSULE_BRANCH', defaultValue: '',
    31                  description: 'Git branch, tag or hash of the vegaprotocol/vegacapsule repository')
    32          string( name: 'VEGATOOLS_BRANCH', defaultValue: 'develop',
    33                  description: 'Git branch, tag or hash of the vegaprotocol/vegatools repository')
    34          string( name: 'DEVOPS_INFRA_BRANCH', defaultValue: 'master',
    35                  description: 'Git branch, tag or hash of the vegaprotocol/devops-infra repository')
    36          string( name: 'DEVOPSSCRIPTS_BRANCH', defaultValue: 'main',
    37                  description: 'Git branch, tag or hash of the vegaprotocol/devopsscripts repository')
    38          string( name: 'VEGA_MARKET_SIM_BRANCH', defaultValue: 'develop',
    39                  description: 'Git branch, tag or hash of the vegaprotocol/vega-market-sim repository')
    40          string( name: 'DEVOPSTOOLS_BRANCH', defaultValue: 'main',
    41                  description: 'Git branch, tag or hash of the vegaprotocol/devopstools repository')
    42          string( name: 'JENKINS_SHARED_LIB_BRANCH', defaultValue: 'main',
    43                  description: 'Git branch, tag or hash of the vegaprotocol/jenkins-shared-library repository')
    44          string( name: 'NODE_LABEL', defaultValue: 'core-build',
    45                  description: 'Label on which vega build should be run, if empty any any node is used')
    46          string( name: 'DOWNSTREAM_NODE_LABEL', defaultValue: '',
    47                  description: 'The node label for downstream jobs like system-tests, etc. Ignored if empty')
    48      }
    49      
    50      environment {
    51          CGO_ENABLED = 0
    52          GO111MODULE = 'on'
    53          BUILD_UID="${BUILD_NUMBER}-${EXECUTOR_NUMBER}"
    54          GOPATH = "/jenkins/GOPATH"
    55          GOBIN = "${env.GOPATH}/bin"
    56          PATH = "${env.GOBIN}:${env.PATH}"
    57      }
    58  
    59      stages {
    60      	stage('CI Config') {
    61                  steps {
    62                      sh "printenv"
    63                      echo "params=${params.inspect()}"
    64                      script {
    65                          publicIP = agent.getPublicIP()
    66                          print("Jenkins Agent public IP is: " + publicIP)
    67                      }
    68                  }
    69              }
    70  
    71          stage('Config') {
    72              steps {
    73                  cleanWs()
    74                  sh 'printenv'
    75                  echo "params=${params}"
    76                  echo "isPRBuild=${isPRBuild()}"
    77                  script {
    78                      params = pr.injectPRParams()
    79                      originRepo = pr.getOriginRepo('vegaprotocol/vega')
    80                  }
    81                  echo "params (after injection)=${params}"
    82  
    83                  script {
    84                      sh 'go version'
    85                  }
    86              }
    87          }
    88  
    89          //
    90          // Begin PREPARE
    91          //
    92          stage('Git clone') {
    93              options { retry(3) }
    94              steps {
    95                  dir('vega') {
    96                      script {
    97                          scmVars = checkout(scm)
    98                          versionHash = sh (returnStdout: true, script: "echo \"${scmVars.GIT_COMMIT}\"|cut -b1-8").trim()
    99                          version = sh (returnStdout: true, script: "git describe --tags 2>/dev/null || echo ${versionHash}").trim()
   100                          commitHash = getCommitHash()
   101                      }
   102                      echo "scmVars=${scmVars}"
   103                      echo "commitHash=${commitHash}"
   104                  }
   105              }
   106          }
   107  
   108          stage('publish to vega-dev-releases') {
   109              when {
   110                  branch 'develop'
   111              }
   112              steps {
   113                  startVegaDevRelease vegaVersion: versionHash,
   114                      jenkinsSharedLib: params.JENKINS_SHARED_LIB_BRANCH
   115              }
   116          }
   117  
   118          stage('Dependencies') {
   119              options { retry(3) }
   120              steps {
   121                  dir('vega') {
   122                      sh '''#!/bin/bash -e
   123                          go mod download -x
   124                      '''
   125                  }
   126              }
   127          }
   128          //
   129          // End PREPARE
   130          //
   131  
   132          //
   133          // Begin LINTERS
   134          //
   135          stage('Linters') {
   136              parallel {
   137                  stage('shellcheck') {
   138                      options { retry(3) }
   139                      steps {
   140                          dir('vega') {
   141                              sh "git ls-files '*.sh'"
   142                              sh "git ls-files '*.sh' | xargs shellcheck"
   143                          }
   144                      }
   145                  }
   146                  stage('yamllint') {
   147                      options { retry(3) }
   148                      steps {
   149                          dir('vega') {
   150                              sh "git ls-files '*.yml' '*.yaml'"
   151                              sh "git ls-files '*.yml' '*.yaml' | xargs yamllint -s -d '{extends: default, rules: {line-length: {max: 200}}}'"
   152                          }
   153                      }
   154                  }
   155                  stage('json format') {
   156                      options { retry(3) }
   157                      steps {
   158                          dir('vega') {
   159                              sh "git ls-files '*.json'"
   160                              sh "for f in \$(git ls-files '*.json'); do echo \"check \$f\"; jq empty \"\$f\"; done"
   161                          }
   162                      }
   163                  }
   164                  stage('markdown spellcheck') {
   165                      environment {
   166                          FORCE_COLOR = '1'
   167                      }
   168                      options { retry(3) }
   169                      steps {
   170                          dir('vega') {
   171                              ansiColor('xterm') {
   172                                  sh 'mdspell --en-gb --ignore-acronyms --ignore-numbers --no-suggestions --report "*.md" "docs/**/*.md" "!UPGRADING.md" "!DOCUMENTATION_STYLE.md"'
   173                              }
   174                          }
   175                          sh 'printenv'
   176                      }
   177                  }
   178              }
   179          }
   180          //
   181          // End LINTERS
   182          //
   183  
   184          //
   185          // Begin TESTS
   186          //
   187          stage('Tests') {
   188              parallel {
   189                  stage('approbation') {
   190                      when {
   191                          anyOf {
   192                              branch 'develop'
   193                              branch 'main'
   194                              branch 'master'
   195                          }
   196                      }
   197                      steps {
   198                          script {
   199                              runApprobation ignoreFailure: !isPRBuild(),
   200                                  originRepo: originRepo,
   201                                  vegaVersion: commitHash
   202                          }
   203                      }
   204                  }
   205                  stage('unit tests') {
   206                      options { retry(3) }
   207                      steps {
   208                          dir('vega') {
   209                              sh 'go test -short -timeout 30m -v ./... 2>&1 | tee unit-test-results.txt && cat unit-test-results.txt | go-junit-report > vega-unit-test-report.xml'
   210                              junit checksName: 'Unit Tests', testResults: 'vega-unit-test-report.xml'
   211                          }
   212                      }
   213                  }
   214                  stage('unit tests with race') {
   215                      environment {
   216                          CGO_ENABLED = 1
   217                      }
   218                      options { retry(3) }
   219                      steps {
   220                          dir('vega') {
   221                              sh 'go test -short -timeout 30m  -v -race ./... 2>&1 | tee unit-test-race-results.txt && cat unit-test-race-results.txt | go-junit-report > vega-unit-test-race-report.xml'
   222                              junit checksName: 'Unit Tests with Race', testResults: 'vega-unit-test-race-report.xml'
   223                          }
   224                      }
   225                  }
   226                  stage('core/integration tests') {
   227                      steps {
   228                          dir('vega/core/integration') {
   229                              sh 'go test . -timeout 30m --godog.format=junit:core-integration-report.xml'
   230                              junit checksName: 'Core Integration Tests', testResults: 'core-integration-report.xml'
   231  
   232                          }
   233                      }
   234                      post {
   235                          failure {
   236                             archiveArtifacts(
   237                                  artifacts: 'vega/core/integration/core-integration-report.xml',
   238                                  allowEmptyArchive: true
   239                              )
   240                          }
   241                      }
   242                  }
   243                  stage('core/integration perps tests') {
   244                      steps {
   245                          dir('vega/core/integration') {
   246                              sh 'go test . -timeout 30m -perps --godog.format=junit:core-integration-perps-report.xml'
   247                              junit checksName: 'Core Integration Perps Tests', testResults: 'core-integration-perps-report.xml'
   248                          }
   249                      }
   250                      post {
   251                          failure {
   252                             archiveArtifacts(
   253                                  artifacts: 'vega/core/integration/core-integration-perps-report.xml',
   254                                  allowEmptyArchive: true
   255                              )
   256                          }
   257                      }
   258                  }
   259                  stage('datanode/integration tests') {
   260                      options { retry(3) }
   261                      steps {
   262                          dir('vega/datanode/integration') {
   263                              sh 'go test -v ./... 2>&1 | tee integration-test-results.txt && cat integration-test-results.txt | go-junit-report > datanode-integration-test-report.xml'
   264                              junit checksName: 'Datanode Integration Tests', testResults: 'datanode-integration-test-report.xml'
   265                          }
   266                      }
   267                  }
   268                  stage('Vega Market Sim') {
   269                      steps {
   270                          script {
   271                              vegaMarketSim ignoreFailure: true,
   272                                  timeout: 45,
   273                                  originRepo: originRepo,
   274                                  vegaVersion: commitHash,
   275                                  vegaMarketSim: params.VEGA_MARKET_SIM_BRANCH,
   276                                  jenkinsSharedLib: params.JENKINS_SHARED_LIB_BRANCH,
   277                                  nodeLabel: params.DOWNSTREAM_NODE_LABEL,
   278                                  branchRun: isPRBuild(),
   279                                  parallelWorkers: "4"
   280                          }
   281                      }
   282                  }
   283                  stage('Vegavisor autoinstall and pup') {
   284                      steps {
   285                          script {
   286                              List visorAutoinstallParams = [
   287                                  string(name: 'RELEASES_REPO', value: 'vegaprotocol/vega-dev-releases-system-tests'),
   288                                  string(name: 'VEGA_BRANCH', value: commitHash),
   289                                  string(name: 'SYSTEM_TESTS_BRANCH', value: params.SYSTEM_TESTS_BRANCH ?: pipelineDefaults.capsuleSystemTests.branchSystemTests),
   290                                  string(name: 'VEGATOOLS_BRANCH', value: params.VEGATOOLS_BRANCH ?: pipelineDefaults.capsuleSystemTests.branchVegatools),
   291                                  string(name: 'VEGACAPSULE_BRANCH', value: params.VEGACAPSULE_BRANCH ?: pipelineDefaults.capsuleSystemTests.branchVegaCapsule),
   292                                  string(name: 'DEVOPSSCRIPTS_BRANCH', value: params.DEVOPSSCRIPTS_BRANCH ?: pipelineDefaults.capsuleSystemTests.branchDevopsScripts),
   293                                  booleanParam(name: 'CREATE_RELEASE', value: true),
   294                                  string(name: 'JENKINS_SHARED_LIB_BRANCH', value: params.JENKINS_SHARED_LIB_BRANCH ?: pipelineDefaults.capsuleSystemTests.jenkinsSharedLib),
   295                              ]
   296  
   297                              if (params.DOWNSTREAM_NODE_LABEL && params.DOWNSTREAM_NODE_LABEL.length() > 0) {
   298                                  visorAutoinstallParams << string(name: 'NODE_LABEL', value: params.DOWNSTREAM_NODE_LABEL)
   299                              }
   300  
   301                              build(
   302                                  job: '/common/visor-autoinstall-and-pup',
   303                                  propagate: true, // fast fail
   304                                  wait: true,
   305                                  parameters: visorAutoinstallParams,
   306                              )
   307                          }
   308                      }
   309                  }
   310  
   311                  stage('System Tests') {
   312                      steps {
   313                          script {
   314                              systemTestsCapsule ignoreFailure: !isPRBuild(),
   315                                  timeout: 45,
   316                                  originRepo: originRepo,
   317                                  vegaVersion: commitHash,
   318                                  systemTests: params.SYSTEM_TESTS_BRANCH,
   319                                  vegacapsule: params.VEGACAPSULE_BRANCH,
   320                                  vegatools: params.VEGATOOLS_BRANCH,
   321                                  devopsInfra: params.DEVOPS_INFRA_BRANCH,
   322                                  devopsScripts: params.DEVOPSSCRIPTS_BRANCH,
   323                                  jenkinsSharedLib: params.JENKINS_SHARED_LIB_BRANCH,
   324                                  downstreamNodeLabel: params.DOWNSTREAM_NODE_LABEL,
   325                                  devopstools: params.DEVOPSTOOLS_BRANCH
   326                          }
   327                      }
   328                  }
   329                  stage('mocks check') {
   330                      steps {
   331                          sh label: 'print go version', script: 'go version'
   332  
   333                          sh label: 'copy vega repo', script: '''#!/bin/bash -e
   334                                  cp -r ./vega ./vega-mocks-check
   335                              '''
   336                          dir('vega-mocks-check') {
   337                              sh '''#!/bin/bash -e
   338                                  make mocks_check
   339                              '''
   340                          }
   341                          sh label: 'remove vega copy', script: '''#!/bin/bash -e
   342                                  rm -rf ./vega-mocks-check
   343                              '''
   344                      }
   345                      post {
   346                          failure {
   347                              sh 'printenv'
   348                              echo "params=${params}"
   349                              dir('vega') {
   350                                  sh 'git diff'
   351                              }
   352                          }
   353                      }
   354                  }
   355                  stage('protos') {
   356                      environment {
   357                          GOPATH = "${env.WORKSPACE}/GOPATH"
   358                          GOBIN = "${env.GOPATH}/bin"
   359                          PATH = "${env.GOBIN}:${env.PATH}"
   360                      }
   361                      stages {
   362                          stage('Install dependencies') {
   363                              // We are using specific tools versions
   364                              // Please use exactly the same versions when modifying protos
   365                              options { retry(3) }
   366                              steps {
   367                                  dir('vega') {
   368                                      sh 'printenv'
   369                                      sh './script/gettools.sh'
   370                                  }
   371                              }
   372                          }
   373                          stage('buf lint') {
   374                              options { retry(3) }
   375                              steps {
   376                                  dir('vega') {
   377                                      sh '''#!/bin/bash -e
   378                                          buf lint
   379                                      '''
   380                                  }
   381                              }
   382                              post {
   383                                  failure {
   384                                      sh 'printenv'
   385                                      echo "params=${params}"
   386                                      sh 'buf --version'
   387                                      sh 'which buf'
   388                                      sh 'git diff'
   389                                  }
   390                              }
   391                          }
   392                          stage('proto format check') {
   393                              options { retry(3) }
   394                              steps {
   395                                  dir('vega') {
   396                                      sh '''#!/bin/bash -e
   397                                          make proto_format_check
   398                                      '''
   399                                  }
   400                              }
   401                              post {
   402                                  failure {
   403                                      sh 'printenv'
   404                                      echo "params=${params}"
   405                                      sh 'buf --version'
   406                                      sh 'which buf'
   407                                      sh 'git diff'
   408                                  }
   409                              }
   410                          }
   411                          stage('proto check') {
   412                              options { retry(3) }
   413                              steps {
   414                                  sh label: 'copy vega repo', script: '''#!/bin/bash -e
   415                                          cp -r ./vega ./vega-proto-check
   416                                      '''
   417                                  dir('vega-proto-check') {
   418                                      sh '''#!/bin/bash -e
   419                                          make proto_check
   420                                      '''
   421                                  }
   422                                  sh label: 'remove vega copy', script: '''#!/bin/bash -e
   423                                          rm -rf ./vega-proto-check
   424                                      '''
   425                              }
   426                              post {
   427                                  failure {
   428                                      sh 'printenv'
   429                                      echo "params=${params}"
   430                                      sh 'buf --version'
   431                                      sh 'which buf'
   432                                      sh 'git diff'
   433                                  }
   434                              }
   435                          }
   436                      }
   437                  }
   438                  stage('Compile visor') {
   439                      options { retry(3) }
   440                      steps {
   441                          sh 'printenv'
   442                          dir('vega') {
   443                              sh label: 'Compile', script: """#!/bin/bash -e
   444                                  go build -v \
   445                                      -o ../build/ \
   446                                      ./cmd/visor
   447                              """
   448                              sh label: 'check for modifications', script: 'git diff'
   449                          }
   450                          dir("build") {
   451                              sh label: 'list files', script: '''#!/bin/bash -e
   452                                  pwd
   453                                  ls -lah
   454                              '''
   455                              sh label: 'Sanity check', script: '''#!/bin/bash -e
   456                                  file *
   457                              '''
   458                              sh label: 'get version', script: '''#!/bin/bash -e
   459                                  ./visor version
   460                              '''
   461                          }
   462                      }
   463                  }
   464              }
   465          }
   466          //
   467          // End TESTS
   468          //
   469      }
   470      post {
   471          always {
   472              retry(3) {
   473                  script {
   474                      slack.slackSendCIStatus name: 'Vega Core CI', channel: '#tradingcore-notify'
   475                  }
   476              }
   477              cleanWs()
   478          }
   479      }
   480  }