diff --git a/.travis.yml b/.travis.yml index 9fbdd863..a4b864e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ +git: + depth: 5 language: node_js +cache: yarn # https://github.com/nodejs/Release node_js: @@ -6,10 +9,13 @@ node_js: - '10' - '8' -git: - depth: 5 - -cache: yarn +script: | + if [[ "$(node -pe process.version)" == v10.* ]]; then # Is latest LTS? + npm run test:ci && + cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js + else + npm run testonly + fi notifications: irc: @@ -21,17 +27,3 @@ notifications: - 'chat.freenode.net#graphql' slack: secure: eFMk+9i9G0F8VYd0cd+qfBXEcngR1odYzGapdSSPH0Ag6Ck1sjK64n0iFwz+RDV2sSVnjnAA5qbXNcltBhEe1DkNsZVXOp4cDxKiFQOH1NJu9m29rYx+dZ4H93JjuDtH0u2o2op/PhtXlwAjr8GBcdGgFNTUbiJv9nIj4sYudQJFL8VUQwYviRO28xx12hG7cmKvQ7YZ/OKz52oGnIOM4yoQgPKFRY4ztMr6OrHwDwWMAxptZjKYY0i2hE3ot+OkWeWteZvE9E2Q0OJI7C6XlZg+bR6Mu7VS5s6jjL21luJJBgwihLuWVNMXxxEfoUCldo0s/RX8lObuFocKpnAtqVimr1rPZtUYZzy/Jjd1fxa27TgONZUgibWoRbAFDCdKhJOsBSLGfvQw+a3sxkV5zD5DKpgaNavT+GbOZJn4KGw3i1M/5Gp1tqB+RsTMjRvXQH5rsc+9z/flys1K9sNrc7O0NS2sVPayf4U5ECgT6t0y6NM1hQNepNHbvPSU/I/dUPYQEMcWMtdgtApAeUcbsRFUgFejNwp4hhTz0MS6k9AtmLJ79mNQBqDgZ3/pnW/YjW7BsK8/f6xOabxJjwIdLJvAifxRy/oj8wd5ttx8u+qKZ547PhdNJiMV7H60tGqkJshqbphlvWr48l0EV0A635uY24VefYoTeMIXZSeueME= - -before_install: - - npm config set spin false --global - -script: - - if [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then npm run lint && npm run check && npm run cover; else npm run testonly; fi - -after_failure: - - (cd resources; python travis_after_all.py) - -after_success: - - (cd resources; python travis_after_all.py) - - export $(cat resources/.to_export_back) - - if [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js; fi diff --git a/package.json b/package.json index 00a2b236..dde6ecab 100644 --- a/package.json +++ b/package.json @@ -37,14 +37,14 @@ "scripts": { "prepublish": ". ./resources/prepublish.sh", "test": "npm run lint && npm run check && npm run testonly", + "test:ci": "yarn check --integrity && npm run lint && npm run check && npm run testonly:cover && npm run build", "testonly": "mocha src/**/__tests__/**/*.js", + "testonly:cover": "nyc npm run testonly", "lint": "prettier --ignore-path .gitignore --check '**/*.{js,ts,md,json,yml}' && eslint src resources", "prettier": "prettier --ignore-path .gitignore --write '**/*.{js,ts,md,json,yml}'", "check": "flow check", "build": "rm -rf dist/* && babel src --ignore '**/__tests__' --out-dir dist && npm run build:flow", "build:flow": "find ./src -name '*.js' -not -path '*/__tests__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/dist\\//g'`.flow; done", - "watch": "node resources/watch.js", - "cover": "nyc npm run testonly", "preversion": "npm test", "start": "node -r @babel/register examples/index.js" }, diff --git a/resources/travis_after_all.py b/resources/travis_after_all.py deleted file mode 100644 index f813c8f9..00000000 --- a/resources/travis_after_all.py +++ /dev/null @@ -1,101 +0,0 @@ -""" -https://github.com/dmakhno/travis_after_all/blob/master/travis_after_all.py -""" - -import os -import json -import time -import logging - -try: - import urllib.request as urllib2 -except ImportError: - import urllib2 - -log = logging.getLogger("travis.leader") -log.addHandler(logging.StreamHandler()) -log.setLevel(logging.INFO) - -TRAVIS_JOB_NUMBER = 'TRAVIS_JOB_NUMBER' -TRAVIS_BUILD_ID = 'TRAVIS_BUILD_ID' -POLLING_INTERVAL = 'LEADER_POLLING_INTERVAL' - -build_id = os.getenv(TRAVIS_BUILD_ID) -polling_interval = int(os.getenv(POLLING_INTERVAL, '5')) - -#assume, first job is the leader -is_leader = lambda job_number: job_number.endswith('.1') - -if not os.getenv(TRAVIS_JOB_NUMBER): - # seems even for builds with only one job, this won't get here - log.fatal("Don't use defining leader for build without matrix") - exit(1) -elif is_leader(os.getenv(TRAVIS_JOB_NUMBER)): - log.info("This is a leader") -else: - #since python is subprocess, env variables are exported back via file - with open(".to_export_back", "w") as export_var: - export_var.write("BUILD_MINION=YES") - log.info("This is a minion") - exit(0) - - -class MatrixElement(object): - def __init__(self, json_raw): - self.is_finished = json_raw['finished_at'] is not None - self.is_succeeded = json_raw['result'] == 0 - self.number = json_raw['number'] - self.is_leader = is_leader(self.number) - - -def matrix_snapshot(): - """ - :return: Matrix List - """ - response = urllib2.build_opener().open("https://api.travis-ci.org/builds/{0}".format(build_id)).read() - raw_json = json.loads(response) - matrix_without_leader = [MatrixElement(element) for element in raw_json["matrix"]] - return matrix_without_leader - - -def wait_others_to_finish(): - def others_finished(): - """ - Dumps others to finish - Leader cannot finish, it is working now - :return: tuple(True or False, List of not finished jobs) - """ - snapshot = matrix_snapshot() - finished = [el.is_finished for el in snapshot if not el.is_leader] - return reduce(lambda a, b: a and b, finished), [el.number for el in snapshot if - not el.is_leader and not el.is_finished] - - while True: - finished, waiting_list = others_finished() - if finished: break - log.info("Leader waits for minions {0}...".format(waiting_list)) # just in case do not get "silence timeout" - time.sleep(polling_interval) - - -try: - wait_others_to_finish() - - final_snapshot = matrix_snapshot() - log.info("Final Results: {0}".format([(e.number, e.is_succeeded) for e in final_snapshot])) - - BUILD_AGGREGATE_STATUS = 'BUILD_AGGREGATE_STATUS' - others_snapshot = [el for el in final_snapshot if not el.is_leader] - if reduce(lambda a, b: a and b, [e.is_succeeded for e in others_snapshot]): - os.environ[BUILD_AGGREGATE_STATUS] = "others_succeeded" - elif reduce(lambda a, b: a and b, [not e.is_succeeded for e in others_snapshot]): - log.error("Others Failed") - os.environ[BUILD_AGGREGATE_STATUS] = "others_failed" - else: - log.warn("Others Unknown") - os.environ[BUILD_AGGREGATE_STATUS] = "unknown" - #since python is subprocess, env variables are exported back via file - with open(".to_export_back", "w") as export_var: - export_var.write("BUILD_LEADER=YES {0}={1}".format(BUILD_AGGREGATE_STATUS, os.environ[BUILD_AGGREGATE_STATUS])) - -except Exception as e: - log.fatal(e)