Skip to content

Commit

Permalink
Upgrade to CircleCI 2.0 (GoogleCloudPlatform#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry authored Oct 17, 2018
1 parent c7a7c4f commit d1f66cd
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 1,307 deletions.
58 changes: 58 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: 2
workflows:
version: 2
tests:
jobs: &workflow_jobs
- node8:
filters: &all_commits
tags:
only: /.*/
- lint:
requires:
- node8
- node10
filters: *all_commits
- tests:
requires:
- lint
filters: &master_and_releases
branches:
only: master
tags: &releases
only: '/^v[\d.]+$/'
nightly:
triggers:
- schedule:
cron: 0 7 * * *
filters:
branches:
only: master
jobs: *workflow_jobs
jobs:
node8:
docker:
- image: 'node:8'
user: node
steps: &unit_tests_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: npm test
- run: node_modules/.bin/codecov
lint:
docker:
- image: 'node:8'
user: node
steps:
- checkout
- run: *npm_install_and_link
- run:
name: Run linting.
command: npm run lint
environment:
NPM_CONFIG_PREFIX: /home/node/.npm-global
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);
}
})();
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
node_modules
.ipynb_checkpoints
yarn.lock
*.sublime-*
key.json
npm-debug.log
config.js
coverage/
settings.json
node_modules
.DS_Store

**/*.log
**/node_modules
.coverage
.nyc_output
docs/
out/
system-test/secrets.js
system-test/*key.json
*.lock
package-lock.json
23 changes: 0 additions & 23 deletions circle.yml

This file was deleted.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"scripts": {
"lint": "semistandard",
"build": "node ./bin/build",
"test": "npm run lint && mocha -t 120000 ./test/*"
"test": "mocha -t 120000 ./test/*"
},
"semistandard": {
"globals": [
Expand All @@ -15,11 +15,12 @@
"it"
],
"ignore": [
"**/node_modules/**"
"**/node_modules/**",
"tutorials/appengine-nodejs-webpack/**"
]
},
"devDependencies": {
"mocha": "3.4.2",
"semistandard": "11.0.0"
"mocha": "5.2.0",
"semistandard": "12.0.1"
}
}
4 changes: 2 additions & 2 deletions tutorials/cloud-functions-avro-import-bq/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.ToBigQuery_Stage = (event, callback) => {
const BigQuery = require('@google-cloud/bigquery');
const Storage = require('@google-cloud/storage');

// specify projectID and bigquery datasetID below
// specify projectID and bigquery datasetID below
const projectId = 'mikekahn-sandbox';
const datasetId = 'avroimport';
const bucketName = file.bucket;
Expand All @@ -23,7 +23,7 @@ exports.ToBigQuery_Stage = (event, callback) => {

console.log(`Load ${filename} into ${tableId}.`);

// Instantiates clients
// Instantiates clients
const bigquery = new BigQuery({
projectId: projectId
});
Expand Down
4 changes: 2 additions & 2 deletions tutorials/cloud-iot-rtdp/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ exports.iot = function (event, callback) {

function getDeviceBy (deviceName) {
const query = datastore
.createQuery('device')
.filter('name', '=', deviceName);
.createQuery('device')
.filter('name', '=', deviceName);
return datastore.runQuery(query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ function handleROPCTokenRequest (req, res) {
}

function verifyAuthorizationCode (authorizationCode, clientId, redirectUrl,
codeVerifier = undefined) {
codeVerifier = undefined) {
const transaction = datastore.transaction();
const key = datastore.key(['authorization_code', authorizationCode]);

Expand Down Expand Up @@ -503,13 +503,13 @@ function verifyAuthorizationCode (authorizationCode, clientId, redirectUrl,
entry.code_challenge !== undefined) {
let codeVerifierBuffer = Buffer.from(codeVerifier);
let codeChallenge = crypto
.createHash('sha256')
.update(codeVerifierBuffer)
.digest()
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
.createHash('sha256')
.update(codeVerifierBuffer)
.digest()
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
if (codeChallenge !== entry.code_challenge) {
return Promise.reject(new Error('Code verifier does not match code challenge.'));
}
Expand Down Expand Up @@ -542,10 +542,10 @@ function handleACTokenRequest (req, res) {
}

const clientQuery = datastore
.createQuery('client')
.filter('client-id', '=', req.body.client_id)
.filter('client-secret', '=', req.body.client_secret)
.filter('ac-enabled', '=', true);
.createQuery('client')
.filter('client-id', '=', req.body.client_id)
.filter('client-secret', '=', req.body.client_secret)
.filter('ac-enabled', '=', true);

datastore
.runQuery(clientQuery)
Expand Down
Loading

0 comments on commit d1f66cd

Please sign in to comment.