File: Jenkinsfile

package info (click to toggle)
colobot 0.1.12-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 416,348 kB
  • sloc: cpp: 138,659; ansic: 3,063; python: 2,115; sh: 205; awk: 91; xml: 32; makefile: 31
file content (293 lines) | stat: -rw-r--r-- 11,705 bytes parent folder | download
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
289
290
291
292
293
#!/usr/bin/env groovy

pipeline {
    agent none
    options {
        buildDiscarder(logRotator(artifactDaysToKeepStr: '30', artifactNumToKeepStr: '20'))
    }
    stages {
        stage('Check pull request target') {
            when { changeRequest() }
            steps {
                script {
                    if (env.CHANGE_TARGET == 'master') {
                        throw "This pull request targets the wrong branch. Please reopen the pull request targetting the dev branch."
                    }
                }
            }
        }
        stage('Build') {
            parallel {
                stage('Build Windows') {
                    agent {
                        docker { image 'krzysh/colobot-build:latest' }
                    }
                    steps {
                        sh 'mkdir -p build/windows'
                        dir('build/windows') {
                            sh '''
                                # FIXME: without -lsetupapi linking sdl2 fails
                                /opt/mxe/usr/bin/i686-w64-mingw32.static-cmake \
                                    -DCMAKE_CXX_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lsetupapi" \
                                    -DCMAKE_INSTALL_PREFIX=/install \
                                    -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=0 ../..
                                make
                                rm -rf install
                                DESTDIR=. make install
                            '''
                        }
                    }
                    post {
                        success {
                            sh 'rm -f windows-debug.zip'
                            zip zipFile: 'windows-debug.zip', archive: true, dir: 'build/windows/install'
                        }
                    }
                }
                
                stage('Build Linux') {
                    agent {
                        docker { image 'krzysh/colobot-build:latest' }
                    }
                    steps {
                        sh 'mkdir -p build/linux'
                        dir('build/linux') {
                            sh '''
                                cmake \
                                    -DCMAKE_INSTALL_PREFIX=/install -DCMAKE_SKIP_INSTALL_RPATH=ON \
                                    -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=1 -DDESKTOP=1 ../..
                                make
                                rm -rf install
                                DESTDIR=. make install
                                patchelf --set-rpath '.' install/colobot
                            '''
                        }
                    }
                    post {
                        success {
                            sh 'rm -f linux-debug.zip'
                            dir('build/linux') {
                                sh '''
                                    # Clean up
                                    rm -rf squashfs-root
                                    rm -rf colobot.AppDir
                                    rm -rf appimage
                                    rm -f Colobot-x86_64.AppImage
                                
                                    # Download app image tool
                                    wget -N https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
                                    chmod +x linuxdeploy-x86_64.AppImage
                                    ./linuxdeploy-x86_64.AppImage --appimage-extract
                                    
                                    # Create AppImage
                                    NO_STRIP=1 ./squashfs-root/AppRun -e colobot --output appimage --appdir colobot.AppDir -d desktop/colobot.desktop -i ../../desktop/colobot.svg
                                    chmod +x Colobot-x86_64.AppImage
                                    
                                    # Prepare folder for zip
                                    mkdir -p appimage
                                    cp -rp install/data appimage/data
                                    cp -rp install/lang appimage/lang
                                    cp -p Colobot-x86_64.AppImage appimage/colobot
                                '''
                            }
                            zip zipFile: 'linux-debug.zip', archive: true, dir: 'build/linux/appimage'
                        }
                    }
                }
            }
        }

        stage('Generate docs') {
            agent {
                docker { image 'krzysh/colobot-build:latest' }
            }
            steps {
                dir('build/linux') {
                    sh 'make doc'
                }
            }
            post {
                success {
                    publishHTML([reportName: 'Doxygen', reportDir: 'build/linux/doc/html', reportFiles: 'index.html', reportTitles: '', allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false])
                }
            }
        }

        stage('Run tests') {
            agent {
                docker { image 'krzysh/colobot-build:latest' }
            }
            steps {
                dir('build/linux') {
                    sh './colobot_ut --gtest_output=xml:gtestresults.xml || true'
                }
                step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '0'], [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']], tools: [[$class: 'GoogleTestType', deleteOutputFiles: true, failIfNotNew: true, pattern: 'build/linux/gtestresults.xml', skipNoTestFiles: false, stopProcessingIfError: true]]])
            }
            // TODO: Maybe run Windows tests using wine as well?
        }

        stage('Run colobot-lint') {
            agent {
                label 'colobot-build'
            }
            environment {
                CC = '/usr/lib/llvm-3.6/bin/clang'
                CXX = '/usr/lib/llvm-3.6/bin/clang++'
                CLANG_PREFIX = '/usr/lib/llvm-3.6'
            }
            steps {
                copyArtifacts filter: 'build/colobot-lint,build/html_report.tar.gz,Tools/count_errors.py', fingerprintArtifacts: true, projectName: 'colobot/colobot-lint/master', selector: lastSuccessful(), target: 'colobot-lint'
                sh 'chmod +x colobot-lint/Tools/count_errors.py' // TODO: ???
                sh 'mkdir -p build/lint'
                dir('build/lint') {
                    // The cd is required here because /var/lib/jenkins is a symlink and colobot-lint breaks otherwise...
                    sh 'cd $WORKSPACE/build/lint; cmake -DCOLOBOT_LINT_BUILD=1 -DTESTS=1 -DTOOLS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 $WORKSPACE'
                    sh '''#!/bin/bash
set -e +x

# Run colobot-lint

COLOBOT_DIR="$WORKSPACE"
COLOBOT_BUILD_DIR="$WORKSPACE/build/lint"

COLOBOT_LINT_BUILD_DIR="$WORKSPACE/colobot-lint/build"

COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml"

# CLANG_PREFIX="/usr/lib/llvm-3.6" # Set in top-level environment block

cd "$COLOBOT_LINT_BUILD_DIR"
chmod +x ./colobot-lint

# Workaround for Clang not finding system headers
rm -rf bin/
mkdir -p bin
mv ./colobot-lint ./bin/
rm -f ./lib
ln -s ${CLANG_PREFIX}/lib ./lib

echo "Running colobot-lint"
find "$WORKSPACE" \\( -wholename "$COLOBOT_DIR/src/*.cpp" \
                 -or -wholename "$COLOBOT_DIR/test/unit/*.cpp" \
                 -or -wholename "$COLOBOT_BUILD_DIR/fake_header_sources/src/*.cpp" \
                 -or -wholename "$COLOBOT_BUILD_DIR/fake_header_sources/test/unit/*.cpp" \\) \
        -exec ./bin/colobot-lint \
        -verbose \
        -output-format xml \
        -output-file "$COLOBOT_LINT_REPORT_FILE" \
        -p "$COLOBOT_BUILD_DIR" \
        -project-local-include-path "$COLOBOT_DIR/src" -project-local-include-path "$COLOBOT_BUILD_DIR/src" \
        -license-template-file "$COLOBOT_DIR/LICENSE-HEADER.txt" \
        {} +
                    '''
                    sh '''#!/bin/bash
set -e +x

# Generate HTML report

COLOBOT_LINT_BUILD_DIR="$WORKSPACE/colobot-lint/build"
COLBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml"
HTML_REPORT_DIR="$WORKSPACE/build/lint/html_report"

echo "Generating HTML report"
cd "$COLOBOT_LINT_BUILD_DIR"
rm -rf HtmlReport/
tar -zxf html_report.tar.gz
HtmlReport/generate.py --xml-report "$COLBOT_LINT_REPORT_FILE" --output-dir "$HTML_REPORT_DIR"
                    '''
                    script {
                        retcode = sh script: '''#!/bin/bash
set -e +x

# Update stable/unstable build status

ret=0

COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/lint/colobot_lint_report.xml"
COLOBOT_LINT_DIR="$WORKSPACE/colobot-lint"

OVERALL_STABLE_RULES=(
    "class naming"
    "code block placement"
    "compile error"
#    "compile warning"
#    "enum naming"
#    "function naming"
    "header file not self-contained"
#    "implicit bool cast"
#    "include style"
#    "inconsistent declaration parameter name"
    "license header"
#    "naked delete"
#    "naked new"
#    "old style function"
    "old-style null pointer"
#    "possible forward declaration"
    "undefined function"
#    "uninitialized field"
#    "uninitialized local variable"
#    "unused forward declaration"
#    "variable naming"
    "whitespace"
)

echo "Checking rule stability (overall)"
for ((i = 0; i < ${#OVERALL_STABLE_RULES[@]}; i++)); do
    rule="${OVERALL_STABLE_RULES[$i]}"
    count="$("$COLOBOT_LINT_DIR/Tools/count_errors.py" --rule-filter="$rule" --xml-report-file "$COLOBOT_LINT_REPORT_FILE")"
    if [ "$count" != "0" ]; then
       echo "UNSTABLE RULE: $rule ($count occurences)"
       ret=1
    fi
done

STABLE_RULES_WITHOUT_CBOT=(
    "class naming"
    "code block placement"
    "compile error"
    "compile warning"
#    "enum naming"
#    "function naming"
    "header file not self-contained"
#    "implicit bool cast"
    "include style"
    "inconsistent declaration parameter name"
    "license header"
    "naked delete"
    "naked new"
#    "old style function"
    "old-style null pointer"
#    "possible forward declaration"
    "undefined function"
    "uninitialized field"
#    "uninitialized local variable"
    "unused forward declaration"
#    "variable naming"
    "whitespace"
)

echo "Checking rule stability (without CBOT)"
for ((i = 0; i < ${#STABLE_RULES_WITHOUT_CBOT[@]}; i++)); do
    rule="${STABLE_RULES_WITHOUT_CBOT[$i]}"
    count="$("$COLOBOT_LINT_DIR/Tools/count_errors.py" --rule-filter="$rule" --file-filter="-.*CBot.*" --xml-report-file "$COLOBOT_LINT_REPORT_FILE")"
    if [ "$count" != "0" ]; then
       echo "UNSTABLE RULE: $rule (without CBOT, $count occurences)"
       ret=1
    fi
done

exit $ret
                        ''', returnStatus: true
                        if (retcode != 0) {
                            currentBuild.result = 'UNSTABLE'
                        }
                    }
                }

                publishCppcheck pattern: 'build/lint/colobot_lint_report.xml'
                publishHTML([reportName: 'Colobot-lint HTML report', reportDir: 'build/lint/html_report', reportFiles: 'index.html', reportTitles: '', allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true])
            }
        }
    }
}