diff --git a/.travis.yml b/.travis.yml index 33b5ea9..2e23b59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,20 @@ language: node_js node_js: - - "0.10" - - "0.11" + - "7.9.0" + - "6.10.2" + - "5.12.0" script: - "npm run-script test-travis" after_script: - "cat coverage/lcov.info" - "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" +env: + global: + # NPM_AUTH_TOKEN + secure: goIuZqbvukt7LXRKzEqXhKb9xqizr7ikxm8KRD/mUiGBJ1xikehQFKSTulJoPfsyOPe3WOfhq1aKZwRCzDXbqt9oSbJoMhgSTn/jB274WYv8VuTWZQUVIeruba0ma1spyQSag1o+WaDYVRUfy1mEkUX7jQJY4lxEUJP1bFHREig= +deploy: +- provider: script + script: ./.travis/deploy.py + on: + condition: '"${TRAVIS_NODE_VERSION}" == "7.9.0"' + tags: true diff --git a/.travis/deploy.py b/.travis/deploy.py new file mode 100755 index 0000000..1019e11 --- /dev/null +++ b/.travis/deploy.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python + +from contextlib import contextmanager +import os +import sys +import subprocess + + +if 'TRAVIS_TAG' in os.environ: + TRAVIS_TAG = os.environ.get('TRAVIS_TAG') +else: + sys.exit("Environment variable TRAVIS_TAG is unavailable") + +if 'NPM_AUTH_TOKEN' in os.environ: + NPM_AUTH_TOKEN = os.environ.get('NPM_AUTH_TOKEN') +else: + sys.exit("Environment variable NPM_AUTH_TOKEN is unavailable") + +@contextmanager +def npm_credentials(): + """Context manager allowing to use different credentials and delete them after use""" + npmrc = os.path.expanduser("~/.npmrc") + + if os.path.isfile(npmrc): + os.remove(npmrc) + print("WARNING! ~/.npmrc already exists. It should be deleted after each use") + print("Overrinding existing ~/.npmrc") + else: + print("Creating ~/.npmrc") + + with open(npmrc, 'a') as f: + f.write("registry=http://registry.npmjs.org/\n//registry.npmjs.org/:_authToken=" + NPM_AUTH_TOKEN) + + yield + + print("Deleting ~/.npmrc") + os.remove(npmrc) + + +def output_if_error(output): + """Callback to print stderr and fail deploy if exit status not successful""" + (stdout, stderr) = output.communicate() + if output.returncode != 0: + print("Process has been failed.\n" + stdout) + sys.exit(stderr) + + +def execute(command, callback=output_if_error): + """Execute shell command with optional callback""" + formatted_command = " ".join(command) if (type(command) == list) else command + print("Executing [{0}]".format(formatted_command)) + output = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if hasattr(callback, '__call__'): + return callback(output) + else: + return output + + +def check_version(): + """Fail deploy if tag version doesn't match ./package.json version""" + get_version = """var fs=require('fs'); fs.readFile('./package.json', 'utf8', function(e,d) { console.log(JSON.parse(d)['version']) });""" + + node_output = execute(['node', '-e', get_version], None) + print(node_output.stderr.read()) + for line in node_output.stdout.read().split("\n"): + print(line) + if line and line != TRAVIS_TAG: + sys.exit("Version extracted from TRAVIS_TAG [{0}] doesn't conform declared in package.json [{1}]".format(TRAVIS_TAG, line)) + if line == TRAVIS_TAG: + return + + sys.exit("Cannot find version in core output:\n" + str(node_output)) + + +if __name__ == "__main__": + check_version() + with npm_credentials(): + execute(['npm', 'publish']) diff --git a/CHANGELOG b/CHANGELOG index b0ba631..8ed0d8a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,12 @@ +Version 0.3.0 (2017-04-28) +-------------------------- +Add npm credentials to .travis.yml (#36) +Bump request to 2.81.0 (#34) +Bump Core to 0.5.0 (#33) +Add agentOptions argument to emitter (#30) +Add latest Node.js versions to travis.yml (#32) +Update README markdown in according with CommonMark (#31) + Version 0.2.0 (2015-10-09) -------------------------- Removed callback argument from tracker constructor (#19) diff --git a/README.md b/README.md index 23bf0f9..f50157f 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ This tracker lets you collect event data from Node.js applications. ## Find out more -| Technical Docs | Setup Guide | Roadmap & Contributing | -|-----------------------------|-----------------------|--------------------------------------| -| [ ![i1] [techdocs-image] ] [tech-docs] | [ ![i2] [setup-image] ] [setup] | ![i3] [roadmap-image] | -| [Technical Docs] [tech-docs] | [Setup Guide] [setup] | _coming soon_ | +| Technical Docs | Setup Guide | Roadmap & Contributing | +|--------------------------------------|-------------------------------|-------------------------| +| [ ![i1][techdocs-image] ][tech-docs] | [ ![i2][setup-image] ][setup] | ![i3][roadmap-image] | +| [Technical Docs][tech-docs] | [Setup Guide][setup] | _coming soon_ | ## Developers @@ -36,9 +36,9 @@ npm test ## Copyright and license -The Snowplow Node.js Tracker is copyright 2014 Snowplow Analytics Ltd. +The Snowplow Node.js Tracker is copyright 2014-2017 Snowplow Analytics Ltd. -Licensed under the **[Apache License, Version 2.0] [license]** (the "License"); +Licensed under the **[Apache License, Version 2.0][license]** (the "License"); you may not use this software except in compliance with the License. Unless required by applicable law or agreed to in writing, software diff --git a/lib/emitter.js b/lib/emitter.js index 8f157d6..d7a9ca3 100644 --- a/lib/emitter.js +++ b/lib/emitter.js @@ -1,7 +1,7 @@ /* * Node.js tracker for Snowplow: emitter.js * - * Copyright (c) 2014-2015 Snowplow Analytics Ltd. All rights reserved. + * Copyright (c) 2014-2017 Snowplow Analytics Ltd. All rights reserved. * * This program is licensed to you under the Apache License Version 2.0, * and you may not use this file except in compliance with the Apache License Version 2.0. @@ -24,8 +24,9 @@ var request = require('request'); * @param string method "get" or "post" * @param number bufferSize Number of events which can be queued before flush is called * @param function callback Callback passed to the request function + * @param agentOptions configuration for http.Agent class */ -function emitter(endpoint, protocol, port, method, bufferSize, callback) { +function emitter(endpoint, protocol, port, method, bufferSize, callback, agentOptions) { protocol = (protocol || 'http').toLowerCase(); method = (method || 'get').toLowerCase(); if (bufferSize === null || typeof bufferSize === 'undefined') { @@ -50,6 +51,7 @@ function emitter(endpoint, protocol, port, method, bufferSize, callback) { request.post({ url: targetUrl, json: postJson, + agentOptions: agentOptions, headers: { 'content-type': 'application/json; charset=utf-8' } @@ -57,7 +59,11 @@ function emitter(endpoint, protocol, port, method, bufferSize, callback) { } else { for (var i=0; i