-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile-lib
More file actions
199 lines (178 loc) · 6.72 KB
/
Jenkinsfile-lib
File metadata and controls
199 lines (178 loc) · 6.72 KB
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
pipeline {
agent any
environment {
PYTHON_VERSION = '3.11'
}
stages {
stage('Setup Python Environment') {
steps {
script {
sh '''
pip install build wheel
'''
// Ensure Python 3.11 is available, fail if not
sh '''
if ! command -v python3.11 &> /dev/null; then
echo "Error: Python 3.11 is not installed or not in PATH."
exit 1
fi
'''
// Get the actual Python 3.11 binary path and check version in dynaface-lib
sh '''
PYTHON_PATH=$(command -v python3.11)
echo "Using Python at: $PYTHON_PATH"
cd dynaface-lib
$PYTHON_PATH --version
'''
}
}
}
stage('Install Dependencies') {
steps {
script {
// Change to dynaface-lib and install your package along with testing dependencies
sh '''
cd dynaface-lib
pip install -e .
pip install --upgrade setuptools
pip install pytest pytest-cov
'''
}
}
}
stage('Static Code Analysis') {
steps {
sh '''
cd dynaface-lib
pip install flake8 mypy bandit black isort
echo "Running flake8..."
flake8 dynaface --config $WORKSPACE/.flake8 --output-file=flake8-report.txt || true
echo "Running mypy..."
mypy --install-types --non-interactive || true
mypy dynaface --show-error-codes --no-color-output --no-error-summary > mypy-report.txt || true
echo "Running bandit..."
bandit -r dynaface -f txt -o bandit-report.txt || true
echo "Checking formatting with black..."
black --check dynaface > black-report.txt 2>&1 || true
echo "Checking imports with isort..."
isort dynaface --check-only > isort-report.txt || true
'''
}
post {
always {
archiveArtifacts artifacts: 'dynaface-lib/*.txt', allowEmptyArchive: true
}
}
}
stage('Run Tests & Generate Coverage') {
steps {
script {
sh '''
cd dynaface-lib
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
python3.11 -m pytest tests \
--junitxml=unit_test_results.xml \
--cov=. \
--cov-report=xml:coverage.xml \
--cov-report=html
'''
}
}
}
stage('Generate Version File') {
steps {
script {
sh '''
cd dynaface-lib
VERSION=$(python3.11 -c "import configparser; c = configparser.ConfigParser(); c.read('setup.cfg'); print(c['metadata']['version'])")
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%S%z")
BUILD="$BUILD_NUMBER"
cat <<EOF > dynaface/version.py
VERSION = "$VERSION"
BUILD_DATE = "$BUILD_DATE"
BUILD = $BUILD
EOF
echo "Generated dynaface/version.py:"
cat dynaface/version.py
'''
}
}
}
stage('Build Package') {
steps {
script {
// Build the package with setuptools via the build module
sh '''
cd dynaface-lib
echo "Cleaning up old .whl files..."
rm -rf dist/* # Deletes old .whl files before building
python3.11 -m build --wheel
'''
}
}
}
stage('Validate Package with Twine') {
steps {
sh '''
cd dynaface-lib
pip install --upgrade twine
twine check dist/*
'''
}
}
stage('Archive Artifacts') {
steps {
script {
// Ensure the necessary paths exist before archiving
sh '''
cd dynaface-lib
mkdir -p dist # Ensure dist exists
'''
archiveArtifacts artifacts: 'dynaface-lib/dist/*.whl', fingerprint: true
archiveArtifacts artifacts: 'dynaface-lib/coverage.xml',
allowEmptyArchive: true // Archive coverage XML
archiveArtifacts artifacts: 'dynaface-lib/htmlcov/**',
allowEmptyArchive: true // Archive HTML coverage
}
}
}
stage('Upload to S3') {
steps {
script {
sh '''
AWS_BUCKET_NAME="data.heatonresearch.com"
AWS_BUCKET_PATH="library/"
echo "Uploading built package to S3 at s3://$AWS_BUCKET_NAME/$AWS_BUCKET_PATH..."
cd dynaface-lib/dist
aws s3 cp *.whl s3://$AWS_BUCKET_NAME/$AWS_BUCKET_PATH --acl public-read
'''
}
}
}
}
post {
always {
script {
// Clean up build artifacts
sh '''
cd dynaface-lib
rm -rf build dist dynaface.egg-info
'''
}
// Archive test and coverage results
junit 'dynaface-lib/unit_test_results.xml'
recordCoverage(
tools: [[parser: 'COBERTURA', pattern: 'dynaface-lib/coverage.xml']],
id: 'pytest-coverage',
name: 'Pytest Coverage',
sourceCodeRetention: 'EVERY_BUILD',
qualityGates: [
[threshold: 60.0, metric: 'LINE', baseline: 'PROJECT', unstable: true],
[threshold: 60.0, metric: 'BRANCH', baseline: 'PROJECT', unstable: true]
]
)
}
}
}