summaryrefslogtreecommitdiff
path: root/build-aux/Jenkinsfile.pr
blob: 46c5e47a0f1e003bac5c0bf1c836b03110c5acdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!groovy
//
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
build_and_test = '''
mkdir -p ${ERLANG_VERSION}
cd ${ERLANG_VERSION}
rm -rf build
mkdir build
cd build
tar -xf ${WORKSPACE}/apache-couchdb-*.tar.gz
cd apache-couchdb-*
./configure --enable-nouveau
make check || (make build-report && false)
'''

docs_changed = "git diff --name-only origin/${env.CHANGE_TARGET} | grep -q '^src/docs/'"
other_changes = "git diff --name-only origin/${env.CHANGE_TARGET} | grep -q -v '^src/docs/'"

pipeline {

  // no top-level agent; agents must be declared for each stage
  agent none

  environment {
    recipient = 'notifications@couchdb.apache.org'
    // Following fix an issue with git <= 2.6.5 where no committer
    // name or email are present for reflog, required for git clone
    GIT_COMMITTER_NAME = 'Jenkins User'
    GIT_COMMITTER_EMAIL = 'couchdb@apache.org'
    // Parameters for the matrix build
    DOCKER_IMAGE_BASE = 'apache/couchdbci-debian:bullseye-erlang'
    // https://github.com/jenkins-infra/jenkins.io/blob/master/Jenkinsfile#64
    // We need the jenkins user mapped inside of the image
    // npm config cache below deals with /home/jenkins not mapping correctly
    // inside the image
    DOCKER_ARGS = '-e npm_config_cache=npm-cache -e HOME=. -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group'

    // *** BE SURE TO ALSO CHANGE THE ERLANG VERSIONS FARTHER DOWN ***
    // Search for ERLANG_VERSION
    // see https://issues.jenkins.io/browse/JENKINS-61047 for why this cannot
    // be done parametrically
    LOW_ERLANG_VER = '23.3.4.18'
  }

  options {
    buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
    // This fails the build immediately if any parallel step fails
    parallelsAlwaysFailFast()
    preserveStashes(buildCount: 10)
    timeout(time: 3, unit: 'HOURS')
    timestamps()
  }

  stages {

    stage('Setup Env') {
      agent {
        docker {
          image "${DOCKER_IMAGE_BASE}-${LOW_ERLANG_VER}"
          label 'docker'
          args "${DOCKER_ARGS}"
          registryUrl 'https://docker.io/'
          registryCredentialsId 'dockerhub_creds'
        }
      }
      options {
        timeout(time: 10, unit: 'MINUTES')
      }
      steps {
        script {
          env.DOCS_CHANGED = '0'
          env.ONLY_DOCS_CHANGED = '0'
          if ( sh(returnStatus: true, script: docs_changed) == 0 ) {
            env.DOCS_CHANGED = '1'
            if (sh(returnStatus: true, script: other_changes) == 1) {
              env.ONLY_DOCS_CHANGED = '1'
            }
          }
        }
      }
      post {
        cleanup {
          // UGH see https://issues.jenkins-ci.org/browse/JENKINS-41894
          sh 'rm -rf ${WORKSPACE}/*'
        }
      }
    } // stage 'Setup Environment'

    stage('Docs Check') {
      // Run docs `make check` stage if any docs changed
      when {
        beforeOptions true
        expression { DOCS_CHANGED == '1' }
      }
      agent {
        docker {
          image "${DOCKER_IMAGE_BASE}-${LOW_ERLANG_VER}"
          label 'docker'
          args "${DOCKER_ARGS}"
          registryUrl 'https://docker.io/'
          registryCredentialsId 'dockerhub_creds'
        }
      }
      options {
        timeout(time: 15, unit: 'MINUTES')
      }
      steps {
        sh '''
          make python-black
        '''
        sh '''
          (cd src/docs && make check)
        '''
      }
      post {
        cleanup {
          // UGH see https://issues.jenkins-ci.org/browse/JENKINS-41894
          sh 'rm -rf ${WORKSPACE}/*'
        }
      }
    } // stage Docs Check

    stage('Build Docs') {
      // Build docs separately if only docs changed. If there are other changes, docs are
      // already built as part of `make dist`
      when {
        beforeOptions true
        expression { ONLY_DOCS_CHANGED == '1' }
      }
      agent {
        docker {
          image "${DOCKER_IMAGE_BASE}-${LOW_ERLANG_VER}"
          label 'docker'
          args "${DOCKER_ARGS}"
          registryUrl 'https://docker.io/'
          registryCredentialsId 'dockerhub_creds'
        }
      }
      options {
        timeout(time: 30, unit: 'MINUTES')
      }
      steps {
        sh '''
           (cd src/docs && ./setup.sh ; make html)
         '''
      }
      post {
        cleanup {
          // UGH see https://issues.jenkins-ci.org/browse/JENKINS-41894
          sh 'rm -rf ${WORKSPACE}/*'
        }
      }
    } // stage Build Docs

    stage('Source Format Checks') {
      when {
        beforeOptions true
        expression { ONLY_DOCS_CHANGED == '0' }
      }
      agent {
        docker {
          image "${DOCKER_IMAGE_BASE}-${LOW_ERLANG_VER}"
          label 'docker'
          args "${DOCKER_ARGS}"
          registryUrl 'https://docker.io/'
          registryCredentialsId 'dockerhub_creds'
        }
      }
      options {
        timeout(time: 15, unit: "MINUTES")
      }
      steps {
        sh '''
          rm -rf apache-couchdb-*
          ./configure --skip-deps --spidermonkey-version 78
          make erlfmt-check
          make elixir-source-checks
          make python-black
        '''
      }
      post {
        cleanup {
          // UGH see https://issues.jenkins-ci.org/browse/JENKINS-41894
          sh 'rm -rf ${WORKSPACE}/*'
        }
      }
    } // stage Erlfmt


    stage('Make Dist') {
      when {
        beforeOptions true
        expression { ONLY_DOCS_CHANGED == '0' }
      }
      agent {
        docker {
          image "${DOCKER_IMAGE_BASE}-${LOW_ERLANG_VER}"
          label 'docker'
          args "${DOCKER_ARGS}"
          registryUrl 'https://docker.io/'
          registryCredentialsId 'dockerhub_creds'
        }
      }
      options {
        timeout(time: 15, unit: "MINUTES")
      }
      steps {
        sh '''
          rm -rf apache-couchdb-*
          ./configure --spidermonkey-version 78 --enable-nouveau
          make dist
          chmod -R a+w * .
        '''
      }
      post {
        success {
          stash includes: 'apache-couchdb-*.tar.gz', name: 'tarball'
        }
        cleanup {
          // UGH see https://issues.jenkins-ci.org/browse/JENKINS-41894
          sh 'rm -rf ${WORKSPACE}/*'
        }
      }
    } // stage Make Dist

    // TODO Rework once Improved Docker Pipeline Engine is released
    // https://issues.jenkins-ci.org/browse/JENKINS-47962
    // https://issues.jenkins-ci.org/browse/JENKINS-48050

    stage('Make Check') {
      when {
        beforeOptions true
        expression { ONLY_DOCS_CHANGED == '0' }
      }
      matrix {
        axes {
          axis {
            name 'ERLANG_VERSION'
            values '23.3.4.18', '24.3.4.10', '25.3'
          }
          axis {
            name 'SM_VSN'
            values '78'
          }
        }

        stages {
          stage('Build and Test') {
            agent {
              docker {
                image "${DOCKER_IMAGE_BASE}-${ERLANG_VERSION}"
                label 'docker'
                args "${DOCKER_ARGS}"
              }
            }
            options {
              skipDefaultCheckout()
              timeout(time: 90, unit: "MINUTES")
            }
            steps {
              unstash 'tarball'
              sh( script: build_and_test )
            }
            post {
              always {
                junit '**/.eunit/*.xml, **/_build/*/lib/couchdbtest/*.xml, **/src/mango/nosetests.xml, **/test/javascript/junit.xml'
              }
              cleanup {
                sh 'rm -rf ${WORKSPACE}/*'
              }
            }
          } // stage
        } // stages
      } // matrix
    } // stage "Make Check"
  } // stages
} // pipeline