From 6abdfd957d07337b86e0ba3aafb1e219e1083665 Mon Sep 17 00:00:00 2001 From: Anton Drukh Date: Sun, 5 Aug 2018 14:41:12 +0300 Subject: [PATCH] chore: upgrade semantic-release, proper travis & appveyor setup --- .travis.yml | 35 ++++----- appveyor.yml | 2 +- package.json | 14 +--- scripts/test-vulns.sh | 21 ------ scripts/travis_after_all.py | 122 -------------------------------- scripts/travis_after_success.sh | 13 ++++ 6 files changed, 33 insertions(+), 174 deletions(-) delete mode 100755 scripts/test-vulns.sh delete mode 100644 scripts/travis_after_all.py diff --git a/.travis.yml b/.travis.yml index 738af8237f..199455606b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ sudo: false language: node_js +node_js: + - "8" + - "6" + - "4" cache: directories: - node_modules @@ -11,26 +15,23 @@ notifications: on_pull_requests: false rooms: secure: mWzYwXXkaPJ/t24kG9gz6hYyRGoGX+zsjKDa+IzjhY4NeMJyzgHyN3x1vWwSXhfG1jQuBTFyT5RTWN8Jfo2Za/XDKYfMXXP5gCMtNkeWdflYWaUC7sAZepRANUB3gzkCTvkc/DOY/FI07xCcLMJoZ7jGiADNakTaWvzdExJUBs6NuhGdIUmOT+chbip02yN7mSPeqyU7/vFqpCxxEoPeNzaNshLufbZUEWgmLm0bm5Uxdo7Yi5rL0/nA7oqXUzzWTtgQEu0mOG4Oqu7oXAki2rLISw8enZwt5/fUbxGgK1J3UB86vgnDrxbTAhuNUuddaSxUuDsg1+3xyRzU74cyKUWnWqL10Tyy9KgDR0A+48w2v8DH/pOvnvfXA+FL0zLtDJ9jPuSK0dFbceRYmolEGMDF53Q/s2W+waC13Bi3nHRQJKYmT+bOnoLABLpfm5fbV/2br4LVTQwiP80HJ+19Vy4lriF55zu1yjESUBzdvvX1Dhp5E3AXZZv6xB0v4gyZZeOoIv6BxqinLauZiS3nM7O9vu1QnFvbo4HH0Df651fyy1kOU5UAAD+CNRgpZ8GMc+EegvnLbS3nzbNOPlkACmhxMNcpEvD6MomcB4UV2dPWAYIQSfrRV5h+iZlNSqCkA2pl3p6TTZhLMvoSxziRzUZZx7GQe/cnUGN6GbzyyRk= -matrix: - include: - - node_js: "8" - - node_js: "6" - - node_js: "4" -before_install: - # tests are failing on npm@5, remove this once this is not an issue - - npm i -g npm@^3.0.0 before_script: - npm prune script: - npm run snyk-auth + # tests are failing on npm@5, downgrade to npm@3 if >3 is installed + - test "$(npm -v | cut -d'.' -f1)" -le 3 || npm i -g npm@^3.0.0 - npm test -after_success: - - npm run travis-coverage - - python scripts/travis_after_all.py - - export $(cat .to_export_back) - - npm run semantic-release - - bash scripts/travis_after_success.sh +jobs: + include: + - stage: Release + node_js: "8" + script: + # run only if this is a 'push' build + # 1. grab and run semantic-release + # (not used as a dev dep because it pulls in new `npm` and breaks our tests) + # 2. run post-release actions + - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then npx semantic-release && bash scripts/travis_after_success.sh; fi' branches: - except: - - "/^v\\d+\\.\\d+\\.\\d+$/" - - /^released-/ + only: + - "master" diff --git a/appveyor.yml b/appveyor.yml index e4fb11000f..8db87ccbdc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -47,4 +47,4 @@ install: # Post-install test scripts. test_script: - npm run snyk-auth-windows - - npm run windows-tests + - npm run tap diff --git a/package.json b/package.json index a03d4ed839..6bc21b2239 100644 --- a/package.json +++ b/package.json @@ -12,14 +12,11 @@ "node": ">=4" }, "scripts": { - "coverage": "tap --cov --coverage-report=lcov test/*.test.js", - "tap": "COVERALLS_REPO_TOKEN=0 tap --timeout=180 --cov --coverage-report=text-summary test/*.test.js", + "tap": "tap test/*.test.js -R spec --timeout=180", "test": "npm run test-common && npm run tap", "test-common": "npm run check-tests && npm run lint && node cli/index.js test --org=snyk", - "windows-tests": "tap -R spec test/*.test.js --timeout=120", "lint": "jscs `find ./cli -name '*.js'` -v && jscs `find ./lib -name '*.js'` -v", "check-tests": "! grep 'test\\.only' test/*.test.js -n", - "semantic-release": "semantic-release pre && npm publish && semantic-release post", "snyk-auth": "node cli auth $SNYK_API_KEY", "snyk-auth-windows": "node cli auth %SNYK_API_KEY%" }, @@ -70,7 +67,6 @@ "nock": "^9.2.5", "proxyquire": "^1.7.4", "restify": "^4.1.1", - "semantic-release": "^8", "sinon": "^1.17.2", "strip-ansi": "^4.0.0", "tap": "^5.7.1", @@ -81,14 +77,6 @@ "type": "git", "url": "https://github.com/snyk/snyk.git" }, - "nyc": { - "exclude": [ - "test", - "test{,-*}.js", - "**/*.test.js", - "**/__tests__/**" - ] - }, "pkg": { "scripts": [ "cli/**/*.js", diff --git a/scripts/test-vulns.sh b/scripts/test-vulns.sh deleted file mode 100755 index b9d79f4e25..0000000000 --- a/scripts/test-vulns.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -server=$@ -snyk -v - -case "$server" in -dev) - server='https://dev.snyk.io' - ;; -staging) - server='https://staging.snyk.io' - ;; -local) - server='http://localhost:8000' - ;; -*) - server='https://snyk.io' - ;; -esac - -SNYK_API=$server/api snyk test @remy/snyk-shrink-test @snyk/module@1.0.0 @snyk/module express@4.x express@latest express jsbin/jsbin | tail -1 \ No newline at end of file diff --git a/scripts/travis_after_all.py b/scripts/travis_after_all.py deleted file mode 100644 index a029d3dd4a..0000000000 --- a/scripts/travis_after_all.py +++ /dev/null @@ -1,122 +0,0 @@ -import os -import sys -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' -GITHUB_TOKEN = 'GITHUB_TOKEN' - - -# Travis API entry point, there are at least https://api.travis-ci.com and https://api.travis-ci.org -travis_entry = sys.argv[1] if len(sys.argv) > 1 else 'https://api.travis-ci.org' - -build_id = os.getenv(TRAVIS_BUILD_ID) -polling_interval = int(os.getenv(POLLING_INTERVAL, '5')) -gh_token = os.getenv(GITHUB_TOKEN) - -# assume, first job is the leader -is_leader = lambda job_number: job_number.endswith('.1') - -job_number = os.getenv(TRAVIS_JOB_NUMBER) - -if not 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(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(travis_token): - """ - :return: Matrix List - """ - headers = {'content-type': 'application/json', 'Authorization': 'token {}'.format(travis_token)} - req = urllib2.Request("{0}/builds/{1}".format(travis_entry, build_id), headers=headers) - response = urllib2.urlopen(req).read() - raw_json = json.loads(response) - matrix_without_leader = [MatrixElement(job) for job in raw_json["matrix"] if not is_leader(job['number'])] - return matrix_without_leader - - -def wait_others_to_finish(travis_token): - 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(travis_token) - finished = [job.is_finished for job in snapshot if not job.is_leader] - return reduce(lambda a, b: a and b, finished), [job.number for job in snapshot if - not job.is_leader and not job.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) - - -def get_token(): - assert gh_token, 'GITHUB_TOKEN is not set' - data = {"github_token": gh_token} - headers = {'content-type': 'application/json'} - - req = urllib2.Request("{0}/auth/github".format(travis_entry), json.dumps(data), headers) - response = urllib2.urlopen(req).read() - travis_token = json.loads(response).get('access_token') - - return travis_token - - -try: - token = get_token() - wait_others_to_finish(token) - - final_snapshot = matrix_snapshot(token) - 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) diff --git a/scripts/travis_after_success.sh b/scripts/travis_after_success.sh index 21ecc27a2a..f93d49817d 100644 --- a/scripts/travis_after_success.sh +++ b/scripts/travis_after_success.sh @@ -1,5 +1,6 @@ #!/bin/bash +# trigger external services into post-release action if [ "$TRAVIS_BRANCH" = "master" ]; then # manually detect master branch push, and post a dockerhub trigger to build the docker images curl -s -H "Content-Type: application/json" --data "{\"build\": true}" -X POST "https://registry.hub.docker.com/u/snyk/snyk-cli/trigger/${DOCKER_TOKEN}/" @@ -10,3 +11,15 @@ if [ "$TRAVIS_BRANCH" = "master" ]; then curl "https://g.codefresh.io/api/builds/$GRADLE28_BUILD_ID" -H "content-type:application/json; charset=utf-8" -H "x-access-token: $CF_ACCESS_TOKEN" --data-binary "{\"repoOwner\":\"snyk\",\"repoName\":\"snyk\",\"serviceId\":\"$GRADLE28_BUILD_ID\",\"branch\":\"master\",\"type\":\"build\"}" --compressed curl "https://g.codefresh.io/api/builds/$GRADLE44_BUILD_ID" -H "content-type:application/json; charset=utf-8" -H "x-access-token: $CF_ACCESS_TOKEN" --data-binary "{\"repoOwner\":\"snyk\",\"repoName\":\"snyk\",\"serviceId\":\"$GRADLE44_BUILD_ID\",\"branch\":\"master\",\"type\":\"build\"}" --compressed fi + +# grab latest version and publish its assets +npm i -g snyk # must install to get the proper `version` key +cd $(dirname $(which snyk))/../lib/node_modules/snyk + +npx pkg . # create standalone binaries based on the latest `pkg` + +export SNYK_VERSION=$(./cli/index.js -v) + +# upload assets built by `pkg` +# GH_TOKEN is set as Travis env var +GITHUB_TOKEN=$GH_TOKEN npx github-release upload --owner snyk --repo snyk --tag "v${SNYK_VERSION}" --name "v${SNYK_VERSION}" ./snyk-linux ./snyk-macos ./snyk-win.exe