Skip to content

Commit

Permalink
chore: Improve automated checks; NPM release scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Roberts <[email protected]>
  • Loading branch information
mttrbrts committed May 25, 2018
1 parent b768560 commit 93ff83e
Show file tree
Hide file tree
Showing 30 changed files with 3,902 additions and 9,909 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

.DS_Store

# Logs
Expand Down
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node_js:
dist: trusty
before_install: |
set -e
export PATH="./$HOME/node_modules/.bin:$PATH"
npm install -g @alrra/travis-scripts
date
install: |
set -e
Expand All @@ -12,6 +14,13 @@ install: |
lerna bootstrap 2>&1
date
script: lerna run test 2>&1
deploy:
provider: script
script:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./.travis/deploy.sh; fi'
skip_cleanup: true
on:
all_branches: true
after_failure: tail -n +1 -- /home/travis/.npm/_logs/*-debug.log
after_success: npm run coverage
deploy:
Expand All @@ -25,4 +34,4 @@ deploy:
cache:
directories:
- node_modules
services:
services:
59 changes: 59 additions & 0 deletions .travis/base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

## this is a script soley for inclusion in the main build scripts.
## Common functions that are executed both all types of builds

ME=`basename "$0"`
echo "-->-- Starting ${ME}"
echo "--I-- ${TRAVIS_TAG} ${TRAVIS_BRANCH}"

function _exit(){
printf "%s Exiting %s because %s exit code:%s\n" "--<--" "${ME}" "$1" "$2"
exit $2
}

function _abortBuild(){
echo "ABORT_BUILD=true" > ${DIR}/build.cfg
echo "ABORT_CODE=$1" >> ${DIR}/build.cfg
echo "BUILD_FOCUS=${BUILD_FOCUS}" >> ${DIR}/build.cfg
echo "BUILD_RELEASE=${BUILD_RELEASE}" >> ${DIR}/build.cfg
}

#check to see if the build.cfg file (that holds state between scripts)
if [ ! -f ${DIR}/build.cfg ]; then

echo "ABORT_BUILD=false" > ${DIR}/build.cfg
echo "ABORT_CODE=0" >> ${DIR}/build.cfg
## determine the build type here
if [ -z "${TRAVIS_TAG}" ]; then
BUILD_RELEASE="unstable"
BUILD_FOCUS="latest"
else
BUILD_RELEASE="stable"
BUILD_FOCUS="latest"
fi

echo "BUILD_FOCUS=${BUILD_FOCUS}" >> ${DIR}/build.cfg
echo "BUILD_RELEASE=${BUILD_RELEASE}" >> ${DIR}/build.cfg
fi

source ${DIR}/build.cfg

echo "--I-- Build focus is ${BUILD_FOCUS}"
echo "--I-- Build release is ${BUILD_RELEASE}"

if [ "${ABORT_BUILD}" == "true" ]; then
_exit "exiting early from" ${ABORT_CODE}
fi
15 changes: 15 additions & 0 deletions .travis/build.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ABORT_BUILD=true
105 changes: 105 additions & 0 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Script for the deploy phase, to push NPM modules, docker images and
# cloud playground images

# Exit on first error, print all commands.
set -ev
set -o pipefail

# Bring in the standard set of script utilities
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
source ${DIR}/.travis/base.sh

# ----

# Check that this is the main repository.
if [[ "${TRAVIS_REPO_SLUG}" != accordproject* ]]; then
_exit "Skipping deploy; wrong repository slug." 0
fi

# Check that this is the main repository.
if [[ "${TRAVIS_BRANCH}" != master ]]; then
_exit "Skipping deploy; Not a master branch build." 0
fi

## Start of release process

# Set the NPM access token we will use to publish.
npm config set registry https://registry.npmjs.org/
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}

# Set the GitHub deploy key we will use to publish.
set-up-ssh --key "$encrypted_50be70a02dcf_key" \
--iv "$encrypted_50be70a02dcf_iv" \
--path-encrypted-key ".travis/github_deploy_key.enc"

# Change from HTTPS to SSH.
./.travis/fix_github_https_repo.sh

# Test the GitHub deploy key.
git ls-remote

# Determine the details of the suffixes NPM tags
if [[ "${BUILD_RELEASE}" == "unstable" ]]; then

# Set the prerelease version.
npm run pkgstamp

TAG="unstable"
elif [[ "${BUILD_RELEASE}" == "stable" ]]; then
TAG="latest"
else
_exit "Unknown build focus" 1
fi

# Hold onto the version number
export VERSION=$(node -e "console.log(require('${DIR}/package.json').version)")

# Publish with tag
echo "Pushing with tag ${TAG}"
lerna exec -- npm publish --tag="${TAG}" 2>&1

# Check that all required modules have been published to npm and are retrievable
for j in ${NPM_MODULES}; do
# check the next in the list
while ! npm view ${j}@${VERSION} | grep dist-tags > /dev/null 2>&1; do
sleep 10
done
done

## Stable releases only; both latest and next then clean up git, and bump version number
if [[ "${BUILD_RELEASE}" = "stable" ]]; then

# Configure the Git repository and clean any untracked and unignored build files.
git config user.name "${GH_USER_NAME}"
git config user.email "${GH_USER_EMAIL}"
git checkout -b master
git reset --hard
git clean -d -f

# Bump the version number.
npm run pkgbump
export NEW_VERSION=$(node -e "console.log(require('${DIR}/package.json').version)")

# Add the version number changes and push them to Git.
git add .
git commit -m "Automatic version bump to ${NEW_VERSION}"
git push origin master

fi

_exit "All complete" 0
47 changes: 47 additions & 0 deletions .travis/fix_github_https_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password

REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi

USER=`echo $REPO_URL | sed -Ene's#https://github.com/([^/]*)/(.*).git#\1#p'`
if [ -z "$USER" ]; then
echo "-- ERROR: Could not identify User."
exit
fi

REPO=`echo $REPO_URL | sed -Ene's#https://github.com/([^/]*)/(.*).git#\2#p'`
if [ -z "$REPO" ]; then
echo "-- ERROR: Could not identify Repo."
exit
fi

NEW_URL="[email protected]:$USER/$REPO.git"
echo "Changing repo url from "
echo " '$REPO_URL'"
echo " to "
echo " '$NEW_URL'"
echo ""

CHANGE_CMD="git remote set-url origin $NEW_URL"
`$CHANGE_CMD`

echo "Success"
Binary file added .travis/github_deploy_key.enc
Binary file not shown.
14 changes: 14 additions & 0 deletions .travis/stable.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Exit on first error, print all commands.
set -ev
date
Expand Down
14 changes: 14 additions & 0 deletions .travis/unstable.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Exit on first error, print all commands.
set -ev
date
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline


**Note:** Version bump only for package cicero

## License <a name="license"></a>
Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,6 @@ from the main (upstream) repository:
[github-new-issue]: https://github.com/accordproject/cicero/issues/new
[github]: https://github.com/accordproject/cicero
[stackoverflow]: http://stackoverflow.com/questions/tagged/cicero
## License <a name="license"></a>
Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.
3 changes: 3 additions & 0 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ changes.

This means that since we generate the documentation from the source code, we can easily provide
version-specific documentation by simply checking out a version of Cicero and running the build.

## License <a name="license"></a>
Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.
Loading

0 comments on commit 93ff83e

Please sign in to comment.