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

Commit

Permalink
Update CI config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Nov 16, 2018
1 parent ca9200b commit 83d77fd
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 81 deletions.
123 changes: 61 additions & 62 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,89 @@ workflows:
version: 2
tests:
jobs: &workflow_jobs
- node6:
filters:
tags:
only: /.*/
# - node8:
# filters:
# tags:
# only: /.*/
# - node10:
# filters:
# tags:
# only: /.*/
- lint:
requires:
- node6
# - node8
# - node10
filters:
filters: &all_commits
tags:
only: /.*/
- system_tests:
- node6:
requires:
- lint
filters:
branches:
only: master
tags:
only: '/^v[\d.]+$/'
- publish_npm:
filters: *all_commits
- node8:
requires:
- system_tests
- lint
filters: *all_commits
nightly:
triggers:
- schedule:
cron: 0 7 * * *
filters:
branches:
ignore: /.*/
tags:
only: '/^v[\d.]+$/'
only: master
jobs: *workflow_jobs
jobs:
lint:
docker:
- image: 'node:8'
user: node
steps:
- checkout
- run: &npm_install_and_link
name: Install and link the module
command: |-
mkdir -p /home/node/.npm-global
./.circleci/npm-install-retry.js
environment:
NPM_CONFIG_PREFIX: /home/node/.npm-global
- run:
name: Run linting.
command: npm run lint
environment:
NPM_CONFIG_PREFIX: /home/node/.npm-global
node6:
docker:
- image: 'node:6'
steps: &unit_tests_steps
user: node
steps: &tests_steps
- checkout
- run:
name: Decrypt credentials.
command: |
if ! [[ -z "${SERVICE_ACCOUNT_ENCRYPTION_KEY}" ]]; then
for encrypted_key in .circleci/*.json.enc; do
openssl aes-256-cbc -d -in $encrypted_key \
-out $(echo $encrypted_key | sed 's/\.enc//') \
-k "${SERVICE_ACCOUNT_ENCRYPTION_KEY}"
done
fi
- run:
name: Install and configure Cloud SDK
command: |
echo $KEYFILE > key.json
curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-209.0.0-linux-x86_64.tar.gz | tar xz
curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-225.0.0-linux-x86_64.tar.gz | tar xz
mv ./google-cloud-sdk /opt
export PATH=$PATH:/opt/google-cloud-sdk/bin
gcloud components install beta -q
gcloud components update -q
gcloud config set project cloud-functions-emulator
gcloud config set compute/region us-central1
gcloud auth activate-service-account --key-file key.json
- run: yarn
- run: yarn test
gcloud auth activate-service-account --key-file .circleci/key.json
- run: *npm_install_and_link
- run:
name: Run tests.
command: npm test
environment:
GCLOUD_PROJECT: cloud-functions-emulator
GOOGLE_APPLICATION_CREDENTIALS: .circleci/key.json
- run: node_modules/.bin/codecov
# node8:
# docker:
# - image: 'node:8'
# steps: *unit_tests_steps
# node10:
# docker:
# - image: 'node:10'
# steps: *unit_tests_steps
lint:
docker:
- image: 'node:6'
steps:
- checkout
- run: yarn install
- run: npm run lint
system_tests:
- run:
name: Remove unencrypted key.
command: |
if ! [[ -z "${SERVICE_ACCOUNT_ENCRYPTION_KEY}" ]]; then
rm .circleci/*.json
fi
when: always
node8:
docker:
- image: 'node:6'
- image: 'node:8'
user: node
steps:
- checkout
- run: yarn
- run: yarn run system-test
publish_npm:
docker:
- image: 'node:10'
steps:
- checkout
- run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run: npm publish
steps: *tests_steps
Binary file added .circleci/key.json.enc
Binary file not shown.
60 changes: 60 additions & 0 deletions .circleci/npm-install-retry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env node

let spawn = require('child_process').spawn;

//
//USE: ./index.js <ms npm can be idle> <number of attempts> [... NPM ARGS]
//

let timeout = process.argv[2] || 60000;
let attempts = process.argv[3] || 3;
let args = process.argv.slice(4);
if (args.length === 0) {
args = ['install'];
}

(function npm() {
let timer;
args.push('--verbose');
let proc = spawn('npm', args);
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
proc.stdin.end();
proc.stdout.on('data', () => {
setTimer();
});
proc.stderr.on('data', () => {
setTimer();
});

// side effect: this also restarts when npm exits with a bad code even if it
// didnt timeout
proc.on('close', (code, signal) => {
clearTimeout(timer);
if (code || signal) {
console.log('[npm-are-you-sleeping] npm exited with code ' + code + '');

if (--attempts) {
console.log('[npm-are-you-sleeping] restarting');
npm();
} else {
console.log('[npm-are-you-sleeping] i tried lots of times. giving up.');
throw new Error("npm install fails");
}
}
});

function setTimer() {
clearTimeout(timer);
timer = setTimeout(() => {
console.log('[npm-are-you-sleeping] killing npm with SIGTERM');
proc.kill('SIGTERM');
// wait a couple seconds
timer = setTimeout(() => {
// its it's still not closed sigkill
console.log('[npm-are-you-sleeping] killing npm with SIGKILL');
proc.kill('SIGKILL');
}, 2000);
}, timeout);
}
})();
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@
"generate-scaffolding": "repo-tools generate contributors coc contributing license pr_template pkgjson"
},
"dependencies": {
"@google-cloud/storage": "^1.7.0",
"adm-zip": "^0.4.11",
"ajv": "^6.5.2",
"@google-cloud/storage": "^2.3.1",
"adm-zip": "^0.4.13",
"ajv": "^6.5.5",
"body-parser": "^1.18.3",
"chokidar": "^2.0.4",
"cli-table2": "0.2.0",
"colors": "^1.3.1",
"colors": "^1.3.2",
"configstore": "^4.0.0",
"express": "^4.16.3",
"express": "^4.16.4",
"googleapis": "^35.0.0",
"got": "^9.0.0",
"got": "^9.3.2",
"http-proxy": "^1.17.0",
"lodash": "4.17.11",
"make-dir": "1.3.0",
Expand All @@ -92,23 +92,23 @@
"semver": "5.6.0",
"serializerr": "1.0.3",
"tmp": "0.0.33",
"uuid": "3.2.1",
"uuid": "3.3.2",
"winston": "3.1.0",
"xdg-basedir": "3.0.0",
"yargs": "11.0.0"
"yargs": "12.0.2"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"codecov": "^3.0.4",
"codecov": "^3.1.0",
"intelli-espower-loader": "^1.0.1",
"mocha": "^5.2.0",
"nock": "^10.0.0",
"nyc": "^13.0.0",
"power-assert": "^1.6.0",
"proxyquire": "^2.0.0",
"semistandard": "^13.0.0",
"nock": "^10.0.2",
"nyc": "^13.1.0",
"power-assert": "^1.6.1",
"proxyquire": "^2.1.0",
"semistandard": "^13.0.1",
"semistandard-format": "^3.0.0",
"sinon": "^7.0.0",
"supertest": "^3.0.0"
"sinon": "^7.1.1",
"supertest": "^3.3.0"
}
}
6 changes: 3 additions & 3 deletions test/unit/service/rest-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('unit/service/rest-service', () => {

nock('https://faked.com')
.post('/fake-project/us-central1/test-function', {
auth: {admin: true}
auth: { admin: true }
})
.reply(200);

Expand All @@ -124,15 +124,15 @@ describe('unit/service/rest-service', () => {

nock('https://faked.com')
.post('/fake-project/us-central1/test-function', {
auth: {admin: false},
auth: { admin: false },
resource: 'custom.resource'
})
.reply(200);

request(service.server)
.post('/v1/projects/fake-project/locations/us-central1/functions/test-function:call')
.send({
auth: {admin: false},
auth: { admin: false },
resource: 'custom.resource'
})
.expect(200, done);
Expand Down

0 comments on commit 83d77fd

Please sign in to comment.