-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
83 lines (82 loc) · 3.71 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
pipeline {
agent {
label 'docker'
}
stages {
stage('Generate CSV-W') {
agent {
docker {
image 'gsscogs/databaker'
reuseNode true
alwaysPull true
}
}
steps {
script {
def pipelineInfo = readJSON(text: readFile(file: 'datasets/info.json'))
String [] testPipelines = pipelineInfo['pipelines']
if (pipelineInfo.containsKey('tests') && pipelineInfo['tests'].containsKey('skip')) {
testPipelines = testPipelines.minus(pipelineInfo['tests']['skip'])
}
for (String pipeline : testPipelines) {
dir("datasets/${pipeline}") {
def inFiles = findFiles(glob: '*.py') +
findFiles(glob: 'codelists/*') +
findFiles(glob: 'info.json')
def outFiles = findFiles(glob: 'out/*')
def newestIn = inFiles.max { it.lastModified }
def oldestOut = outFiles.min { it.lastModified }
if (oldestOut == null || (newestIn.lastModified > oldestOut.lastModified)) {
sh "rm -rf out"
warnError("Transform error for ${pipeline}.") {
sh "jupytext --to notebook --use-source-timestamp '*.py'"
sh "jupyter-nbconvert --to html --output-dir='out' --ExecutePreprocessor.timeout=None --execute 'main.ipynb'"
}
}
}
}
}
}
}
stage('Validate CSV-W') {
agent {
docker {
image 'gsscogs/csvlint'
reuseNode true
alwaysPull true
}
}
steps {
script {
def pipelineInfo = readJSON(text: readFile(file: 'datasets/info.json'))
String [] testPipelines = pipelineInfo['pipelines']
if (pipelineInfo.containsKey('tests') && pipelineInfo['tests'].containsKey('skip')) {
testPipelines = testPipelines.minus(pipelineInfo['tests']['skip'])
}
for (String pipeline : testPipelines) {
dir("datasets/${pipeline}") {
sh "mkdir -p reports"
def schemas = findFiles(glob: 'out/*-metadata.json')
def results = findFiles(glob: 'reports/*-report.txt')
def newestIn = schemas.max { it.lastModified }
def oldestOut = results.min { it.lastModified }
if (oldestOut == null || (newestIn.lastModified > oldestOut.lastModified)) {
for (String schema : schemas) {
String baseName = schema.name.substring(0, schema.name.lastIndexOf('-metadata.json'))
sh(returnStatus: true, script: "csvlint --format junit --no-verbose -s ${schema} > reports/${baseName}-report.xml")
}
}
}
}
}
}
}
}
post {
always {
script {
junit allowEmptyResults: true, testResults: 'datasets/*/reports/*-report.xml'
}
}
}
}