Skip to content

Commit 98bf56e

Browse files
authored
Merge pull request #7 from cortex-lab/dev
Version 2.0 - Switch to Serveo
2 parents 58ace8b + 56b44e0 commit 98bf56e

File tree

5 files changed

+207
-80
lines changed

5 files changed

+207
-80
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
## [Latest](https://github.com/cortex-lab/matlab-ci/commits/master)
4+
5+
### Added
6+
7+
- changelog
8+
- status and coverage endpoints for shields
9+
10+
### Modified
11+
12+
- changed from using Smee client to Serveo for exposing ZTEST
13+
- fixes for test reports endpoint
14+
- tests now performed only on head commit

README.md

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Run the install script to install all dependencies, then create your .env file c
88

99
### Prerequisites
1010

11-
Requires MATLAB 2017a or later and Node.js. The following Node.js modules are required:
11+
Requires MATLAB 2017a or later, Node.js and Git Bash. The following Node.js modules are required:
1212

1313
```
1414
npm install --save express dotenv @octokit/app @octokit/request ...
15-
github-webhook-handler smee-client xml2js
15+
github-webhook-handler xml2js
1616
```
1717

1818
### Installing
@@ -23,22 +23,6 @@ Make sure runAllTests.m is on your MATLAB paths
2323

2424
TODO
2525

26-
### Break down into end to end tests
27-
28-
Explain what these tests test and why
29-
30-
```
31-
Give an example
32-
```
33-
34-
### And coding style tests
35-
36-
Explain what these tests test and why
37-
38-
```
39-
Give an example
40-
```
41-
4226
## Deployment
4327

