Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Commit d48c9ec

Browse files
committed
Update CI config.
1 parent ca9200b commit d48c9ec

File tree

10 files changed

+186
-120
lines changed

10 files changed

+186
-120
lines changed

.circleci/config.yml

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,90 +3,89 @@ workflows:
33
version: 2
44
tests:
55
jobs: &workflow_jobs
6-
- node6:
7-
filters:
8-
tags:
9-
only: /.*/
10-
# - node8:
11-
# filters:
12-
# tags:
13-
# only: /.*/
14-
# - node10:
15-
# filters:
16-
# tags:
17-
# only: /.*/
186
- lint:
19-
requires:
20-
- node6
21-
# - node8
22-
# - node10
23-
filters:
7+
filters: &all_commits
248
tags:
259
only: /.*/
26-
- system_tests:
10+
- node6:
2711
requires:
2812
- lint
29-
filters:
30-
branches:
31-
only: master
32-
tags:
33-
only: '/^v[\d.]+$/'
34-
- publish_npm:
13+
filters: *all_commits
14+
- node8:
3515
requires:
36-
- system_tests
16+
- lint
17+
filters: *all_commits
18+
nightly:
19+
triggers:
20+
- schedule:
21+
cron: 0 7 * * *
3722
filters:
3823
branches:
39-
ignore: /.*/
40-
tags:
41-
only: '/^v[\d.]+$/'
24+
only: master
25+
jobs: *workflow_jobs
4226
jobs:
27+
lint:
28+
docker:
29+
- image: 'node:8'
30+
user: node
31+
steps:
32+
- checkout
33+
- run: &npm_install_and_link
34+
name: Install and link the module
35+
command: |-
36+
mkdir -p /home/node/.npm-global
37+
./.circleci/npm-install-retry.js
38+
environment:
39+
NPM_CONFIG_PREFIX: /home/node/.npm-global
40+
- run:
41+
name: Run linting.
42+
command: npm run lint
43+
environment:
44+
NPM_CONFIG_PREFIX: /home/node/.npm-global
4345
node6:
4446
docker:
4547
- image: 'node:6'
46-
steps: &unit_tests_steps
48+
user: node
49+
steps: &tests_steps
4750
- checkout
51+
- run:
52+
name: Decrypt credentials.
53+
command: |
54+
if ! [[ -z "${SERVICE_ACCOUNT_ENCRYPTION_KEY}" ]]; then
55+
for encrypted_key in .circleci/*.json.enc; do
56+
openssl aes-256-cbc -d -in $encrypted_key \
57+
-out $(echo $encrypted_key | sed 's/\.enc//') \
58+
-k "${SERVICE_ACCOUNT_ENCRYPTION_KEY}"
59+
done
60+
fi
4861
- run:
4962
name: Install and configure Cloud SDK
5063
command: |
51-
echo $KEYFILE > key.json
52-
curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-209.0.0-linux-x86_64.tar.gz | tar xz
64+
curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-225.0.0-linux-x86_64.tar.gz | tar xz
5365
mv ./google-cloud-sdk /opt
5466
export PATH=$PATH:/opt/google-cloud-sdk/bin
5567
gcloud components install beta -q
5668
gcloud components update -q
5769
gcloud config set project cloud-functions-emulator
5870
gcloud config set compute/region us-central1
59-
gcloud auth activate-service-account --key-file key.json
60-
- run: yarn
61-
- run: yarn test
71+
gcloud auth activate-service-account --key-file .circleci/key.json
72+
- run: *npm_install_and_link
73+
- run:
74+
name: Run tests.
75+
command: npm test
76+
environment:
77+
GCLOUD_PROJECT: cloud-functions-emulator
78+
GOOGLE_APPLICATION_CREDENTIALS: .circleci/key.json
6279
- run: node_modules/.bin/codecov
63-
# node8:
64-
# docker:
65-
# - image: 'node:8'
66-
# steps: *unit_tests_steps
67-
# node10:
68-
# docker:
69-
# - image: 'node:10'
70-
# steps: *unit_tests_steps
71-
lint:
72-
docker:
73-
- image: 'node:6'
74-
steps:
75-
- checkout
76-
- run: yarn install
77-
- run: npm run lint
78-
system_tests:
80+
- run:
81+
name: Remove unencrypted key.
82+
command: |
83+
if ! [[ -z "${SERVICE_ACCOUNT_ENCRYPTION_KEY}" ]]; then
84+
rm .circleci/*.json
85+
fi
86+
when: always
87+
node8:
7988
docker:
80-
- image: 'node:6'
89+
- image: 'node:8'
8190
user: node
82-
steps:
83-
- checkout
84-
- run: yarn
85-
- run: yarn run system-test
86-
publish_npm:
87-
docker:
88-
- image: 'node:10'
89-
steps:
90-
- checkout
91-
- run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
92-
- run: npm publish
91+
steps: *tests_steps

.circleci/key.json.enc

2.31 KB
Binary file not shown.

.circleci/npm-install-retry.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env node
2+
3+
let spawn = require('child_process').spawn;
4+
5+
//
6+
//USE: ./index.js <ms npm can be idle> <number of attempts> [... NPM ARGS]
7+
//
8+
9+
let timeout = process.argv[2] || 60000;
10+
let attempts = process.argv[3] || 3;
11+
let args = process.argv.slice(4);
12+
if (args.length === 0) {
13+
args = ['install'];
14+
}
15+
16+
(function npm() {
17+
let timer;
18+
args.push('--verbose');
19+
let proc = spawn('npm', args);
20+
proc.stdout.pipe(process.stdout);
21+
proc.stderr.pipe(process.stderr);
22+
proc.stdin.end();
23+
proc.stdout.on('data', () => {
24+
setTimer();
25+
});
26+
proc.stderr.on('data', () => {
27+
setTimer();
28+
});
29+
30+
// side effect: this also restarts when npm exits with a bad code even if it
31+
// didnt timeout
32+
proc.on('close', (code, signal) => {
33+
clearTimeout(timer);
34+
if (code || signal) {
35+
console.log('[npm-are-you-sleeping] npm exited with code ' + code + '');
36+
37+
if (--attempts) {
38+
console.log('[npm-are-you-sleeping] restarting');
39+
npm();
40+
} else {
41+
console.log('[npm-are-you-sleeping] i tried lots of times. giving up.');
42+
throw new Error("npm install fails");
43+
}
44+
}
45+
});
46+
47+
function setTimer() {
48+
clearTimeout(timer);
49+
timer = setTimeout(() => {
50+
console.log('[npm-are-you-sleeping] killing npm with SIGTERM');
51+
proc.kill('SIGTERM');
52+
// wait a couple seconds
53+
timer = setTimeout(() => {
54+
// its it's still not closed sigkill
55+
console.log('[npm-are-you-sleeping] killing npm with SIGKILL');
56+
proc.kill('SIGKILL');
57+
}, 2000);
58+
}, timeout);
59+
}
60+
})();

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@
7373
"generate-scaffolding": "repo-tools generate contributors coc contributing license pr_template pkgjson"
7474
},
7575
"dependencies": {
76-
"@google-cloud/storage": "^1.7.0",
77-
"adm-zip": "^0.4.11",
78-
"ajv": "^6.5.2",
76+
"@google-cloud/storage": "^2.3.1",
77+
"adm-zip": "^0.4.13",
78+
"ajv": "^6.5.5",
79+
"axios": "^0.18.0",
7980
"body-parser": "^1.18.3",
8081
"chokidar": "^2.0.4",
81-
"cli-table2": "0.2.0",
82-
"colors": "^1.3.1",
82+
"cli-table3": "^0.5.1",
83+
"colors": "^1.3.2",
8384
"configstore": "^4.0.0",
84-
"express": "^4.16.3",
85+
"express": "^4.16.4",
8586
"googleapis": "^35.0.0",
86-
"got": "^9.0.0",
8787
"http-proxy": "^1.17.0",
8888
"lodash": "4.17.11",
8989
"make-dir": "1.3.0",
@@ -92,23 +92,23 @@
9292
"semver": "5.6.0",
9393
"serializerr": "1.0.3",
9494
"tmp": "0.0.33",
95-
"uuid": "3.2.1",
95+
"uuid": "3.3.2",
9696
"winston": "3.1.0",
9797
"xdg-basedir": "3.0.0",
98-
"yargs": "11.0.0"
98+
"yargs": "12.0.2"
9999
},
100100
"devDependencies": {
101101
"@google-cloud/nodejs-repo-tools": "^3.0.0",
102-
"codecov": "^3.0.4",
102+
"codecov": "^3.1.0",
103103
"intelli-espower-loader": "^1.0.1",
104104
"mocha": "^5.2.0",
105-
"nock": "^10.0.0",
106-
"nyc": "^13.0.0",
107-
"power-assert": "^1.6.0",
108-
"proxyquire": "^2.0.0",
109-
"semistandard": "^13.0.0",
105+
"nock": "^10.0.2",
106+
"nyc": "^13.1.0",
107+
"power-assert": "^1.6.1",
108+
"proxyquire": "^2.1.0",
109+
"semistandard": "^13.0.1",
110110
"semistandard-format": "^3.0.0",
111-
"sinon": "^7.0.0",
112-
"supertest": "^3.0.0"
111+
"sinon": "^7.1.1",
112+
"supertest": "^3.3.0"
113113
}
114114
}

src/cli/controller.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ require('colors');
3434

3535
const _ = require('lodash');
3636
const AdmZip = require('adm-zip');
37+
const axios = require('axios');
3738
const exec = require('child_process').exec;
3839
const fs = require('fs');
39-
const got = require('got');
4040
const path = require('path');
4141
const spawn = require('child_process').spawn;
4242
const Storage = require('@google-cloud/storage');
@@ -367,14 +367,15 @@ class Controller {
367367
this.log(`You paused execution. Connect to the debugger on port ${opts.port} to resume execution and begin debugging.`);
368368
}
369369

370-
return got.post(`http://${this.config.host}:${this.config.supervisorPort}/api/debug`, {
371-
body: {
370+
return axios.request({
371+
url: `http://${this.config.host}:${this.config.supervisorPort}/api/debug`,
372+
method: 'POST',
373+
data: {
372374
type: type,
373375
name: cloudfunction.name,
374376
port: opts.port,
375377
pause: opts.pause
376-
},
377-
json: true
378+
}
378379
});
379380
});
380381
}
@@ -563,12 +564,13 @@ class Controller {
563564
reset (name, opts) {
564565
return this.client.getFunction(name)
565566
.then(([cloudfunction]) => {
566-
return got.post(`http://${this.config.host}:${this.config.supervisorPort}/api/reset`, {
567-
body: {
567+
return axios.request({
568+
url: `http://${this.config.host}:${this.config.supervisorPort}/api/reset`,
569+
method: 'POST',
570+
data: {
568571
name: cloudfunction.name,
569572
keep: opts.keep
570-
},
571-
json: true
573+
}
572574
});
573575
});
574576
}

src/client/rest-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
'use strict';
1717

1818
const _ = require('lodash');
19-
const google = require('googleapis');
19+
const { google } = require('googleapis');
2020
const net = require('net');
2121
const path = require('path');
2222
const url = require('url');

src/model/functions.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
const _ = require('lodash');
1919
const AdmZip = require('adm-zip');
20+
const axios = require('axios');
2021
const Configstore = require('configstore');
2122
const fs = require('fs');
22-
const got = require('got');
2323
const logger = require('winston');
2424
const os = require('os');
2525
const path = require('path');
@@ -388,11 +388,12 @@ class Functions {
388388

389389
return new Promise((resolve, reject) => {
390390
setTimeout(() => {
391-
got.post(`${this.getSupervisorHost()}/api/deploy`, {
392-
body: {
391+
return axios.request({
392+
url: `${this.getSupervisorHost()}/api/deploy`,
393+
method: 'POST',
394+
data: {
393395
name: cloudfunction.name
394-
},
395-
json: true
396+
}
396397
}).then(resolve, (err) => {
397398
if (err && err.response && err.response.body) {
398399
if (err.response.body.error) {
@@ -521,11 +522,12 @@ class Functions {
521522
// Delete the CloudFunction
522523
this.adapter.deleteFunction(name)
523524
.then(() => {
524-
return got.post(`${this.getSupervisorHost()}/api/delete`, {
525-
body: {
525+
return axios.request({
526+
url: `${this.getSupervisorHost()}/api/delete`,
527+
method: 'POST',
528+
data: {
526529
name: cloudfunction.name
527-
},
528-
json: true
530+
}
529531
});
530532
})
531533
.then(() => {

0 commit comments

Comments
 (0)