Skip to content

Commit 6608938

Browse files
richardo2016ngot
authored andcommitted
feat: support customize built in services for .travis.yml and add samples for test locally; (#4)
1 parent 0cc985d commit 6608938

11 files changed

Lines changed: 138 additions & 4 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
node_modules
2+
3+
package-lock.json
4+
samples/**/.travis.yml
5+
samples/**/appveyor.yml

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
samples

generator.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ const engine = nunjucks.configure({
1010
});
1111

1212
let root;
13+
const env_sample_name = process.env.FIBJSCI_SAMPLE_NAME || 'normal';
1314
// support npminstall path
1415
if (__dirname.indexOf('.npminstall') >= 0) {
1516
root = path.join(__dirname, '../../../../../..');
17+
} else if (is_tested_locally(env_sample_name)) {
18+
root = path.join(__dirname, `./samples/${env_sample_name}`);
1619
} else {
1720
root = path.join(__dirname, '../../..');
1821
}
@@ -27,11 +30,24 @@ try {
2730
}
2831

2932
const config = Object.assign({
30-
type: 'travis, appveyor', // default is travis and appveyor
31-
version: '0.3.1', // default version to 0.3.1
33+
// default is travis and appveyor
34+
type: 'travis, appveyor',
35+
// default version to 0.3.1
36+
version: '0.3.1',
37+
// default empty
38+
/* travis services about: start */
39+
travis_services: [],
40+
get use_travis_services () {
41+
return !!this.travis_services.length
42+
},
43+
get use_travis_service__mysql () {
44+
return ~this.travis_services.indexOf('mysql')
45+
}
46+
/* travis services about: end */
3247
}, pkg.ci);
3348
config.types = arrayify(config.type);
3449
config.versions = arrayify(config.version);
50+
config.travis_services = arrayify(config.travis_services);
3551

3652
let ymlName = '';
3753

@@ -56,3 +72,9 @@ function arrayify(str) {
5672
if (Array.isArray(str)) return str;
5773
return str.split(/\s*,\s*/).filter(s => !!s);
5874
}
75+
76+
function is_tested_locally (env_sample_name = process.env.FIBJSCI_SAMPLE_NAME) {
77+
return !!env_sample_name && fs.existsSync(
78+
path.resolve(__dirname, './samples/.lifecyclecheck')
79+
)
80+
}

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ Add `ci` property to your `package.json`:
1414

1515
```json
1616
"ci": {
17-
"type": "travis, appveyor", // default ci env type is 'travis, appveyor'
18-
"version": "0.3.1" // default version is 0.3.1. Only support version >= 0.3.1
17+
// default ci env type is 'travis, appveyor'
18+
"type": "travis, appveyor",
19+
// default version is 0.3.1. Only support version >= 0.3.1
20+
"version": "0.3.1",
21+
// support use built-in services for travis
22+
"travis_services": [
23+
"mysql"
24+
]
1925
}
2026
```
2127

samples/.lifecyclecheck

Whitespace-only changes.

samples/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## How to test locally in /samples?
2+
3+
in case testing `normal-versions`:
4+
5+
```bash
6+
# set environment variable
7+
export FIBJSCI_SAMPLE_NAME=normal-versions
8+
# cd to tested sample
9+
cd ./samples/normal-versions
10+
# install @fibjs/ci locally to trigger npm script `postinstall`
11+
npm i ../../
12+
```
13+
14+
run commands above, then view the results generated by `@fibjs/ci`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "normal-appveyor-only",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"ci": {
11+
"type": "appveyor"
12+
},
13+
"license": "ISC",
14+
"dependencies": {
15+
"@fibjs/ci": "file:../.."
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "normal-versions",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"ci": {
11+
"version": [
12+
"0.21.0",
13+
"0.22.0",
14+
"0.26.1"
15+
]
16+
},
17+
"license": "ISC",
18+
"dependencies": {
19+
"@fibjs/ci": "file:../.."
20+
}
21+
}

samples/normal/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "normal",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "npm i ../../"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {},
12+
"devDependencies": {
13+
"@fibjs/ci": "file:../.."
14+
}
15+
}

samples/travis-mysql/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "travis-mysql",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"ci": {
12+
"travis_services": [
13+
"redis",
14+
"mysql"
15+
]
16+
},
17+
"dependencies": {
18+
"@fibjs/ci": "file:../.."
19+
}
20+
}

0 commit comments

Comments
 (0)