4428
To work properly you need to create install a Github app on your target repository and download the private key. Update your .env file like so:
@@ -47,9 +31,8 @@ To work properly you need to create install a Github app on your target reposito
4731
GITHUB_PRIVATE_KEY=path\to\private-key.pem
4832
GITHUB_APP_IDENTIFIER=1234
4933
GITHUB_WEBHOOK_SECRET=
50-
WEBHOOK_PROXY_URL=https://smee.io/abcd
34+
WEBHOOK_PROXY_URL=
5135
RIGBOX_REPO_PATH=C:\Path\To\Code\Repo
52-
COVERALLS_TOKEN=
5336
```
5437

5538
To run at startup create a batch file with the following command:
@@ -62,7 +45,8 @@ Create a shortcut in your startup folder ([Windows-logo] + [R] in Windows-10 and
6245

6346
## Built With
6447

65-
* [Coveralls](coveralls.io) - Code coverage
48+
* [Serveo](serveo.net) - SSH tunneling service
49+
* [Shields.io](shields.io) - Display shields
6650

6751
## Contributing
6852

coverage.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var fs = require('fs'),
2323
crypto = require('crypto'),
2424
assert = require('assert').strict,
2525
parser = new xml2js.Parser(),
26-
timestamp, md5;
26+
timestamp, md5, cb;
2727
var timestamp;
2828
var token = process.env.COVERALLS_TOKEN;
2929

@@ -33,7 +33,9 @@ var token = process.env.COVERALLS_TOKEN;
3333
* @param {Array} classList - An array of class objects from the loaded XML file.
3434
* @param {String} path - The root path of the code repository.
3535
* @param {String} sha - The commit SHA for this coverage test.
36-
* @returns {Object} Object containing array of source code files and their code coverage
36+
* @param {function} callback - The callback function to run when complete. Takes object containing array of source
37+
* code files and their code coverage
38+
* @returns {Object}
3739
* @todo Generalize path default
3840
*/
3941
const formatCoverage = function(classList, path, sha) {
@@ -63,20 +65,22 @@ const formatCoverage = function(classList, path, sha) {
6365
job.source_files = sourceFiles;
6466
job.commit_sha = sha;
6567
job.run_at = timestamp; // "2013-02-18 00:52:48 -0800"
66-
return job;
68+
cb(job);
6769
}
6870

6971
/**
7072
* Loads a code coverage XML file in Cobertura Format and returns payload object for Coveralls API
7173
* @see {@link https://docs.coveralls.io/api-reference|Coveralls API docs}
7274
* @param {String} path - Path to the XML file containing coverage information.
7375
* @param {String} sha - The commit SHA for this coverage test
74-
* @returns {Object} Object containing array of source code files and their code coverage
76+
* @param {String} repo - The repo to which the commit belongs
77+
* @param {function} callback - The callback function to run when complete
7578
* @todo Remove assert
7679
* @todo Generalize ignoring of submodules
7780
* @see {@link https://github.com/cobertura/cobertura/wiki|Cobertura Wiki}
7881
*/
79-
const coverage = function(path, sha) {
82+
const coverage = function(path, repo, sha, callback) {
83+
cb = callback; // @fixme Making callback global feels hacky
8084
fs.readFile(path, function(err, data) { // Read in XML file
8185
parser.parseString(data, function (err, result) { // Parse XML
8286
const rigboxPath = result.coverage.sources[0].source[0]; // Extract root code path
@@ -87,25 +91,20 @@ const coverage = function(path, sha) {
8791
const packages = result.coverage.packages[0].package;
8892
packages.forEach(package => { classes.push(package.classes[0].class) }); // Get all classes
8993
classes = classes.reduce((acc, val) => acc.concat(val), []); // Flatten
90-
//console.log(classes.length);
9194

9295
// The submodules
93-
var alyx_matlab = [];
94-
var signals = [];
95-
var npy_matlab = [];
96-
var wheelAnalysis = [];
96+
var modules = {'rigbox' : [], 'alyx-matlab' : [], 'signals' : [], 'npy-matlab' : [], 'wheelAnalysis' : []};
9797
// Sort into piles
98-
classes = classes.filter(function (e) {
98+
modules['rigbox'] = classes.filter(function (e) {
9999
if (e.$.filename.search(/(tests\\|_.*test|docs\\)/i) != -1) {return false;} // Filter out tests and docs
100100
if (!Array.isArray(e.lines[0].line)) {return false;} // Filter out files with no functional lines
101-
if (e.$.filename.startsWith('alyx-matlab\\')) {alyx_matlab.push(e); return false;}
102-
if (e.$.filename.startsWith('signals\\')) {signals.push(e); return false;}
103-
if (e.$.filename.startsWith('npy-matlab\\')) {npy_matlab.push(e); return false;}
104-
if (e.$.filename.startsWith('wheelAnalysis\\')) {wheelAnalysis.push(e); return false;}
101+
if (e.$.filename.startsWith('alyx-matlab\\')) {modules['alyx-matlab'].push(e); return false;}
102+
if (e.$.filename.startsWith('signals\\')) {modules.signals.push(e); return false;}
103+
if (e.$.filename.startsWith('npy-matlab\\')) {modules['npy-matlab'].push(e); return false;}
104+
if (e.$.filename.startsWith('wheelAnalysis\\')) {modules.wheelAnalysis.push(e); return false;}
105105
else {return true};
106106
});
107-
//console.log(obj.source_files[0].coverage.length);
108-
return obj = formatCoverage(classes, rigboxPath);
107+
formatCoverage(modules[repo.toLowerCase()], rigboxPath, callback);
109108
});
110109
});
111110
};
@@ -115,7 +114,7 @@ const coverage = function(path, sha) {
115114
* @param {String} path - Path to the source code file.
116115
* @returns {Object} key `Hash` contains MD5 digest string of file; `count` contains number of lines in source file
117116
*/
118-
const md5 = function(path) {
117+
md5 = function(path) {
119118
var hash = crypto.createHash('md5'); // Creating hash object
120119
var buf = fs.readFileSync(path, 'utf-8'); // Read in file
121120
var count = buf.split(/\r\n|\r|\n/).length; // Count the number of lines

0 commit comments

Comments
 (0)