From b23de7c8ae33b62990e34c0f5b916cd4ce13e4d3 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 13 Jan 2019 17:07:18 +0700 Subject: [PATCH] New script and travis reference --- scripts/.travis.yml | 50 ++++++++++++++++++++++++ scripts/before_deploy_no_publish.sh | 60 +++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 scripts/.travis.yml create mode 100644 scripts/before_deploy_no_publish.sh diff --git a/scripts/.travis.yml b/scripts/.travis.yml new file mode 100644 index 0000000..2834c21 --- /dev/null +++ b/scripts/.travis.yml @@ -0,0 +1,50 @@ +language: node_js +dist: trusty +sudo: required + +stages: + - name: build-test + if: tag !~ ^release*$" + - name: release + if: tag =~ ^release*$" + +jobs: + include: + # Test that it builds correctly + ############################### + - stage: build-test + if: env(TRAVIS_TAG) != master + services: + - docker + script: + - docker-compose build + + # Deploy stage + # - code below is common between DAppNode packages + ################################################## + - stage: release + services: + - docker + script: skip + node_js: lts/* + before_deploy: + - wget https://raw.githubusercontent.com/dappnode/DAppNode/master/scripts/before_deploy.sh + - source before_deploy.sh + deploy: + provider: releases + prerelease: true + api_key: "$GITHUB_TOKEN" + file_glob: true + # $RELEASE_VERSION is exported on before_deploy.sh + file: build_${RELEASE_VERSION}/* + skip_cleanup: true + # $TRAVIS_TAG is exported on before_deploy.sh + name: "$TRAVIS_TAG" + body: "# Changelog" + on: + branch: master + tags: true + condition: "$TRAVIS_TAG =~ ^release*$" + after_deploy: + - wget https://raw.githubusercontent.com/dappnode/DAppNode/master/scripts/after_deploy.sh + - source after_deploy.sh diff --git a/scripts/before_deploy_no_publish.sh b/scripts/before_deploy_no_publish.sh new file mode 100644 index 0000000..6ca63de --- /dev/null +++ b/scripts/before_deploy_no_publish.sh @@ -0,0 +1,60 @@ +# > This script is designed to be run within a travis CI job, on the before_deploy step +# > The will do the following: +# 1. Configure the git user to dappnode +# 2. Correct origin modify tags and push branches +# 3. Remove current tag before creating the v0.X.Y tag. +# 4. Install and run the dappnodesdk +# 5. Compute the next version from the mainnet APM smart contract +# 6. Generate the release files running the dappnodesdk +# 7. Tag release with the correct version + +# > How to include the script in a .travis.yml +# jobs: +# include: +# - stage: release +# before_deploy: +# - wget -O - https://raw.githubusercontent.com/dappnode/DAppNode//before_deploy.sh | bash + +echo "Running DAppNode travis CI before_deploy.sh script" + +# 1. Configure the git user to dappnode +git config --global user.email "dappnode@dappnode.io" +git config --global user.name "dappnode" + +# 2. Correct origin modify tags and push branches +git remote rm origin +git remote add origin https://user:${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git + +# 3. Remove current tag before creating the v0.X.Y tag. Fail safe, catch errors with || +echo "Deleting previous tag $TRAVIS_TAG" +git push --delete origin $TRAVIS_TAG || echo "Error deleting previous tag $TRAVIS_TAG from origin" +git tag --delete $TRAVIS_TAG || echo "Error deleting previous tag $TRAVIS_TAG locally" + +# 4. Install the dappnodesdk +# `travis_retry` does not work in an external script. Also travis mentioned that it doesn't work on the deploy stage +npm install -g @dappnode/dappnodesdk + +# 5. Compute the next version from the mainnet APM smart contract +export RELEASE_VERSION=$(dappnodesdk next patch -p infura) +export TRAVIS_TAG="v${RELEASE_VERSION}" +echo "NEXT TRAVIS_TAG $TRAVIS_TAG" + +# 6. Generate the release files running the dappnodesdk +# The DNP_ETHCHAIN takes > 60 min to build. This command triggers a timeout and should be run directly from the travis yml to prevent it. +# dappnodesdk publish patch -p infura + +# 7. Tag release with the correct version +# (7.) Check if the tag exists, if so delete it. Fail safe, catch errors with || +if [ $(git tag -l "$TRAVIS_TAG") ]; then export DELETE_TAG=true ; fi +if [ $DELETE_TAG ]; then git push --delete origin $TRAVIS_TAG || echo "Error deleting tag $TRAVIS_TAG from origin" ; fi +if [ $DELETE_TAG ]; then git tag --delete $TRAVIS_TAG || echo "Error deleting tag $TRAVIS_TAG locally" ; fi +# (7.) Tag this commit +git tag $TRAVIS_TAG +# (7.) Return to master. +# When travis is triggered by a tag this error happens: +# > error: pathspec 'master' did not match any file(s) known to git. +# A `git fetch` will be run to ensure that the master branch is present +git fetch +git checkout master + +echo "Successfully completed DAppNode travis CI before_deploy.sh script"