Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chuwy committed Apr 28, 2017
2 parents fb36091 + 8c7cce4 commit 2e11ed5
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 20 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions .travis/deploy.py
Original file line number Diff line number Diff line change
@@ -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'])
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions lib/emitter.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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') {
Expand All @@ -50,14 +51,19 @@ function emitter(endpoint, protocol, port, method, bufferSize, callback) {
request.post({
url: targetUrl,
json: postJson,
agentOptions: agentOptions,
headers: {
'content-type': 'application/json; charset=utf-8'
}
}, callback);

} else {
for (var i=0; i<temp.length; i++) {
request.get({url: targetUrl, qs: temp[i]}, callback);
request.get({
url: targetUrl,
agentOptions: agentOptions,
qs: temp[i]
}, callback);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

var version = require('./version');
var core = require('snowplow-tracker-core');
var core = require('snowplow-tracker-core').trackerCore;

/**
* Snowplow Node.js Tracker
Expand Down
4 changes: 2 additions & 2 deletions lib/version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Node.js tracker for Snowplow: version.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.
Expand All @@ -13,4 +13,4 @@
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/

module.exports = '0.2.0';
module.exports = '0.3.0';
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snowplow-tracker",
"version": "0.2.0",
"version": "0.3.0",
"scripts": {
"test": "./node_modules/mocha/bin/mocha",
"test-travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./test/*"
Expand All @@ -12,7 +12,8 @@
"coveralls": "~2.11.4"
},
"contributors": [
"Fred Blundun"
"Fred Blundun",
"Anton Parkhomenko"
],
"description": "Node.js tracker for Snowplow",
"repository": {
Expand All @@ -29,7 +30,7 @@
],
"license": "Apache 2.0",
"dependencies": {
"request": "^2.39.0",
"snowplow-tracker-core": "^0.4.0"
"request": "^2.81.0",
"snowplow-tracker-core": "^0.5.0"
}
}
4 changes: 2 additions & 2 deletions test/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var context = [{
}];

var completedContext = JSON.stringify({
schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-1',
schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0',
data: context
});

Expand Down Expand Up @@ -298,7 +298,7 @@ function performTestsWithMethod(method) {
var e = emitter(endpoint, 'http', null, method, 0, function (error, body, response) {
var pd = extractPayload(response, method, true);
assert.equal(pd['ue_px'], 'eyJzY2hlbWEiOiJpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy91bnN0cnVjdF9ldmVudC9qc29uc2NoZW1hLzEtMC0wIiwiZGF0YSI6eyJzY2hlbWEiOiJpZ2x1OmNvbS5hY21lL3ZpZXdlZF9wcm9kdWN0L2pzb25zY2hlbWEvMS0wLTAiLCJkYXRhIjp7InByaWNlIjoyMH19fQ');
assert.equal(pd['cx'], 'eyJzY2hlbWEiOiJpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy9jb250ZXh0cy9qc29uc2NoZW1hLzEtMC0xIiwiZGF0YSI6W3sic2NoZW1hIjoiaWdsdTpjb20uYWNtZS91c2VyL2pzb25zY2hlbWEvMS0wLTAiLCJkYXRhIjp7InR5cGUiOiJ0ZXN0ZXIifX1dfQ');
assert.equal(pd['cx'], 'eyJzY2hlbWEiOiJpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy9jb250ZXh0cy9qc29uc2NoZW1hLzEtMC0wIiwiZGF0YSI6W3sic2NoZW1hIjoiaWdsdTpjb20uYWNtZS91c2VyL2pzb25zY2hlbWEvMS0wLTAiLCJkYXRhIjp7InR5cGUiOiJ0ZXN0ZXIifX1dfQ');
done.call(this, error);
});

Expand Down

0 comments on commit 2e11ed5

Please sign in to comment.