From 8af78ab9d4694c9b54409d47bdbb8bd4df35d122 Mon Sep 17 00:00:00 2001 From: "liyan@cryptape.com" Date: Tue, 26 May 2020 20:49:04 +0800 Subject: [PATCH] test travis streamline --- .travis.yml | 193 ++++------------------------- scripts/release_black2b.sh | 48 +++++++ scripts/release_multi_algorithm.sh | 94 ++++++++++++++ scripts/release_sha3.sh | 15 +++ scripts/release_sm2.sh | 46 +++++++ 5 files changed, 225 insertions(+), 171 deletions(-) create mode 100755 scripts/release_black2b.sh create mode 100755 scripts/release_multi_algorithm.sh create mode 100755 scripts/release_sha3.sh create mode 100755 scripts/release_sm2.sh diff --git a/.travis.yml b/.travis.yml index 0609162f..1e5c858f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,182 +1,33 @@ language: generic sudo: required cache: - timeout: 600 + timeout: 1024 directories: - - $TRAVIS_BUILD_DIR/target/debug - - /opt/.cargo/git - - /opt/.cargo/registry -services: - - docker -git: - depth: 1 + - "./docker/release" stages: - - CheckShell - - Release - - IntegrateTest +- secp256k1 +- sm2 +- blake2b before_install: - docker pull cita/cita-build:ubuntu-18.04-20191128 jobs: - include: - - - stage: CheckShell + include: + - stage: secp256k1 script: - # Fail if any of these files have warnings - - shellcheck scripts/*.sh env.sh - - - stage: Release - name: Release for Integrate Test - language: node_js - node_js: - # - lts/* - - 8.10.0 - cache: - directories: - - $TRAVIS_BUILD_DIR/target/release-cache - env: HASH_ALGO=sha3hash CRYPTO_ALGO=secp256k1 - before_script: - - cd $TRAVIS_BUILD_DIR - - ./scripts/replace_default_feature.sh ./ sha3hash ${HASH_ALGO} - - ./scripts/replace_default_feature.sh ./ secp256k1 ${CRYPTO_ALGO} - script: ./env.sh make release - before_cache: - - cd $TRAVIS_BUILD_DIR - - rm -rf target/release-cache - - mv -vf target/install target/release-cache - - - &stage-contract-test-sha3-secp256k1 - stage: IntegrateTest - name: Unit Group - language: node_js - node_js: - # - lts/* - - 8.10.0 - cache: - directories: - - $TRAVIS_BUILD_DIR/target/release-cache - env: HASH_ALGO=sha3hash CRYPTO_ALGO=secp256k1 - before_install: - - cd $TRAVIS_BUILD_DIR - - rm -rf target/install - - cp -rv target/release-cache target/install - install: - - rm -rf /opt/cita-run/test-chain - - cd $TRAVIS_BUILD_DIR/target/install - - ./bin/cita create - --nodes "127.0.0.1:4100" - --super_admin "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" - - ./bin/cita setup test-chain/0 - - ./bin/cita start test-chain/0 - before_script: - - cd $TRAVIS_BUILD_DIR/target/install/scripts/contracts/tests - - travis_retry yarn install - script: npm run-script unit_group - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Permission - script: npm run-script unit_permission - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Auth - script: npm run-script unit_auth - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Chain - script: npm run-script unit_chain - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Group Management - script: npm run-script unit_gm - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Permission Management - script: npm run-script unit_pm - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Role Management - script: npm run-script unit_rm - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Quota Management - script: npm run-script unit_qm - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Quota - script: npm run-script unit_quota - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Abi - script: npm run-script abi - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Admin - script: npm run-script unit_admin - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Store - script: npm run-script store - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Batch Tx - script: npm run-script batch_tx - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Uint8 - script: npm run-script uint8 - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit VersionManager - script: npm run-script unit_vm - - - <<: *stage-contract-test-sha3-secp256k1 - name: Unit Node - install: - - cd $TRAVIS_BUILD_DIR/target/install - - ./bin/cita create - --nodes "127.0.0.1:4000,127.0.0.1:4001,127.0.0.1:4002" - --super_admin "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" - - for i in {0..2} ; do - ./bin/cita setup test-chain/$i - && ./bin/cita start test-chain/$i ; - done + - "./scripts/release_sha3.sh" + - stage: sm2 script: - - npm run-script unit_node - - - <<: *stage-contract-test-sha3-secp256k1 - name: Integrate Quota - install: - - cd $TRAVIS_BUILD_DIR/target/install - - ./bin/cita create - --nodes "127.0.0.1:4100" - --contract_arguments "SysConfig.checkQuota=true" - --super_admin "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" - - ./bin/cita setup test-chain/0 - - ./bin/cita start test-chain/0 + - "./scripts/release_sm2.sh" + - stage: blake2b script: - - npm run-script integrate_quota - - - <<: *stage-contract-test-sha3-secp256k1 - name: Integrate Permission - install: - - cd $TRAVIS_BUILD_DIR/target/install - - ./bin/cita create - --nodes "127.0.0.1:4100" - --contract_arguments "SysConfig.checkCallPermission=true" - --super_admin "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" - - ./bin/cita setup test-chain/0 - - ./bin/cita start test-chain/0 - script: - - npm run-script permission - - - <<: *stage-contract-test-sha3-secp256k1 - name: Integrate AutoExec - install: - - cd $TRAVIS_BUILD_DIR/target/install - - ./bin/cita create - --nodes "127.0.0.1:4100" - --contract_arguments "SysConfig.autoExec=true" - --super_admin "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" - - ./bin/cita setup test-chain/0 - - ./bin/cita start test-chain/0 - script: - - npm run-script auto_exec - - - <<: *stage-contract-test-sha3-secp256k1 - name: Integrate Lifetime - install: - - cd $TRAVIS_BUILD_DIR/target/install - - ./bin/cita create - --nodes "127.0.0.1:4100" - --contract_arguments "SysConfig.economicalModel=1 PriceManager.quotaPrice=1" - --super_admin "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" - --init_token 0x1000000 - - ./bin/cita setup test-chain/0 - - ./bin/cita start test-chain/0 - script: - - npm run-script lifetime + - "./scripts/release_black2b.sh" +deploy: + provider: releases + api_key: + secure: UmH2AT2HhPBL3wkaFa5lCRnK5j1PbqeT7w4LpJ7LqS7/YakpIYlMLmLutEVH2Gu8tvhUHM7Wm2soHMWUgo08L+eN7RPeV6t2r6z/5N9aD4I+l7ki5W6XwwZ5kYcs05xuSFn6cJxyPHR4TeM1aZmJ+/ngKAUhdGr6f16z1XAt4HUvg/HKVOZRukbnHp3pKQeMuXYlMSJBsaAvyY64cwGnKQMngAnZJxEG7s/5LfJb3zrlfxm2gRSnvcvTjdfeYSk4kXaWvWVQXeNIwEjNkKu7/EnoaYr5hmylTGukA8lIMeDdmJClroBZeTESJLSZ0gLNIlX03PyM50IVMayKp16+aAf6IY0/CPFYZSCGtR6MyV4GpQBMHgNkNR+B6TtzR9N7CRoXtoKfK5Gb/sba3Y01koaFRwq6Fu0rjofl+u04R8JEMaBKzY/OgjK2nbhYReU63dRWEesFZOxVYhp9v9/Tv+0ZFluq9Aukn7c4ePs96YBaUgCVbtzCebyNx85t05C0RmXaB/EsX7VwXwoJltE8CGJ9A9ZuBusZsjupFNOxsqzrNzhfkro5BVp7jgBgSn0X9D2dx1PL6xNkMneLz5npyrcbshFXjOkMV9d0w9gMX543tQlfuVIBPmrGGFGqX2cRWADwoRKKfxVSoWrHR0RhQk8dF3pcVsmILS70PCoSqGI= + file: + - "./docker/release/cita_secp256k1_sha3.tar.gz" + - "./docker/release/cita_sm2_sm3.tar.gz" + - "./docker/release/cita_ed25519_blake2b.tar.gz" + on: + tags: true diff --git a/scripts/release_black2b.sh b/scripts/release_black2b.sh new file mode 100755 index 00000000..cc3029ab --- /dev/null +++ b/scripts/release_black2b.sh @@ -0,0 +1,48 @@ +#!/bin/bash +DIR=./docker/release +SOURCE_DIR=`pwd` +echo "pwd travis is " "$(pwd)" +git submodule init +git submodule update + +function replace_default_feature () { + local workspacedir="${1}" + local old_feature="${2}" + local new_feature="${3}" + if [ "${old_feature}" = "${new_feature}" ]; then + return + fi + local before_feature='[ \t]*default[ \t]*=[ \t]*\[.*\"' + local before_feature2='[ \t]*features[ \t]*=[ \t]*\[.*\"' + local all_feature='[ \t]*\(features\|default\)[ \t]*=[ \t]*\[.*\"' + local after_feature='\".*' + find "${workspacedir}" -mindepth 2 -name "Cargo.toml" -print0 \ + | xargs -0 grep -l "^${all_feature}${old_feature}${after_feature}" \ + | while read -r cargotoml; do + if [ -f "${cargotoml}" ]; then + echo "[Info ] Replace [${old_feature}] by [${new_feature}] for [${cargotoml}] ..." + sed -i "s/\(${before_feature}\)${old_feature}\(${after_feature}\)\$/\1${new_feature}\2/" "${cargotoml}" + sed -i "s/\(${before_feature2}\)${old_feature}\(${after_feature}\)\$/\1${new_feature}\2/" "${cargotoml}" + else + echo "[Error] [${cargotoml}] is not a file." + fi + done +} + +DEFAULT_HASH="sha3hash" +DEFAULT_CRYPT="secp256k1" + +# blake2b +SELECT_HASH_Blake2b="blake2bhash" +SELECT_CRYPT_Blake2b="ed25519" + +function replace_algorithm_blake2b() { + replace_default_feature "${SOURCE_DIR}" "${DEFAULT_HASH}" "${SELECT_HASH_Blake2b}" + replace_default_feature "${SOURCE_DIR}" "${DEFAULT_CRYPT}" "${SELECT_CRYPT_Blake2b}" +} + +replace_algorithm_blake2b +sudo rm -rf target +sudo ./env.sh make release > /dev/null +cp -r target/install $DIR/cita_ed25519_blake2b + diff --git a/scripts/release_multi_algorithm.sh b/scripts/release_multi_algorithm.sh new file mode 100755 index 00000000..5e29e704 --- /dev/null +++ b/scripts/release_multi_algorithm.sh @@ -0,0 +1,94 @@ +#!/bin/bash +DIR=./docker/release +SOURCE_DIR=`pwd` +echo "pwd travis is " "$(pwd)" +git submodule init +git submodule update + +function replace_default_feature () { + local workspacedir="${1}" + local old_feature="${2}" + local new_feature="${3}" + if [ "${old_feature}" = "${new_feature}" ]; then + return + fi + local before_feature='[ \t]*default[ \t]*=[ \t]*\[.*\"' + local before_feature2='[ \t]*features[ \t]*=[ \t]*\[.*\"' + local all_feature='[ \t]*\(features\|default\)[ \t]*=[ \t]*\[.*\"' + local after_feature='\".*' + find "${workspacedir}" -mindepth 2 -name "Cargo.toml" -print0 \ + | xargs -0 grep -l "^${all_feature}${old_feature}${after_feature}" \ + | while read -r cargotoml; do + if [ -f "${cargotoml}" ]; then + echo "[Info ] Replace [${old_feature}] by [${new_feature}] for [${cargotoml}] ..." + sed -i "s/\(${before_feature}\)${old_feature}\(${after_feature}\)\$/\1${new_feature}\2/" "${cargotoml}" + sed -i "s/\(${before_feature2}\)${old_feature}\(${after_feature}\)\$/\1${new_feature}\2/" "${cargotoml}" + else + echo "[Error] [${cargotoml}] is not a file." + fi + done +} + +# sha256 +sudo rm -rf target +sed -i "s/\"\${USE_TTY}\" \"\${CONTAINER_NAME}\"/\${USE_TTY} \${CONTAINER_NAME}/" ./env.sh +sudo ./env.sh make release + +cp -r target/install $DIR/cita_secp256k1_sha3 + +DEFAULT_HASH="sha3hash" +DEFAULT_CRYPT="secp256k1" + +# sm2 +SELECT_HASH_SM2="sm3hash" +SELECT_CRYPT_SM2="sm2" +function replace_algorithm_sm2() { + replace_default_feature "${SOURCE_DIR}" "${SELECT_HASH}" "${SELECT_HASH_SM2}" + replace_default_feature "${SOURCE_DIR}" "${SELECT_CRYPT}" "${SELECT_CRYPT_SM2}" +} +replace_algorithm_sm2 +sudo rm -rf target +sudo ./env.sh make release > /dev/null +cp -r target/install $DIR/cita_sm2_sm3 + + +# blake2b +SELECT_HASH_Blake2b="blake2bhash" +SELECT_CRYPT_Blake2b="ed25519" + +function replace_algorithm_blake2b() { + replace_default_feature "${SOURCE_DIR}" "${DEFAULT_HASH}" "${SELECT_HASH_Blake2b}" + replace_default_feature "${SOURCE_DIR}" "${DEFAULT_CRYPT}" "${SELECT_CRYPT_Blake2b}" +} + +replace_algorithm_blake2b +sudo rm -rf target +sudo ./env.sh make release > /dev/null +cp -r target/install $DIR/cita_ed25519_blake2b + +# tar.gz +cd $DIR +tar -zcf cita_secp256k1_sha3.tar.gz cita_secp256k1_sha3 +tar -zcf cita_sm2_sm3.tar.gz cita_sm2_sm3 +tar -zcf cita_ed25519_blake2b.tar.gz cita_ed25519_blake2b + +# build image +CITA_REPOSITORY_NAME=hhliyan/cli-test-20 +cat "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +docker push "$CITA_CLI_REPOSITORY_NAME":"$TRAVIS_TAG" + + +docker build . --build-arg ENCRYPTION_ALG=secp256k1 --build-arg HASH_ALG=sha3 -t $CITA_REPOSITORY_NAME:$TRAVIS_TAG-secp256k1-sha3 +docker push $CITA_REPOSITORY_NAME:$TRAVIS_TAG-secp256k1-sha3 + +docker build . --build-arg ENCRYPTION_ALG=sm2 --build-arg HASH_ALG=sm3 -t $CITA_REPOSITORY_NAME:$TRAVIS_TAG-sm2-sm3 +docker push $CITA_REPOSITORY_NAME:$TRAVIS_TAG-sm2-sm3 + + +docker build . --build-arg ENCRYPTION_ALG=ed25519 --build-arg HASH_ALG=blake2b -t $CITA_REPOSITORY_NAME:$TRAVIS_TAG-ed25519-blake2b +docker push $CITA_REPOSITORY_NAME:$TRAVIS_TAG-ed25519-blake2b + + + + + diff --git a/scripts/release_sha3.sh b/scripts/release_sha3.sh new file mode 100755 index 00000000..4b5e08ac --- /dev/null +++ b/scripts/release_sha3.sh @@ -0,0 +1,15 @@ + +#!/bin/bash +git submodule init +git submodule update + +DIR=./docker/release + +sudo rm -rf target + +sed -i "s/\"\${USE_TTY}\" \"\${CONTAINER_NAME}\"/\${USE_TTY} \${CONTAINER_NAME}/" ./env.sh +sudo ./env.sh make release + +cp -r target/install $DIR +cd $DIR +tar czvf cita_secp256k1_sha3.tar.gz cita_secp256k1_sha3 diff --git a/scripts/release_sm2.sh b/scripts/release_sm2.sh new file mode 100755 index 00000000..be64deb6 --- /dev/null +++ b/scripts/release_sm2.sh @@ -0,0 +1,46 @@ +#!/bin/bash +DIR=./docker/release +SOURCE_DIR=`pwd` +echo "pwd travis is " "$(pwd)" +git submodule init +git submodule update + +function replace_default_feature () { + local workspacedir="${1}" + local old_feature="${2}" + local new_feature="${3}" + if [ "${old_feature}" = "${new_feature}" ]; then + return + fi + local before_feature='[ \t]*default[ \t]*=[ \t]*\[.*\"' + local before_feature2='[ \t]*features[ \t]*=[ \t]*\[.*\"' + local all_feature='[ \t]*\(features\|default\)[ \t]*=[ \t]*\[.*\"' + local after_feature='\".*' + find "${workspacedir}" -mindepth 2 -name "Cargo.toml" -print0 \ + | xargs -0 grep -l "^${all_feature}${old_feature}${after_feature}" \ + | while read -r cargotoml; do + if [ -f "${cargotoml}" ]; then + echo "[Info ] Replace [${old_feature}] by [${new_feature}] for [${cargotoml}] ..." + sed -i "s/\(${before_feature}\)${old_feature}\(${after_feature}\)\$/\1${new_feature}\2/" "${cargotoml}" + sed -i "s/\(${before_feature2}\)${old_feature}\(${after_feature}\)\$/\1${new_feature}\2/" "${cargotoml}" + else + echo "[Error] [${cargotoml}] is not a file." + fi + done +} + + +DEFAULT_HASH="sha3hash" +DEFAULT_CRYPT="secp256k1" + +# sm2 +SELECT_HASH_SM2="sm3hash" +SELECT_CRYPT_SM2="sm2" +function replace_algorithm_sm2() { + replace_default_feature "${SOURCE_DIR}" "${SELECT_HASH}" "${SELECT_HASH_SM2}" + replace_default_feature "${SOURCE_DIR}" "${SELECT_CRYPT}" "${SELECT_CRYPT_SM2}" +} +replace_algorithm_sm2 +sudo rm -rf target +sudo ./env.sh make release > /dev/null +cp -r target/install $DIR/cita_sm2_sm3