Skip to content

Commit

Permalink
Implement internal CLI for per-PR NPM and Docker Hub publishing
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Klenik <[email protected]>
  • Loading branch information
aklenik committed Feb 5, 2020
1 parent aa99bed commit d54a70a
Show file tree
Hide file tree
Showing 34 changed files with 946 additions and 377 deletions.
18 changes: 5 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ env:
jobs:
include:
- stage: checks and unit tests
name: Show various information about the CI build
script: ./.travis/build-info.sh
- name: Package name check, license check, lint check, unit tests
name: Package name check, license check, lint check, unit tests
if: type = pull_request
script: ./.travis/checks-and-unit-tests.sh

Expand All @@ -50,17 +48,11 @@ jobs:
if: type = pull_request
script: BENCHMARK=generator ./.travis/benchmark-integration-test-direct.sh

# publish npm packages
- stage: npm publish
name: Publishing to NPM
# publish packages
- stage: publish
name: Publishing to NPM and Docker Hub
if: type = push
script: ./.travis/npm-publish.sh

# publish docker image
- stage: docker publish
name: Publishing to Docker Hub
if: type = push
script: ./.travis/docker-publish.sh
script: ./.travis/publish.sh

cache:
directories:
Expand Down
51 changes: 0 additions & 51 deletions .travis/benchmark-integration-test-verdaccio.sh

This file was deleted.

45 changes: 0 additions & 45 deletions .travis/build-info.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .travis/checks-and-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -o pipefail

# check reference Caliper package names
# publishNpmPackages.js contains the package dir names as caliper-*, those are fine
if grep -rnE --exclude="publishNpmPackages.js" "['\"]caliper-(cli|core|burrow|composer|ethereum|fabric|fisco-bcos|iroha|sawtooth)['\"]" . ; then
if grep -rnE --exclude-dir="caliper-publish" "['\"]caliper-(cli|core|burrow|composer|ethereum|fabric|fisco-bcos|iroha|sawtooth)['\"]" . ; then
echo "^^^ Found incorrect Caliper package names. Use the @hyperledger/ prefix for Caliper packages, e.g., @hyperledger/caliper-core"
exit 1
fi
Expand Down
24 changes: 3 additions & 21 deletions .travis/npm-publish.sh → .travis/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,7 @@
# Exit on first error
set -e

if [[ -z "${NPM_TOKEN}" ]]
then
echo "ERROR: No decrypted NPM_TOKEN variable detected"
exit 1
fi

# 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}

if grep '"version": ".*\-unstable",$' ./package.json
then
export DIST_TAG=unstable
else
export DIST_TAG=latest
fi

# Only install lerna, other package deps are not needed for publishing
cd ./packages/caliper-publish/
npm i

# publish through lerna
npm run publish_npm
./publish.js npm
./publish.js docker --user klenik --publish
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"packages/caliper-iroha",
"packages/caliper-sawtooth",
"packages/caliper-cli",
"packages/caliper-publish",
"packages/caliper-tests-integration"
],
"version": "0.3.0-unstable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
# limitations under the License.
#

*.log
.pm2/*
scripts/*
lib/*
node_modules/*
log/*
fabric_tests/*
besu_tests/*
ethereum_tests/*
fisco-bcos_tests/*
sawtooth_tests/*
.pm2/*
.storage/*
.editorconfig
.eslintignore
.eslintrc.yml
.gitignore
caliper.Dockerfile
package.json
run-tests.sh
package-lock.json
publish.js
README.md
26 changes: 26 additions & 0 deletions packages/caliper-publish/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# 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.
#

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
16 changes: 16 additions & 0 deletions packages/caliper-publish/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# 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.
#

coverage
node_modules
48 changes: 48 additions & 0 deletions packages/caliper-publish/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
env:
es6: true
node: true
mocha: true
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 2018
sourceType:
- script
rules:
indent:
- error
- 4
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
no-unused-vars:
- error
- args: none
no-console: off
curly: error
eqeqeq: error
no-throw-literal: error
strict: error
no-var: error
dot-notation: error
no-tabs: error
no-trailing-spaces: error
no-use-before-define: error
no-useless-call: error
no-with: error
operator-linebreak: error
require-jsdoc:
- error
- require:
ClassDeclaration: true
MethodDefinition: true
FunctionDeclaration: true
valid-jsdoc:
- error
- requireReturn: false
yoda: error
39 changes: 39 additions & 0 deletions packages/caliper-publish/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
*.bak

# Ignore any generated html files
*.html

# Ignore DS_Store files from Mac
**.DS_Store

architecture.pptx
output.log
lerna-debug.log

# Ignore zookeeper files
zookeeper.out

# We prefer to not use lock files
**/package-lock.json

.idea/
**/node_modules/
**/log/

# Ignore code coverage logs
**/.nyc_output/
**/coverage/

# Ignore IDE files
.vscode/

# Website files
.sass-cache/
Gemfile.lock
_site/

# verdaccio files
**/storage

# pm2 files
**/.pm2/
23 changes: 23 additions & 0 deletions packages/caliper-publish/artifacts/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/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.
#

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

# Set ARCH
ARCH=`uname -m`

docker build --network=host -t "${IMAGE}:${TAG}" -f caliper.Dockerfile --build-arg "caliper_version=${TAG}" --build-arg "npm_registry=${NPM_REGISTRY}" .
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ set -e

if [[ -z "${DOCKER_TOKEN}" ]]
then
echo "ERROR: No decrypted DOCKER_TOKEN variable detected"
echo "ERROR: No DOCKER_TOKEN variable detected"
exit 1
fi

# login to docker with secret token
echo ${DOCKER_TOKEN} | docker login -u klenik --password-stdin

cd ./packages/caliper-tests-integration/
./scripts/buildDockerImage.js
echo ${DOCKER_TOKEN} | docker login -u ${DOCKER_USER} --password-stdin
docker push ${IMAGE}:${TAG}
Loading

0 comments on commit d54a70a

Please sign in to comment.