-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcoverage.Jenkinsfile
More file actions
174 lines (155 loc) · 5.84 KB
/
coverage.Jenkinsfile
File metadata and controls
174 lines (155 loc) · 5.84 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
@Library('ontotext-platform@v0.1.49') _
pipeline {
agent {
label 'aws-large'
}
tools {
nodejs 'nodejs-22'
}
environment {
DOCKER_COMPOSE_FILE = 'docker-compose-coverage.yaml'
}
parameters {
gitParameter name: 'GIT_BRANCH',
description: 'The Git branch to test',
branchFilter: 'origin/(.*)',
defaultValue: 'master',
selectedValue: 'DEFAULT',
type: 'PT_BRANCH',
listSize: '0',
quickFilterEnabled: true
}
options {
disableConcurrentBuilds()
timestamps()
}
stages {
stage('Install And Stash') {
steps {
script {
git_cmd.checkout(branch: params.GIT_BRANCH)
sh 'npm run install:ci'
stash name: 'workspace', includes: '**/*', useDefaultExcludes: false
}
}
}
stage('Unit Test Coverage') {
steps {
script {
restoreWorkspace()
sh 'npm run test:coverage'
archiveArtifacts allowEmptyArchive: true, artifacts: 'packages/api/coverage/**, packages/root-config/coverage/**, packages/shared-components/coverage/**'
}
}
}
// =====================================================================================
// Code Coverage Instrumentation Workaround
//
// The following three stages ('Instrument', 'Build', 'Restore source code') are a
// necessary workaround to generate accurate code coverage reports for our single-spa
// application.
//
// **Problem:** The standard "in-memory" instrumentation during the Webpack build causes
// issues for `nyc` (the reporting tool). `nyc` struggles to map the coverage data
// from the final, single bundled JS file back to the original source files.
//
// **Solution:** We use a more explicit, physical approach:
// 1. **Instrument:** Modify the source files on disk before the build.
// 2. **Build:** Create the distributable (`dist/`) from the pre-instrumented code.
// 3. **Restore:** Reset the workspace to its original state, leaving clean source
// code for `nyc` to use when generating the final HTML report.
//
// This ensures that `nyc` can always find a matching source file for the data
// collected by Cypress, guaranteeing a correct report.
// =====================================================================================
stage('Instrument') {
steps {
script {
restoreWorkspace()
sh 'npm run instrument:legacy-workbench'
}
}
}
stage('Build') {
steps {
script {
sh 'npm run build'
}
}
}
stage ('Restore source code') {
steps {
script {
echo "Stashing dist/ into Jenkins..."
stash name: 'dist-artifacts', includes: 'dist/**', allowEmpty: true
echo "Hard reset of ${params.GIT_BRANCH}..."
sh "git reset --hard ${params.GIT_BRANCH}"
echo "Unstash dist/ onto workspace..."
unstash 'dist-artifacts'
}
}
}
stage('Workbench Cypress Test With Coverage') {
steps {
script {
withKsm(application: [[
credentialsId: 'ksm-jenkins',
secrets: [
[
destination: 'file',
filePath: 'graphdb.license',
notation: 'keeper://AByA4tIDmeN7RmqnQYGY0A/file/graphdb.license'
]
]
]]) {
sh 'cp graphdb.license ./e2e-tests/fixtures/'
sh "ls -lh ./e2e-tests/fixtures/"
dockerCompose.buildCmd(
composeFile: env.DOCKER_COMPOSE_FILE,
options: ["--force-rm"]
)
def caughtError = false
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
dockerCompose.upCmd(
composeFile: env.DOCKER_COMPOSE_FILE,
options: ["--abort-on-container-exit", "--exit-code-from cypress"]
)
}
echo "Tests passed — archiving coverage artifacts."
archiveArtifacts allowEmptyArchive: true, artifacts: 'e2e-tests/coverage/**'
dockerCompose.downCmd(
composeFile: env.DOCKER_COMPOSE_FILE,
options: ['--volumes', '--remove-orphans', '--rmi', 'local'],
ignoreErrors: true
)
}
}
}
}
}
post {
success {
script {
workspaceCleanup()
}
}
failure {
wrap([$class: 'BuildUser']) {
sendMail(env.BUILD_USER_EMAIL)
}
script {
workspaceCleanup()
}
}
}
}
def workspaceCleanup() {
configFileProvider([configFile(fileId: 'cleanup-script', variable: 'CLEANUP_SCRIPT')]) {
def scriptContent = readFile(env.CLEANUP_SCRIPT)
evaluate(scriptContent)
}
}
def restoreWorkspace() {
cleanWs()
unstash 'workspace'
}