|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + |
| 7 | +jobs: |
| 8 | + backend: |
| 9 | + name: Backend |
| 10 | + runs-on: ubuntu-18.04 |
| 11 | + strategy: |
| 12 | + # TODO: [ci] should be true if GitHub Actions supports ""allow failures" on matrix |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + rust: |
| 16 | + - stable |
| 17 | + - beta |
| 18 | + - nightly |
| 19 | + |
| 20 | + env: |
| 21 | + CARGO_INCREMENTAL: 0 |
| 22 | + RUSTFLAGS: "-C debuginfo=0 -D warnings" |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v2-beta |
| 26 | + |
| 27 | + - name: Cleanup pre-installed Rust toolchains |
| 28 | + # The pre-installed toolchain is under root permission, and this would |
| 29 | + # make tarball fail to extract. Here we remove the symlink and install |
| 30 | + # our own Rust toolchain if necessary. |
| 31 | + run: | |
| 32 | + which rustup |
| 33 | + which cargo |
| 34 | + if [[ -L "$HOME/.cargo" && -L "$HOME/.rustup" ]]; then |
| 35 | + rm -v "$HOME/.rustup" |
| 36 | + rm -v "$HOME/.cargo" |
| 37 | + fi |
| 38 | + echo "::add-path::$HOME/.cargo/bin" |
| 39 | +
|
| 40 | + - name: Dump GitHub context |
| 41 | + env: |
| 42 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 43 | + run: echo "$GITHUB_CONTEXT" |
| 44 | + - name: Dump job context |
| 45 | + env: |
| 46 | + JOB_CONTEXT: ${{ toJson(job) }} |
| 47 | + run: echo "$JOB_CONTEXT" |
| 48 | + - name: Dump steps context |
| 49 | + env: |
| 50 | + STEPS_CONTEXT: ${{ toJson(steps) }} |
| 51 | + run: echo "$STEPS_CONTEXT" |
| 52 | + - name: Dump runner context |
| 53 | + env: |
| 54 | + RUNNER_CONTEXT: ${{ toJson(runner) }} |
| 55 | + run: echo "$RUNNER_CONTEXT" |
| 56 | + - name: Dump strategy context |
| 57 | + env: |
| 58 | + STRATEGY_CONTEXT: ${{ toJson(strategy) }} |
| 59 | + run: echo "$STRATEGY_CONTEXT" |
| 60 | + - name: Dump matrix context |
| 61 | + env: |
| 62 | + MATRIX_CONTEXT: ${{ toJson(matrix) }} |
| 63 | + run: echo "$MATRIX_CONTEXT" |
| 64 | + |
| 65 | + - name: Cache rustup |
| 66 | + uses: actions/cache@v1 |
| 67 | + with: |
| 68 | + path: ~/.rustup |
| 69 | + key: ${{ runner.os }}-rustup-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }} |
| 70 | + restore-key: | |
| 71 | + ${{ runner.os }}-rustup-${{ matrix.rust }}- |
| 72 | +
|
| 73 | + - name: Cache cargo registry cache |
| 74 | + uses: actions/cache@v1 |
| 75 | + with: |
| 76 | + path: ~/.cargo/registry/cache |
| 77 | + key: ${{ runner.os }}-cargo-registry-cache-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }} |
| 78 | + restore-key: | |
| 79 | + ${{ runner.os }}-cargo-registry-cache-${{ matrix.rust }}- |
| 80 | + ${{ runner.os }}-cargo-registry-cache- |
| 81 | +
|
| 82 | + - name: Cache cargo registry index |
| 83 | + uses: actions/cache@v1 |
| 84 | + with: |
| 85 | + path: ~/.cargo/registry/index |
| 86 | + key: ${{ runner.os }}-cargo-registry-index-${{ github.ref }}-${{ github.sha }} |
| 87 | + restore-key: | |
| 88 | + ${{ runner.os }}-cargo-registry-index-master- |
| 89 | +
|
| 90 | + - name: Cache cargo git db |
| 91 | + uses: actions/cache@v1 |
| 92 | + with: |
| 93 | + path: ~/.cargo/git/db |
| 94 | + key: ${{ runner.os }}-cargo-git-db--${{ github.ref }}-${{ hashFiles('**/Cargo.lock') }} |
| 95 | + restore-key: | |
| 96 | + ${{ runner.os }}-cargo-git-db-master |
| 97 | +
|
| 98 | + - name: Cache cargo build |
| 99 | + uses: actions/cache@v1 |
| 100 | + with: |
| 101 | + path: target |
| 102 | + key: ${{ runner.os }}-cargo-build-target-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }} |
| 103 | + restore-key: | |
| 104 | + ${{ runner.os }}-cargo-build-target-${{ matrix.rust }}- |
| 105 | + ${{ runner.os }}-cargo-build-target- |
| 106 | +
|
| 107 | + - name: Install ${{ matrix.rust }} Rust |
| 108 | + run: | |
| 109 | + if [[ ! -d "$HOME/.cargo" || ! -d "$HOME/.rustup" ]]; then |
| 110 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh |
| 111 | + sh rustup-init.sh -y --default-toolchain none |
| 112 | + fi |
| 113 | + rustup set profile minimal |
| 114 | + rustup update ${{ matrix.rust }} |
| 115 | + rustup default ${{ matrix.rust }} |
| 116 | +
|
| 117 | + - name: Install lint tools |
| 118 | + if: matrix.rust == 'stable' |
| 119 | + run: | |
| 120 | + rustup component add rustfmt |
| 121 | + rustup component add clippy |
| 122 | +
|
| 123 | + - name: Cargo clean on new rustc version |
| 124 | + run: script/ci/cargo-clean-on-new-rustc-version.sh |
| 125 | + |
| 126 | + - name: Lint |
| 127 | + if: matrix.rust == 'stable' |
| 128 | + run: | |
| 129 | + cargo fmt -- --check |
| 130 | + cargo clippy --all-targets --all-features --all |
| 131 | +
|
| 132 | + - name: Test |
| 133 | + run: cargo test |
| 134 | + |
| 135 | + - name: Prune unnecessary cache |
| 136 | + run: script/ci/prune-cache.sh |
0 commit comments