-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
203 lines (187 loc) · 7.7 KB
/
Jenkinsfile
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
pipeline {
agent {
dockerfile {
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
reuseNode true
}
}
stages {
stage('Clean') {
steps {
script {
// Clean up any unwanted files lying about after the previous build.
sh "git clean -fxd --exclude='.venv'"
}
}
}
stage('Pyright') {
when { not { buildingTag() } }
steps {
sh 'poetry run pyright . --lib'
}
}
stage('Test') {
when { not { buildingTag() } }
steps {
script {
try {
sh 'poetry run behave tests/behaviour --tags=-skip -f json.cucumber -o tests/behaviour/test-results.json'
dir('tests/unit') {
sh "poetry run pytest --junitxml=pytest_results_csvcubed.xml"
}
} catch (ex) {
echo "An error occurred when testing: ${ex}"
stash name: 'test-results', includes: '**/test-results.json,**/*results*.xml' // Ensure test reports are available to be reported on.
throw ex
}
stash name: 'test-results', includes: '**/test-results.json,**/*results*.xml' // Ensure test reports are available to be reported on.
}
}
}
stage('Tox') {
when {
buildingTag()
tag pattern: "v\\d+\\.\\d+\\.\\d+(-RC\\d)?", comparator: "REGEXP"
}
agent {
docker { image 'gsscogs/pythonversiontesting' }
}
steps {
script {
try {
sh 'tox'
} catch (ex) {
echo "An error occurred testing with tox: ${ex}"
stash name: 'tox-test-results', includes: '**/tox-test-results-*.json,**/*results*.xml'
throw ex
}
// Ensure test reports are available to be reported on.
stash name: 'tox-test-results', includes: '**/tox-test-results-*.json,**/*results*.xml'
}
}
}
stage('Set dev version') {
when {
branch 'main'
}
steps {
// This runs when we're not building a release or release candidate
// It sets the version of the project to something containing the decimalised version of the
// git commit id so that the package can be automatically deployed to testpypi.
sh 'revision="$(git rev-parse HEAD | tr \'[:lower:]\' \'[:upper:]\')"; decimal_rev=$(echo "obase=10; ibase=16; $revision" | bc); poetry version "0.1.0-dev$decimal_rev"'
}
}
stage('Package') {
steps {
sh 'poetry build'
stash name: 'wheels', includes: '**/dist/*.whl'
}
}
stage('Building Documentation') {
steps {
script {
dir('external-docs'){
sh "python3 -m mkdocs build"
}
stash name: 'mkdocs', includes: '**/external-docs/site/**/*'
}
}
}
stage('Publishing Documentation'){
when {
branch 'main'
}
steps{
script{
try {
withCredentials([gitUsernamePassword(credentialsId: 'csvcubed-github', gitToolName: 'git-tool')]){
sh 'git clone "https://github.com/GSS-Cogs/csvcubed-docs.git"'
dir ('csvcubed-docs') {
sh 'git config --global user.email "[email protected]" && git config --global user.name "csvcubed"'
if (fileExists("external")) {
sh 'git rm -rf external'
}
sh 'mkdir external'
sh 'cp -r ../external-docs/site/* external'
if (fileExists("api-docs")) {
sh 'git rm -rf api-docs'
}
sh 'touch .nojekyll'
sh 'git add *'
sh 'git add .nojekyll'
sh 'git commit -m "Updating documentation."'
// commit being built in csvcubed repo: https://github.com/GSS-Cogs/csvcubed
sh 'git checkout gh-pages'
sh 'git reset --hard main'
sh 'git push -f'
}
}
} finally {
sh 'rm -rf csvcubed-docs'
}
}
}
}
stage('Publish to Test-pypi') {
when {
branch 'main'
}
steps {
script {
sh "twine check dist/csvcubed*.whl"
withCredentials([usernamePassword(credentialsId: 'testpypi-robons', usernameVariable:'TWINE_USERNAME', passwordVariable: 'TWINE_PASSWORD')]) {
sh 'twine upload -r testpypi dist/csvcubed*.whl'
}
}
}
}
stage('Publish to Pypi') {
when {
buildingTag()
tag pattern: "v\\d+\\.\\d+\\.\\d+(-RC\\d)?", comparator: "REGEXP"
}
steps {
script {
sh "twine check dist/csvcubed*.whl"
withCredentials([usernamePassword(credentialsId: 'pypi-robons', usernameVariable:'TWINE_USERNAME', passwordVariable: 'TWINE_PASSWORD')]) {
sh 'twine upload dist/csvcubed*.whl'
}
}
}
}
}
post {
always {
script {
try {
unstash name: 'test-results'
} catch (Exception e) {
echo 'test-results stash does not exist'
}
try {
unstash name: 'tox-test-results'
} catch (Exception e) {
echo 'tox-test-results stash does not exist'
}
cucumber fileIncludePattern: '**/test-results.json'
cucumber fileIncludePattern: '**/tox-test-results-*.json'
junit allowEmptyResults: true, testResults: '**/*results*.xml'
try {
unstash name: 'wheels'
} catch (Exception e) {
echo 'wheels stash does not exist'
}
try {
unstash name: 'mkdocs'
} catch (Exception e) {
echo 'mkdocs stash does not exist'
}
archiveArtifacts artifacts: '**/dist/*.whl, **/docs/_build/html/**/*, **/external-docs/site/**/*, **/test-results.json, **/tox-test-results-*.json, **/*results*.xml', fingerprint: true
// Set more permissive permissions on all files so future processes/Jenkins can easily delete them.
sh 'chmod -R ugo+rw .'
// Clean up any unwanted files lying about.
sh "git clean -fxd --exclude='.venv'"
}
}
}
}