|
| 1 | +version: 2.1 |
| 2 | +commands: |
| 3 | + install-rust: |
| 4 | + steps: |
| 5 | + - run: |
| 6 | + name: Install Rust |
| 7 | + command: | |
| 8 | + sudo apt-get update |
| 9 | + sudo apt-get -y install apt-utils cmake pkg-config libssl-dev git llvm clang |
| 10 | + if [ ! -d /home/circleci/.cargo ]; then |
| 11 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |
| 12 | + fi |
| 13 | + source ~/.cargo/env |
| 14 | + rustup install $RUST_VERSION |
| 15 | + rustup default $RUST_VERSION |
| 16 | + rustup install nightly-2020-04-17 |
| 17 | + rustup target add wasm32-unknown-unknown --toolchain=nightly-2020-04-17 |
| 18 | + rustup target add x86_64-unknown-linux-musl --toolchain=$RUST_VERSION |
| 19 | + export RUSTC_WRAPPER="" # sccache is uninstalled at this point so it must be unset here for `wasm-gc` install |
| 20 | + command -v wasm-gc || cargo install --git https://github.com/alexcrichton/wasm-gc --force |
| 21 | + rustc --version; cargo --version; rustup --version |
| 22 | + install-sccache: |
| 23 | + steps: |
| 24 | + - run: |
| 25 | + name: Install sccache |
| 26 | + command: | |
| 27 | + curl -L https://github.com/mozilla/sccache/releases/download/0.2.10/sccache-0.2.10-x86_64-unknown-linux-musl.tar.gz | tar -xz |
| 28 | + chmod +x sccache-0.2.10-x86_64-unknown-linux-musl/sccache |
| 29 | + mv sccache-0.2.10-x86_64-unknown-linux-musl/sccache ~/.cargo/bin/sccache |
| 30 | + sccache --version |
| 31 | + restore-cache: |
| 32 | + steps: |
| 33 | + - restore_cache: |
| 34 | + name: Restore sccache |
| 35 | + key: sccache-{{ arch }}-{{ .Environment.RUST_VERSION }}-{{ .Environment.CIRCLE_JOB }} |
| 36 | + save-cache: |
| 37 | + steps: |
| 38 | + - save_cache: |
| 39 | + name: Save sccache |
| 40 | + # We use {{ epoch }} to always upload a fresh cache: |
| 41 | + # Of course, restore_cache will not find this exact key, |
| 42 | + # but it will fall back to the closest key (aka the most recent). |
| 43 | + # See https://discuss.circleci.com/t/add-mechanism-to-update-existing-cache-key/9014/13 |
| 44 | + key: sccache-{{ arch }}-{{ .Environment.RUST_VERSION }}-{{ .Environment.CIRCLE_JOB }}-{{ epoch }} |
| 45 | + paths: |
| 46 | + - "~/.cache/sccache" |
| 47 | + cargo-check: |
| 48 | + steps: |
| 49 | + - run: |
| 50 | + name: Build |
| 51 | + command: | |
| 52 | + cargo --version |
| 53 | + cargo check |
| 54 | + no_output_timeout: 30m |
| 55 | + cargo-build-test: |
| 56 | + steps: |
| 57 | + - run: |
| 58 | + command: cargo test --no-run --release --all |
| 59 | + no_output_timeout: 30m |
| 60 | + cargo-run-test: |
| 61 | + steps: |
| 62 | + - run: |
| 63 | + command: |
| 64 | + cargo --version |
| 65 | + cargo test --release --all |
| 66 | + no_output_timeout: 30m |
| 67 | +jobs: |
| 68 | + build: |
| 69 | + machine: |
| 70 | + image: ubuntu-1604:201903-01 |
| 71 | + steps: |
| 72 | + - run: echo "successfully built and tested" |
| 73 | + build-bin: |
| 74 | + machine: |
| 75 | + image: ubuntu-1604:201903-01 |
| 76 | + resource_class: large |
| 77 | + environment: |
| 78 | + BASH_ENV: ~/.cargo/env |
| 79 | + RUST_VERSION: 1.44.1 |
| 80 | + RUSTC_WRAPPER: sccache |
| 81 | + SCCACHE_CACHE_SIZE: 10G |
| 82 | + steps: |
| 83 | + - checkout |
| 84 | + - install-rust |
| 85 | + - install-sccache |
| 86 | + - restore-cache |
| 87 | + - cargo-check |
| 88 | + - save-cache |
| 89 | + build-test-and-run: |
| 90 | + machine: |
| 91 | + image: ubuntu-1604:201903-01 |
| 92 | + resource_class: large |
| 93 | + environment: |
| 94 | + BASH_ENV: ~/.cargo/env |
| 95 | + RUST_VERSION: 1.44.1 |
| 96 | + RUSTC_WRAPPER: sccache |
| 97 | + SCCACHE_CACHE_SIZE: 10G |
| 98 | + steps: |
| 99 | + - checkout |
| 100 | + - install-rust |
| 101 | + - install-sccache |
| 102 | + - restore-cache |
| 103 | + - cargo-build-test |
| 104 | + - save-cache |
| 105 | + - cargo-run-test |
| 106 | + publish-docker: |
| 107 | + machine: |
| 108 | + image: ubuntu-1604:201903-01 |
| 109 | + steps: |
| 110 | + - checkout |
| 111 | + - run: |
| 112 | + name: Build and publish Docker image |
| 113 | + command: | |
| 114 | + docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD |
| 115 | + if [ -z "${CIRCLE_TAG}" ]; then |
| 116 | + GIT_SHORT="${CIRCLE_SHA1:0:8}" |
| 117 | + if [ "${CIRCLE_BRANCH}" == "develop" ]; then |
| 118 | + VERSION="latest" |
| 119 | + else |
| 120 | + VERSION="${CIRCLE_BRANCH////-}" |
| 121 | + fi |
| 122 | + DOCKER_TAG="$VERSION-$GIT_SHORT" |
| 123 | + else |
| 124 | + DOCKER_TAG="${CIRCLE_TAG}" |
| 125 | + fi |
| 126 | + docker build --pull -t plugnet/plugblockchain:$DOCKER_TAG -f ./.maintain/Dockerfile . |
| 127 | + docker push plugnet/plugblockchain:$DOCKER_TAG |
| 128 | + no_output_timeout: 60m |
| 129 | +workflows: |
| 130 | + version: 2 |
| 131 | + build-test-publish: |
| 132 | + jobs: |
| 133 | + - build-bin |
| 134 | + - build-test-and-run |
| 135 | + - build: |
| 136 | + requires: |
| 137 | + - build-bin |
| 138 | + - build-test-and-run |
| 139 | + - publish-docker: |
| 140 | + requires: |
| 141 | + - build |
| 142 | + filters: |
| 143 | + branches: |
| 144 | + only: |
| 145 | + - /^[0-9]+[.][0-9]+[.][0-9]+(-rc[0-9]+)*$/ |
| 146 | + - master |
0 commit comments