Skip to content

Commit a19038d

Browse files
authored
Merge pull request #47 from cortex-lab/py_ci
Python CI
2 parents 04c91f7 + 63d63e6 commit a19038d

31 files changed

+63411
-690
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.idea/*
22
.DS_Store
33
node_modules/*
4+
.env
5+
.pem

.travis.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: node_js
2+
node_js: 12
3+
env:
4+
- NODE_ENV=test
5+
branches:
6+
only:
7+
- master
8+
jobs:
9+
include:
10+
- name: "windows"
11+
os: windows
12+
env: NODE_ENV=test DOTENV_CONFIG_PATH=.\\test\\fixtures\\.env.test
13+
- name: "linux"
14+
os: linux
15+
env: NODE_ENV=test DOTENV_CONFIG_PATH=./test/fixtures/.env.test

CHANGELOG.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
# Changelog
22

3-
## [Latest](https://github.com/cortex-lab/matlab-ci/commits/master) [1.2.0]
3+
## [Latest](https://github.com/cortex-lab/matlab-ci/commits/master) [2.0.0]
4+
### Added
5+
6+
- there are now three major modules: lib, serve and main
7+
- lots and lots of new tests
8+
- support for running any tests: now CI calls a custom shell script
9+
- new settings file and config module to validate settings
10+
- branch pass list option in settings
11+
- force flag for badge API
12+
- function for converting string to bool in robust way
13+
- function for saving test records
414

15+
16+
### Modified
17+
18+
- complete rewrite of code
19+
- index.js renamed to main.js
20+
- preparing the environment may be optional
21+
- errors during test function are now saved into test record db
22+
- new config options (see readme)
23+
- kill child processes in job timer
24+
25+
26+
## [1.2.0]
527
### Modified
628

729
- test log formatted in html
@@ -23,11 +45,7 @@
2345
- suppress warnings about shadowing builtins in runAllTests
2446
- run tests in subfolders
2547
- filter out performance tests
26-
<<<<<<< HEAD
27-
- skip tests for commits to branches named 'documentation'
28-
=======
2948
- skip checks for commits to branches named 'documentation'
30-
>>>>>>> master
3149

3250
## [1.0.0]
3351
### Added

README.md

+55-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,73 @@
11
# MATLAB-ci
2+
[![Build Status](https://travis-ci.com/cortex-lab/matlab-ci.svg?branch=master)](https://travis-ci.com/cortex-lab/matlab-ci)
23

34
A small set of modules written in Node.js for running automated tests of MATLAB code in response to GitHub events. Also submits code coverage to the Coveralls API.
45

6+
Currently unsupported:
7+
* Running tests on forked repositories
8+
* Testing multiple repos (unless they are submodules)
9+
510
## Getting Started
611

712
Run the install script to install all dependencies, then create your .env file containing your App's tokens, secrets, etc.
813

914
### Prerequisites
1015

11-
Requires MATLAB 2017a or later, Node.js and Git Bash. The following Node.js modules are required:
16+
Requires Git Bash, npm v6.14 or later and Node.js v12.19.0 or later. For MATLAB tests use MATLAB 2017a or later.
1217

1318
```
14-
npm install --save express dotenv @octokit/app @octokit/request ...
15-
github-webhook-handler xml2js localtunnel
19+
npm install ./matlab-ci
1620
```
1721

1822
### Installing
1923

20-
Make sure runAllTests.m is on your MATLAB paths
24+
Create a shell/batch script for preparing your environment, and one for running the tests (i.e. calling Python or MATLAB).
25+
Add these to the settings.json file in config:
26+
```
27+
{
28+
"setup_function": "./prep_env.BAT",
29+
"test_function": "./run_tests.BAT",
30+
"listen_port": 3000,
31+
"timeout": 480000,
32+
"program": "python",
33+
"strict_coverage": false,
34+
"events": {
35+
"push": {
36+
"checks": null,
37+
"ref_ignore": ["documentation", "gh-pages"]
38+
},
39+
"pull_request": {
40+
"checks": ["continuous-integration", "coverage"],
41+
"actions": ["opened", "synchronize", "reopened"],
42+
"ref_ignore": ["documentation", "gh-pages"]
43+
}
44+
}
45+
}
46+
```
47+
Some extra optional settings:
48+
49+
- `shell` - optional shell to use when calling scripts (see `child_process.execFile` options).
50+
- `events:event:ref_include` - same as `ref_ignore`, but a pass list instead of block list.
51+
- `kill_children` - if present and true, `tree-kill` is used to kill the child processes, required
52+
if shell/batch script forks test process (e.g. a batch script calls python).
53+
54+
Finally, ensure these scripts are executable by node:
55+
```
56+
chmod u+x ./run_tests.BAT
57+
chmod u+x ./prep_env.BAT
58+
```
2159

2260
## Running the tests
2361

24-
TODO
62+
```
63+
mocha ./test
64+
```
2565

2666
## Deployment
2767

28-
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:
68+
To work properly you need to create install a
69+
[Github app](https://docs.github.com/en/free-pro-team@latest/developers/apps/creating-a-github-app)
70+
on your target repository and download the private key. Update your .env file like so:
2971

3072
```
3173
GITHUB_PRIVATE_KEY=path\to\private-key.pem
@@ -42,11 +84,17 @@ TUNNEL_SUBDOMAIN=
4284
To run at startup create a batch file with the following command:
4385

4486
```batch
45-
cmd /k node -r dotenv/config dotenv_config_path=/Path/To/Env/Vars ./Path/To/index.js
87+
cmd /k node -r dotenv/config dotenv_config_path=/Path/To/Env/Vars ./Path/To/main.js
4688
```
4789

4890
Create a shortcut in your startup folder ([Windows-logo] + [R] in Windows-10 and enter the command `shell:startup`)
4991

92+
## Test script
93+
Your test script must do the following:
94+
1. Accept a commit ID as an input arg
95+
2. Save the results into the JSON cache file without duplication
96+
3. For code coverage the script must either save the coverage directly, or export a Cobertura formatted XML file.
97+
5098
## Built With
5199

52100
* [LocalTunnel](https://localtunnel.me) - A secure tunneling service

config.json

-4
This file was deleted.

config/config.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const userSettings = require('./settings.json') || {}; // User settings
2+
const path = require('path');
3+
env = process.env.NODE_ENV || 'production';
4+
const appdata = process.env.APPDATA || process.env.HOME;
5+
const dataPath = process.env.APPDATA? path.join(appdata, 'CI') : path.join(appdata, '.ci');
6+
const fixtureDir = path.resolve(__dirname, '..', 'test', 'fixtures');
7+
const dbFilename = '.db.json';
8+
let settings;
9+
10+
// Defaults for when there's no user file; will almost certainly fail
11+
defaults = {
12+
setup_function: null,
13+
test_function: null,
14+
listen_port: 3000,
15+
timeout: 8*60000,
16+
program: "python",
17+
strict_coverage: false,
18+
events: {
19+
push: {
20+
checks: null,
21+
ref_ignore: ["documentation", "gh-pages"]
22+
},
23+
pull_request: {
24+
checks: ["continuous-integration", "coverage"],
25+
actions: ["opened", "synchronize", "reopen"],
26+
ref_ignore: ["documentation", "gh-pages"]
27+
}
28+
},
29+
dataPath: dataPath,
30+
dbFile: path.join(dataPath, dbFilename)
31+
}
32+
33+
// Settings for the tests
34+
testing = {
35+
listen_port: 3000,
36+
timeout: 60000,
37+
setup_function: 'prep_env.BAT',
38+
test_function: "run_tests.BAT",
39+
events: {
40+
push: {
41+
checks: "continuous-integration",
42+
ref_ignore: "documentation"
43+
},
44+
pull_request: {
45+
checks: ["coverage", "continuous-integration"],
46+
actions: ["opened", "synchronize"],
47+
ref_ignore: ["documentation", "gh-pages"]
48+
}
49+
},
50+
dataPath: fixtureDir,
51+
dbFile: path.join(fixtureDir, dbFilename) // cache of test results
52+
}
53+
54+
// Pick the settings to return
55+
if (env.startsWith('test')) {
56+
settings = testing;
57+
} else if (userSettings) {
58+
settings = userSettings;
59+
if (!('dbFile' in settings)) {
60+
settings.dbFile = path.join(dataPath, dbFilename)
61+
}
62+
if (!('dataPath' in settings)) {
63+
settings.dataPath = dataPath;
64+
}
65+
} else {
66+
settings = defaults;
67+
}
68+
69+
// Check ENV set up correctly
70+
required = ['GITHUB_PRIVATE_KEY', 'GITHUB_APP_IDENTIFIER', 'GITHUB_WEBHOOK_SECRET',
71+
'WEBHOOK_PROXY_URL', 'REPO_PATH', 'REPO_NAME', 'REPO_OWNER', 'TUNNEL_HOST',
72+
'TUNNEL_SUBDOMAIN'];
73+
missing = required.filter(o => { return !process.env[o] });
74+
if (missing.length > 0) {
75+
errMsg = `Env not set correctly; the following variables not found: \n${missing.join(', ')}`
76+
throw ReferenceError(errMsg)
77+
}
78+
79+
module.exports = { settings }

config/settings.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"setup_function": "prep_env.BAT",
3+
"test_function": "run_tests.BAT",
4+
"listen_port": 3000,
5+
"timeout": 480000,
6+
"program": "python",
7+
"strict_coverage": false,
8+
"events": {
9+
"push": {
10+
"checks": null,
11+
"ref_ignore": ["documentation", "gh-pages"]
12+
},
13+
"pull_request": {
14+
"checks": ["continuous-integration", "coverage"],
15+
"actions": ["opened", "synchronize", "reopened"],
16+
"ref_ignore": ["documentation", "gh-pages"]
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)