-
Notifications
You must be signed in to change notification settings - Fork 87
/
.pipeline
152 lines (139 loc) · 5.68 KB
/
.pipeline
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
def imgname = 'hubblestack/jenkins:centos-v1.0.17'
pipeline {
agent {
docker {
image "${imgname}"
}
}
options {
timestamps()
ansiColor 'xterm'
buildDiscarder(logRotator(numToKeepStr: '2', artifactNumToKeepStr: '1'))
}
environment {
PY_COLORS = 1
HS_PROFILE = 1
TEST_PY_V = '3.7.9'
OUTPUT = 'tests/unittests/output'
REF = 'tests/unittests/output/relevant-files.txt'
SKIP_0_POOL_NTP_TEST = 1
}
stages {
stage('setup') {
steps {
sh '''#!/bin/bash
echo "---=: CLEAN UP WORKSPACE :=---"
git clean -dfx -e .pip-cache
mkdir -vp $OUTPUT
'''
sh '''#!/bin/bash
echo "---=: RELEVANT-FILES.TXT :=---"
echo "CHANGE_TARGET=$CHANGE_TARGET BRANCH_NAME=$BRANCH_NAME"
LHS='' RHS=''
if [ -n "$CHANGE_TARGET" ]; then
if tmp=$(git rev-parse origin/$CHANGE_TARGET 2>/dev/null)
then LHS=$tmp
else LHS=$CHANGE_TARGET
fi
fi
if [ -n "$BRANCH_NAME" ]; then
if tmp=$(git rev-parse origin/$BRANCH_NAME 2>/dev/null)
then RHS=$tmp
else RHS=$BRANCH_NAME
fi
fi
if [ -z "$LHS" ]; then
git log --decorate --pretty=%H%d --simplify-by-decoration > git-log.txt
tail -n +2 git-log.txt | head -n 1 > nearest-ancestor.txt
echo "nearest ancestor seems to be $(<nearest-ancestor.txt)"
LHS=$(cut -d' ' -f1 < nearest-ancestor.txt)
echo "using nearest ancestor for LHS (because it was empty)"
fi
if [ -z "$RHS" ]; then
echo "using HEAD for RHS (because it was empty)"
RHS=HEAD
fi
echo "computed git diff LHS: $LHS"
echo "computed git diff RHS: $RHS"
if [ -n "$LHS" -a -n "$RHS" ]
then find hubblestack -name "*.py" -print0 \\
| xargs -r0 git diff --name-only "$LHS" "$RHS" > $REF
head -v $REF
else cat /dev/null > $REF
echo "*** NULL $REF ***"
fi
'''
sh '''#!/bin/bash
echo "---=: CONFIGURE TEST ENVIRONMENT :=---"
source /etc/profile.d/kersplat.sh
export PY_V="$TEST_PY_V"
pyenv local $TEST_PY_V
pyenv shell $TEST_PY_V
echo "pyenv version-name: $(pyenv version-name)"
set -e
pip install --cache-dir .pip-cache -t ./vlib virtualenv
PYTHONPATH=./vlib ./vlib/bin/virtualenv ./venv
source ./venv/bin/activate
echo no | ./mk-requires.sh
pip install --cache-dir .pip-cache -U -r requirements.txt
pip install --cache-dir .pip-cache -U -r tests/automation/requirements.txt
pip uninstall -y salt-ssh
python -c "
import sys
try:
import salt
print('ERROR, SALT IS FOUND, ERROR')
sys.exit(1)
except:
pass
"
'''
}
}
stage('lint/test') {
parallel {
stage('pytest') {
steps {
sh '''#!/bin/bash
source ./venv/bin/activate
pytest -v tests/unittests --html=tests/unittests/output/pytest.html
x=$?
cp tests/unittests/output/combined.svg tests/unittests/output/profile-diagram.svg
exit $x
'''
}
}
stage('pylint') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''#!/bin/bash
source ./venv/bin/activate
if [ -s $REF ]
then xargs -r pylint --output-format=json < $REF > $OUTPUT/pylint.json; x=$?
echo "Wrote $(wc -l < $OUTPUT/pylint.json) line(s) to $OUTPUT/pylint.json with exit($x)"
else echo SKIPPING PYLINT "$REF is empty"; x=0
fi
test -s $OUTPUT/pylint.json || echo '[]' > $OUTPUT/pylint.json
python ./tests/automation/pylint-json-to-html $OUTPUT/pylint.json
echo "Wrote $(wc -l < $OUTPUT/pylint.html) line(s) to $OUTPUT/pylint.html (see test reports)"
exit $x
'''
}
}
}
}
}
}
post {
always {
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'tests/unittests/output',
reportFiles: 'pytest.html, coverage/index.html, pylint.html, profile-diagram.svg, relevant-files.txt',
reportName: "Test Reports"
])
}
}
}