Skip to content

Commit

Permalink
Merge pull request #60 from dappnode/fix_scripts
Browse files Browse the repository at this point in the history
New script and travis reference
  • Loading branch information
eduadiez authored Jan 16, 2019
2 parents eeaa5e6 + dfdfc6f commit 3bc73e2
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 7 deletions.
54 changes: 54 additions & 0 deletions scripts/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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
name: build-test
services:
- docker
script:
- docker-compose build

# Deploy stage
# - code below is common between DAppNode packages
##################################################
- stage: release
name: release
services:
- docker
script:
- npm install -g @dappnode/dappnodesdk
- docker-compose build
- dappnodesdk publish patch -p infura
node_js: lts/*
before_deploy:
- wget https://raw.githubusercontent.com/dappnode/DAppNode/master/scripts/before_deploy_no_publish.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
11 changes: 4 additions & 7 deletions scripts/before_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ 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
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 ||
# 6. Tag release with the correct version
# (6.) 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
# (6.) Tag this commit
git tag $TRAVIS_TAG
# (7.) Return to master.
# (6.) 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
Expand Down
56 changes: 56 additions & 0 deletions scripts/before_deploy_no_publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# > 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/<path-to-script>/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. Tag release with the correct version
# (6.) 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
# (6.) Tag this commit
git tag $TRAVIS_TAG
# (6.) 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"

0 comments on commit 3bc73e2

Please sign in to comment.