This repository has been archived by the owner on Mar 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
125 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters