forked from ckeditor/ckeditor5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontinuous-integration-script.js
More file actions
169 lines (127 loc) · 5.62 KB
/
Copy pathcontinuous-integration-script.js
File metadata and controls
169 lines (127 loc) · 5.62 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
#!/usr/bin/env node
/**
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/* eslint-env node */
'use strict';
const childProcess = require( 'child_process' );
const crypto = require( 'crypto' );
const fs = require( 'fs' );
const path = require( 'path' );
const glob = require( 'glob' );
const failedChecks = {
dependency: new Set(),
unitTests: new Set(),
codeCoverage: new Set()
};
const RED = '\x1B[0;31m';
const YELLOW = '\x1B[33;1m';
const NO_COLOR = '\x1B[0m';
const travis = {
_lastTimerId: null,
_lastStartTime: null,
foldStart( packageName, foldLabel ) {
console.log( `travis_fold:start:${ packageName }${ YELLOW }${ foldLabel }${ NO_COLOR }` );
this._timeStart();
},
foldEnd( packageName ) {
this._timeFinish();
console.log( `\ntravis_fold:end:${ packageName }\n` );
},
_timeStart() {
const nanoSeconds = process.hrtime.bigint();
this._lastTimerId = crypto.createHash( 'md5' ).update( nanoSeconds.toString() ).digest( 'hex' );
this._lastStartTime = nanoSeconds;
// Intentional direct write to stdout, to manually control EOL.
process.stdout.write( `travis_time:start:${ this._lastTimerId }\r\n` );
},
_timeFinish() {
const travisEndTime = process.hrtime.bigint();
const duration = travisEndTime - this._lastStartTime;
// Intentional direct write to stdout, to manually control EOL.
process.stdout.write( `\ntravis_time:end:${ this._lastTimerId }:start=${ this._lastStartTime },` +
`finish=${ travisEndTime },duration=${ duration }\r\n` );
}
};
childProcess.execSync( 'rm -r -f .nyc_output' );
childProcess.execSync( 'mkdir .nyc_output' );
childProcess.execSync( 'rm -r -f .out' );
childProcess.execSync( 'mkdir .out' );
const packages = childProcess.execSync( 'ls packages -1', {
encoding: 'utf8'
} ).toString().trim().split( '\n' );
for ( const fullPackageName of packages ) {
const simplePackageName = fullPackageName.replace( /^ckeditor5?-/, '' );
const foldLabelName = 'pkg-' + simplePackageName;
travis.foldStart( foldLabelName, `Testing ${ fullPackageName }${ NO_COLOR }` );
appendCoverageReport();
runSubprocess( 'npx', [ 'ckeditor5-dev-tests-check-dependencies', `packages/${ fullPackageName }` ], simplePackageName, 'dependency',
'have a dependency problem' );
const testArguments = [ 'run', 'test', '-f', simplePackageName, '--reporter=dots', '--production', '--coverage' ];
runSubprocess( 'yarn', testArguments, simplePackageName, 'unitTests', 'failed to pass unit tests' );
childProcess.execSync( 'cp coverage/*/coverage-final.json .nyc_output' );
const nyc = [ 'nyc', 'check-coverage', '--branches', '100', '--functions', '100', '--lines', '100', '--statements', '100' ];
runSubprocess( 'npx', nyc, simplePackageName, 'codeCoverage', 'doesn\'t have required code coverage' );
travis.foldEnd( foldLabelName );
}
console.log( 'Uploading combined code coverage report…' );
if ( shouldUploadCoverageReport() ) {
childProcess.execSync( 'npx coveralls < .out/combined_lcov.info' );
} else {
console.log( 'Since the PR comes from the community, we do not upload code coverage report.' );
console.log( 'Read more why: https://github.com/ckeditor/ckeditor5/issues/7745.' );
}
console.log( 'Done' );
if ( Object.values( failedChecks ).some( checksSet => checksSet.size > 0 ) ) {
console.log( '\n---\n' );
console.log( `🔥 ${ RED }Errors were detected by the CI.${ NO_COLOR }\n\n` );
showFailedCheck( 'dependency', 'The following packages have dependencies that are not included in its package.json' );
showFailedCheck( 'unitTests', 'The following packages did not pass unit tests' );
showFailedCheck( 'codeCoverage', 'The following packages did not provide required code coverage' );
console.log( '\n---\n' );
process.exit( 1 ); // Exit code 1 will break the CI build.
}
/*
* @param {String} binaryName - Name of a CLI binary to be called.
* @param {String[]} cliArguments - An array of arguments to be passed to the `binaryName`.
* @param {String} packageName - Checked package name.
* @param {String} checkName - A key associated with the problem in the `failedChecks` dictionary.
* @param {String} failMessage - Message to be shown if check failed.
*/
function runSubprocess( binaryName, cliArguments, packageName, checkName, failMessage ) {
const subprocess = childProcess.spawnSync( binaryName, cliArguments, {
encoding: 'utf8',
shell: true
} );
console.log( subprocess.stdout );
if ( subprocess.stderr ) {
console.log( subprocess.stderr );
}
if ( subprocess.status !== 0 ) {
failedChecks[ checkName ].add( packageName );
console.log( `💥 ${ RED }${ packageName }${ NO_COLOR } ` + failMessage + ' 💥' );
}
}
function showFailedCheck( checkKey, errorMessage ) {
const failedPackages = failedChecks[ checkKey ];
if ( failedPackages.size ) {
console.log( `${ errorMessage }: ${ RED }${ Array.from( failedPackages.values() ).join( ', ' ) }${ NO_COLOR }` );
}
}
function appendCoverageReport() {
// Appends coverage data to the combined code coverage info file. It's used because all the results
// needs to be uploaded at once (#6742).
const matches = glob.sync( 'coverage/*/lcov.info' );
matches.forEach( filePath => {
const buffer = fs.readFileSync( filePath );
fs.writeFileSync( [ '.out', 'combined_lcov.info' ].join( path.sep ), buffer, {
flag: 'as'
} );
} );
}
function shouldUploadCoverageReport() {
// If the repository slugs are different, the pull request comes from the community (forked repository).
// For such builds, sending the CC report will be disabled.
return ( process.env.TRAVIS_EVENT_TYPE !== 'pull_request' || process.env.TRAVIS_PULL_REQUEST_SLUG === process.env.TRAVIS_REPO_SLUG );
}