From 40103d84cef8632f6c0b2ba51ea02e0a69b120e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Nagy?= Date: Fri, 10 Jan 2020 11:02:40 +1100 Subject: [PATCH] Use GitHub actions (#407) * gh-403: add basic github actions * gh-403: add environment variables during test * gh-403: fix error in tower-balance example * gh-403: rename build workflow * gh-403: fix release workflow * gh-403: add GitHub page publish workflow * gh-403: remove release workflow * gh-403: run per crate build * gh-403: replace build to check --- .github/workflows/build.yml | 135 +++++++++++++++++++++++++++++++++ .github/workflows/publish.yml | 29 +++++++ tower-balance/examples/demo.rs | 2 +- 3 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..6753a7dd --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,135 @@ +name: continuous integration + +on: [push, pull_request] + +jobs: + build_whole_workspace: + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-18.04, windows-2019, macOS-10.14] + rust: [stable, nightly] + + steps: + - name: Checkout code + uses: actions/checkout@v1 + - name: Install rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + - name: Build + uses: actions-rs/cargo@v1 + with: + command: check + args: --verbose + - name: Run tests + uses: actions-rs/cargo@v1 + env: + CI: 'True' + RUSTFLAGS: '-D warnings' + with: + command: test + args: --verbose + + build_per_crate: + + runs-on: ubuntu-latest + + strategy: + matrix: + crate: + - tower + - tower-balance + - tower-buffer + - tower-discover + - tower-filter + - tower-hedge + - tower-layer + - tower-limit + - tower-load + - tower-load-shed + - tower-make + - tower-ready-cache + - tower-reconnect + - tower-retry + - tower-service + - tower-spawn-ready + - tower-test + - tower-timeout + - tower-util + + steps: + - name: Checkout code + uses: actions/checkout@v1 + - name: Install rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Patch + run: | + set -e + # Remove any existing patch statements + mv Cargo.toml Cargo.toml.bck + sed -n '/\[patch.crates-io\]/q;p' Cargo.toml.bck > Cargo.toml + # Patch all crates + cat ci/patch.toml >> Cargo.toml + # Print `Cargo.toml` for debugging + echo "~~~~ Cargo.toml ~~~~" + cat Cargo.toml + echo "~~~~~~~~~~~~~~~~~~~~" + - name: Build + uses: actions-rs/cargo@v1 + with: + command: check + args: -p ${{ matrix.crate }} --verbose + - name: Run tests + uses: actions-rs/cargo@v1 + env: + CI: 'True' + RUSTFLAGS: '-D warnings' + with: + command: test + args: -p ${{ matrix.crate }} --verbose + + rustfmt_check: + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v1 + - name: Ensure that rustfmt is installed + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + components: rustfmt + - name: Run rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + +# This is failing, because it finds errors... +# clippy_check: +# +# runs-on: ubuntu-latest +# +# steps: +# - name: Checkout code +# uses: actions/checkout@v1 +# - name: Ensure that clippy is installed +# uses: actions-rs/toolchain@v1 +# with: +# toolchain: nightly +# override: true +# components: clippy +# - name: Run clippy +# uses: actions-rs/clippy-check@v1 +# with: +# token: ${{ secrets.GITHUB_TOKEN }} +# args: --all-targets --all-features diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..40554ebd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,29 @@ +name: Deploy API Documentation + +on: + push: + branches: + - master + +jobs: + publish: + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v1 + - name: Generate documentation + uses: actions-rs/cargo@v1 + with: + command: doc + args: --workspace --no-deps + - name: Deploy documentation + if: success() + uses: crazy-max/ghaction-github-pages@v1 + with: + target_branch: gh-pages + build_dir: target/doc + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/tower-balance/examples/demo.rs b/tower-balance/examples/demo.rs index 88a69966..cc22bd73 100644 --- a/tower-balance/examples/demo.rs +++ b/tower-balance/examples/demo.rs @@ -180,7 +180,7 @@ impl Summary { for c in &self.count_by_instance { total += c; } - for (i, c) in self.count_by_instance.into_iter().enumerate() { + for (i, c) in self.count_by_instance.iter().enumerate() { let p = *c as f64 / total as f64 * 100.0; println!(" [{:02}] {:>5.01}%", i, p); }