|
| 1 | +version: 2.1 |
| 2 | + |
| 3 | +executors: |
| 4 | + test-executor: |
| 5 | + resource_class: xlarge |
| 6 | + machine: |
| 7 | + image: ubuntu-2004:202010-01 |
| 8 | + docker_layer_caching: true |
| 9 | + environment: |
| 10 | + IMAGE_NAME: chainsafe/pint |
| 11 | + CARGO_AUDIT: /home/circleci/.cargo/bin/cargo-audit |
| 12 | + RUSTC_WRAPPER: /home/circleci/.cargo/bin/sccache |
| 13 | + RUSTC_TOOLCHAIN: nightly-2021-04-18 |
| 14 | + SCCACHE_CACHE_SIZE: 5G |
| 15 | + |
| 16 | +commands: |
| 17 | + install_deps: |
| 18 | + steps: |
| 19 | + - run: |
| 20 | + name: Download Substrate Dependencies |
| 21 | + command: sudo apt-get update && sudo apt-get install -y git clang curl libssl-dev |
| 22 | + cargo_audit_setup: |
| 23 | + description: Install cargo-audit |
| 24 | + steps: |
| 25 | + - restore_cache: |
| 26 | + key: cargo-audit-{{ arch }} |
| 27 | + - run: |
| 28 | + name: Sets up cargo-audit |
| 29 | + command: | |
| 30 | + [[ ! -f ${CARGO_AUDIT} ]] && RUSTC_WRAPPER='' cargo install cargo-audit |
| 31 | + cargo audit --version |
| 32 | + - save_cache: |
| 33 | + key: cargo-audit-{{ arch }} |
| 34 | + paths: |
| 35 | + - ../.cargo/bin/cargo-audit |
| 36 | + sccache_setup: |
| 37 | + steps: |
| 38 | + - restore_cache: |
| 39 | + key: sccache-{{ arch }} |
| 40 | + - run: |
| 41 | + name: Sets up Sccache |
| 42 | + command: | |
| 43 | + [[ ! -f ${RUSTC_WRAPPER} ]] \ |
| 44 | + && curl -L https://github.com/mozilla/sccache/releases/download/\ |
| 45 | + v0.2.15/sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz \ |
| 46 | + | tar -zxvf - sccache-v0.2.15-x86_64-unknown-linux-musl/sccache \ |
| 47 | + && sudo mv sccache-v0.2.15-x86_64-unknown-linux-musl/sccache ${RUSTC_WRAPPER} \ |
| 48 | + && sudo chmod +x ${RUSTC_WRAPPER} |
| 49 | + sccache -s |
| 50 | + - save_cache: |
| 51 | + key: sccache-{{ arch }} |
| 52 | + paths: |
| 53 | + - ../.cargo/bin/sccache |
| 54 | + rust_setup: |
| 55 | + description: Sets up Rust Toolchain |
| 56 | + steps: |
| 57 | + - run: |
| 58 | + name: Sets up Rust Toolchain |
| 59 | + command: | |
| 60 | + curl https://sh.rustup.rs -sSf | sh -s -- -y \ |
| 61 | + --default-toolchain "$RUSTC_TOOLCHAIN" \ |
| 62 | + -c clippy rustfmt \ |
| 63 | + -t wasm32-unknown-unknown \ |
| 64 | + --profile minimal |
| 65 | + - restore_cache: |
| 66 | + key: cargo-package-cache-{{ checksum "Cargo.lock" }}-{{ arch }} |
| 67 | + - sccache_setup |
| 68 | + build_setup: |
| 69 | + description: Sets up environment for future jobs |
| 70 | + steps: |
| 71 | + - checkout |
| 72 | + - rust_setup |
| 73 | + - install_deps |
| 74 | + save_build_cache: |
| 75 | + description: Save cargo package cache for subsequent jobs |
| 76 | + steps: |
| 77 | + - save_cache: |
| 78 | + key: cargo-package-cache-{{ checksum "Cargo.lock" }}-{{ arch }} |
| 79 | + paths: |
| 80 | + - ../.cache/sccache |
| 81 | + - ../.cargo/git |
| 82 | + - ../.cargo/registry |
| 83 | + - ../.cargo/.package-cache |
| 84 | + login_dockerhub: |
| 85 | + description: Login DockerHub |
| 86 | + steps: |
| 87 | + - run: |
| 88 | + name: Login DockerHub |
| 89 | + command: echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin |
| 90 | + |
| 91 | +jobs: |
| 92 | + format: |
| 93 | + executor: test-executor |
| 94 | + description: Format Check |
| 95 | + steps: |
| 96 | + - checkout |
| 97 | + - rust_setup |
| 98 | + - run: |
| 99 | + name: Format check |
| 100 | + command: cargo fmt -- --check |
| 101 | + lint: |
| 102 | + executor: test-executor |
| 103 | + description: Lint Code |
| 104 | + steps: |
| 105 | + - build_setup |
| 106 | + - run: |
| 107 | + name: Clippy Check |
| 108 | + command: cargo clippy --all-targets |
| 109 | + - save_build_cache |
| 110 | + test: |
| 111 | + executor: test-executor |
| 112 | + description: Run tests |
| 113 | + steps: |
| 114 | + - build_setup |
| 115 | + - run: |
| 116 | + name: Run Tests |
| 117 | + command: cargo test --all |
| 118 | + - save_build_cache |
| 119 | + security: |
| 120 | + executor: test-executor |
| 121 | + description: Cargo audit |
| 122 | + steps: |
| 123 | + - checkout |
| 124 | + - rust_setup |
| 125 | + - cargo_audit_setup |
| 126 | + - run: |
| 127 | + name: Check for known security issues in dependencies |
| 128 | + command: cargo audit |
| 129 | + docker-build: |
| 130 | + executor: test-executor |
| 131 | + description: Build Docker Image |
| 132 | + steps: |
| 133 | + - checkout |
| 134 | + - run: |
| 135 | + name: Build docker image |
| 136 | + command: BUILDKIT_PROGRESS=plain DOCKER_BUILDKIT=1 docker build -t $IMAGE_NAME:latest . |
| 137 | + - run: |
| 138 | + name: Archive Docker image |
| 139 | + command: docker save -o image.tar $IMAGE_NAME |
| 140 | + - persist_to_workspace: |
| 141 | + root: . |
| 142 | + paths: |
| 143 | + - ./image.tar |
| 144 | + docker-publish-latest: |
| 145 | + executor: test-executor |
| 146 | + description: Publish latest Docker Image |
| 147 | + steps: |
| 148 | + - attach_workspace: |
| 149 | + at: /tmp/workspace |
| 150 | + - run: |
| 151 | + name: Load Archived Docker Image |
| 152 | + command: docker load -i /tmp/workspace/image.tar |
| 153 | + - login_dockerhub |
| 154 | + - run: |
| 155 | + name: Publish Latest Docker Image |
| 156 | + command: docker push $IMAGE_NAME:latest |
| 157 | + docker-publish-tag: |
| 158 | + executor: test-executor |
| 159 | + description: Publish Tagged Docker Image |
| 160 | + steps: |
| 161 | + - attach_workspace: |
| 162 | + at: /tmp/workspace |
| 163 | + - run: |
| 164 | + name: Load Archived Docker Image |
| 165 | + command: docker load -i /tmp/workspace/image.tar |
| 166 | + - login_dockerhub |
| 167 | + - run: |
| 168 | + name: Publish Tagged Docker Image |
| 169 | + command: | |
| 170 | + IMAGE_TAG=${CIRCLE_TAG/v/''} |
| 171 | + docker tag $IMAGE_NAME:latest $IMAGE_NAME:$IMAGE_TAG |
| 172 | + docker push $IMAGE_NAME:latest |
| 173 | + docker push $IMAGE_NAME:$IMAGE_TAG |
| 174 | +
|
| 175 | +workflows: |
| 176 | + test-code: |
| 177 | + jobs: |
| 178 | + - format |
| 179 | + - lint |
| 180 | + - test |
| 181 | + security: |
| 182 | + jobs: |
| 183 | + - security |
| 184 | + docker: |
| 185 | + jobs: |
| 186 | + - docker-build |
| 187 | + - docker-publish-latest: |
| 188 | + requires: |
| 189 | + - docker-build |
| 190 | + filters: |
| 191 | + branches: |
| 192 | + only: main |
| 193 | + - docker-publish-tag: |
| 194 | + requires: |
| 195 | + - docker-publish-latest |
| 196 | + filters: |
| 197 | + tags: |
| 198 | + only: /^v.*/ |
| 199 | + branches: |
| 200 | + only: main |
0 commit comments