From 1aaa16df2ee3d1245b0883560f7d109f814c0582 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sun, 7 Apr 2019 16:45:26 +0300 Subject: [PATCH] Automate deployment --- .travis.yml | 38 ++++++++++++++++++++++++++++++++------ package.json | 7 +++++-- scripts/travis-deploy.sh | 25 +++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 scripts/travis-deploy.sh diff --git a/.travis.yml b/.travis.yml index 22b8ff5e..e0023b00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,45 @@ +sudo: false +dist: trusty language: node_js + +# Support Active LTS versions of Node.js node_js: + - '8' - '10' +branches: + only: + - master + - /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + addons: - firefox: "latest" + chrome: stable + firefox: latest env: - MOZ_HEADLESS=1 -script: - - npm test - -install: - - npm install before_install: - echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc + +install: + - npm ci + before_script: + # Needed for Karma test runner + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start + - sleep 3 # give xvfb some time to start + +script: + - npm run check-package - npm run lint + - npm run test + +deploy: + - provider: script + skip_cleanup: true + script: bash scripts/travis-deploy.sh + on: + repo: dashevo/dapi-client + tags: true diff --git a/package.json b/package.json index 4399de24..485ba8f1 100644 --- a/package.json +++ b/package.json @@ -44,12 +44,15 @@ }, "scripts": { "build": "webpack --display-error-details", - "dashboard": "node ./poc/dashboard/index.js", "lint": "eslint .", "test": "npm run build && npm run test:node && npm run test:firefox", "test:node": "nyc --check-coverage --reporter=html --reporter=text --lines=83 --branches=63 --functions=70 mocha test/src --recursive", "test:firefox": "karma start ./karma.conf.js --browsers Firefox --single-run", - "test:integration": "mocha './test/integration/*.spec.js' --timeout 240000" + "test:integration": "mocha './test/integration/*.spec.js' --timeout 240000", + "check-package": "npm run check-package:name && npm run check-package:version", + "check-package:name": "test $(jq -r .name package.json) = $(jq -r .name package-lock.json)", + "check-package:version": "test $(jq -r .version package.json) = $(jq -r .version package-lock.json)", + "prepublishOnly": "npm run build" }, "author": "", "license": "MIT" diff --git a/scripts/travis-deploy.sh b/scripts/travis-deploy.sh new file mode 100644 index 00000000..9c729813 --- /dev/null +++ b/scripts/travis-deploy.sh @@ -0,0 +1,25 @@ +#! /bin/sh + +set -xe + +# Update this whenever the latest Node.js LTS version changes (~ every year). +# Do not forget to add this version to .travis.yml config also. +LATEST_LTS_VERSION="10" + +# We want this command to succeed whether or not the Node.js version is the +# latest (so that the build does not show as failed), but _only_ the latest +# should be used to publish the module. +if [[ "$TRAVIS_NODE_VERSION" != "$LATEST_LTS_VERSION" ]]; then + echo "Node.js v$TRAVIS_NODE_VERSION is not latest LTS version -- will not deploy with this version." + exit 0 +fi + +# Ensure the tag matches the one in package.json, otherwise abort. +PACKAGE_TAG=v"$(jq -r .version package.json)" +if [[ "$PACKAGE_TAG" != "$TRAVIS_TAG" ]]; then + echo "Travis tag (\"$TRAVIS_TAG\") is not equal to package.json tag (\"$PACKAGE_TAG\"). Please push a correct tag and try again." + exit 1 +fi + +# Now that checks have been passed, publish the module +npm publish