From 3c7880f77136cf9b171dee7de3fce8370ea6db28 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 17 Feb 2021 14:40:34 +1100 Subject: [PATCH 1/7] Fix path to CLI for artifact upload The name was recently changed but the workflow wasn't adapted. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3330d9d7..45d9e057 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,7 +107,7 @@ jobs: uses: actions/upload-artifact@v2-preview with: name: swap-${{ matrix.target }} - path: target/${{ matrix.target }}/debug/swap + path: target/${{ matrix.target }}/debug/swap_cli docker_tests: env: From acbc0f5551ded5d7b31772b2166bc3d43cd4d0c0 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 17 Feb 2021 14:42:15 +1100 Subject: [PATCH 2/7] Upload nectar binary in addition to swap_cli --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45d9e057..6470873c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,12 +103,18 @@ jobs: run: | cargo build -p swap --target ${{ matrix.target }} - - name: Upload binary + - name: Upload swap_cli binary uses: actions/upload-artifact@v2-preview with: name: swap-${{ matrix.target }} path: target/${{ matrix.target }}/debug/swap_cli + - name: Upload nectar binary + uses: actions/upload-artifact@v2-preview + with: + name: nectar-${{ matrix.target }} + path: target/${{ matrix.target }}/debug/nectar + docker_tests: env: TARGET: x86_64-unknown-linux-gnu From e57c00592012683fad5997270046e19fb739c545 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 17 Feb 2021 14:43:53 +1100 Subject: [PATCH 3/7] Remove unused matrix entry --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6470873c..2a072dbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,6 @@ jobs: os: ubuntu-latest - target: x86_64-apple-darwin os: macos-latest - skip_tests: true # Most likely do not work due to docker usage, TODO: add feature flag to allow unit tests runs-on: ${{ matrix.os }} steps: From f1b097877b19efb96845e486d3d42d86cb0a39be Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 17 Feb 2021 14:46:12 +1100 Subject: [PATCH 4/7] Split `build_test` into `build` and `test` Building binaries and building tests results in different artifacts inside the `target` directory. If we use distinct caches for these commands, the caches are more useful because less code has to be re-built. --- .github/workflows/ci.yml | 78 +++++++++++++++++++++++++++------------- bors.toml | 6 ++-- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a072dbe..32477390 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,57 @@ jobs: - name: Run clippy with all features enabled run: cargo clippy --workspace --all-targets --all-features -- -D warnings - build_test: + build: + strategy: + matrix: + target: [ x86_64-unknown-linux-gnu, x86_64-apple-darwin ] + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + - target: x86_64-apple-darwin + os: macos-latest + runs-on: ${{ matrix.os }} + steps: + + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + override: true + + - name: Cache target directory + uses: actions/cache@v1 + if: matrix.os == 'ubuntu-latest' + with: + path: target + key: rust-${{ matrix.target }}-target-directory-build-${{ hashFiles('Cargo.lock') }}-v1 + + - name: Cache ~/.cargo/registry directory + uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: rust-${{ matrix.target }}-cargo-registry-directory-${{ hashFiles('Cargo.lock') }}-v1 + + - name: Build binary + run: | + cargo build -p swap --target ${{ matrix.target }} + + - name: Upload swap_cli binary + uses: actions/upload-artifact@v2-preview + with: + name: swap-${{ matrix.target }} + path: target/${{ matrix.target }}/debug/swap_cli + + - name: Upload nectar binary + uses: actions/upload-artifact@v2-preview + with: + name: nectar-${{ matrix.target }} + path: target/${{ matrix.target }}/debug/nectar + + test: env: RUST_TEST_TASKS: 2 strategy: @@ -74,7 +124,7 @@ jobs: if: matrix.os == 'ubuntu-latest' with: path: target - key: rust-${{ matrix.target }}-target-directory-${{ hashFiles('Cargo.lock') }}-v1 + key: rust-${{ matrix.target }}-target-directory-test-${{ hashFiles('Cargo.lock') }}-v1 - name: Cache ~/.cargo/registry directory uses: actions/cache@v1 @@ -82,12 +132,6 @@ jobs: path: ~/.cargo/registry key: rust-${{ matrix.target }}-cargo-registry-directory-${{ hashFiles('Cargo.lock') }}-v1 - - name: Cargo check release code with default features - run: cargo check --workspace - - - name: Cargo check all features - run: cargo check --workspace --all-targets --all-features - - name: Build tests run: cargo build --tests --workspace --all-features @@ -98,22 +142,6 @@ jobs: - name: Run library tests for swap run: cargo test --package swap --lib --all-features - - name: Build binary - run: | - cargo build -p swap --target ${{ matrix.target }} - - - name: Upload swap_cli binary - uses: actions/upload-artifact@v2-preview - with: - name: swap-${{ matrix.target }} - path: target/${{ matrix.target }}/debug/swap_cli - - - name: Upload nectar binary - uses: actions/upload-artifact@v2-preview - with: - name: nectar-${{ matrix.target }} - path: target/${{ matrix.target }}/debug/nectar - docker_tests: env: TARGET: x86_64-unknown-linux-gnu @@ -142,7 +170,7 @@ jobs: uses: actions/cache@v1 with: path: target - key: rust-${{ env.TARGET }}-target-directory-${{ hashFiles('Cargo.lock') }}-v1 + key: rust-${{ matrix.target }}-target-directory-test-${{ hashFiles('Cargo.lock') }}-v1 - name: Cache ~/.cargo/registry directory uses: actions/cache@v1 diff --git a/bors.toml b/bors.toml index fcb4f9eb..8f1b1ab7 100644 --- a/bors.toml +++ b/bors.toml @@ -1,7 +1,9 @@ status = [ "static_analysis", - "build_test (x86_64-unknown-linux-gnu)", - "build_test (x86_64-apple-darwin)", + "build (x86_64-unknown-linux-gnu)", + "build (x86_64-apple-darwin)", + "test (x86_64-unknown-linux-gnu)", + "test (x86_64-apple-darwin)", "docker_tests (happy_path)", "docker_tests (happy_path_restart_bob_before_comm)", "docker_tests (bob_refunds_using_cancel_and_refund_command)", From a3b5c13b52886568325b64e738754a4aa3a43846 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 17 Feb 2021 14:50:44 +1100 Subject: [PATCH 5/7] Upgrade to actions/cache@v2.1.4 Usually, we can follow the rolling major tag (@v2) of actions. However the recent release (2.1.4) is not yet included. See https://github.com/actions/cache/issues/528 for more details. We do want to depend on 2.1.4 because it contains a fix that allows us to use the cache action MacOS. v2 also features better compression and allows for multiple paths to be specified. --- .github/workflows/ci.yml | 52 +++++++++++++++------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32477390..4fbff08b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: components: rustfmt, clippy - name: Cache ~/.cargo/bin directory - uses: actions/cache@v1 + uses: actions/cache@v2.1.4 with: path: ~/.cargo/bin key: ubuntu-rust-${{ env.RUST_TOOLCHAIN }}-cargo-bin-directory-v1 @@ -67,18 +67,13 @@ jobs: profile: minimal override: true - - name: Cache target directory - uses: actions/cache@v1 - if: matrix.os == 'ubuntu-latest' + - name: Cache target and registry directory + uses: actions/cache@v2.1.4 with: - path: target - key: rust-${{ matrix.target }}-target-directory-build-${{ hashFiles('Cargo.lock') }}-v1 - - - name: Cache ~/.cargo/registry directory - uses: actions/cache@v1 - with: - path: ~/.cargo/registry - key: rust-${{ matrix.target }}-cargo-registry-directory-${{ hashFiles('Cargo.lock') }}-v1 + path: | + target + ~/.cargo/registry + key: rust-${{ matrix.target }}-build-${{ hashFiles('Cargo.lock') }}-v1 - name: Build binary run: | @@ -119,18 +114,13 @@ jobs: profile: minimal override: true - - name: Cache target directory - uses: actions/cache@v1 - if: matrix.os == 'ubuntu-latest' + - name: Cache target and registry directory + uses: actions/cache@v2.1.4 with: - path: target - key: rust-${{ matrix.target }}-target-directory-test-${{ hashFiles('Cargo.lock') }}-v1 - - - name: Cache ~/.cargo/registry directory - uses: actions/cache@v1 - with: - path: ~/.cargo/registry - key: rust-${{ matrix.target }}-cargo-registry-directory-${{ hashFiles('Cargo.lock') }}-v1 + path: | + target + ~/.cargo/registry + key: rust-${{ matrix.target }}-test-${{ hashFiles('Cargo.lock') }}-v1 - name: Build tests run: cargo build --tests --workspace --all-features @@ -166,17 +156,13 @@ jobs: profile: minimal override: true - - name: Cache target directory - uses: actions/cache@v1 + - name: Cache target and registry directory + uses: actions/cache@v2.1.4 with: - path: target - key: rust-${{ matrix.target }}-target-directory-test-${{ hashFiles('Cargo.lock') }}-v1 - - - name: Cache ~/.cargo/registry directory - uses: actions/cache@v1 - with: - path: ~/.cargo/registry - key: rust-${{ env.TARGET }}-cargo-registry-directory-${{ hashFiles('Cargo.lock') }}-v1 + path: | + target + ~/.cargo/registry + key: rust-${{ matrix.target }}-test-${{ hashFiles('Cargo.lock') }}-v1 - name: Run test ${{ matrix.test_name }} run: cargo test --package swap --all-features --test ${{ matrix.test_name }} "" From 8072f4d7ee0f6cf49d2643087e45ed1839841217 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 17 Feb 2021 14:53:35 +1100 Subject: [PATCH 6/7] Only install tomlfmt if we don't have ~/.cargo/bin cached --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fbff08b..89842a1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,13 +23,15 @@ jobs: components: rustfmt, clippy - name: Cache ~/.cargo/bin directory + id: cargo-bin-cache uses: actions/cache@v2.1.4 with: path: ~/.cargo/bin key: ubuntu-rust-${{ env.RUST_TOOLCHAIN }}-cargo-bin-directory-v1 - name: Install tomlfmt - run: which cargo-tomlfmt || cargo install cargo-tomlfmt + if: steps.cargo-bin-cache.outputs.cache-hit != 'true' + run: cargo install cargo-tomlfmt - name: Check Cargo.toml formatting run: | From fb45ff66eb5fea2e6b7b41cdb77f6215858222c0 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 17 Feb 2021 14:55:53 +1100 Subject: [PATCH 7/7] Update rust-toolchain to new toml syntax This allows us to completely skip the "Install Rust" step in CI because the rust-toolchain file completely describes what we need. The first invocation of cargo will simply install all the required components. Additionally, we make all caches dependant on the version of Rust that we require. --- .github/workflows/ci.yml | 33 ++++----------------------------- rust-toolchain | 4 +++- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89842a1c..caaffef1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,19 +15,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - override: true - components: rustfmt, clippy - - name: Cache ~/.cargo/bin directory id: cargo-bin-cache uses: actions/cache@v2.1.4 with: path: ~/.cargo/bin - key: ubuntu-rust-${{ env.RUST_TOOLCHAIN }}-cargo-bin-directory-v1 + key: ubuntu-rust-${{ hashFiles('rust-toolchain') }}-cargo-bin-directory-v1 - name: Install tomlfmt if: steps.cargo-bin-cache.outputs.cache-hit != 'true' @@ -63,19 +56,13 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - override: true - - name: Cache target and registry directory uses: actions/cache@v2.1.4 with: path: | target ~/.cargo/registry - key: rust-${{ matrix.target }}-build-${{ hashFiles('Cargo.lock') }}-v1 + key: rust-${{ matrix.target }}-build-${{ hashFiles('Cargo.lock') }}-${{ hashFiles('rust-toolchain') }}-v1 - name: Build binary run: | @@ -110,19 +97,13 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - override: true - - name: Cache target and registry directory uses: actions/cache@v2.1.4 with: path: | target ~/.cargo/registry - key: rust-${{ matrix.target }}-test-${{ hashFiles('Cargo.lock') }}-v1 + key: rust-${{ matrix.target }}-test-${{ hashFiles('Cargo.lock') }}-${{ hashFiles('rust-toolchain') }}-v1 - name: Build tests run: cargo build --tests --workspace --all-features @@ -152,19 +133,13 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - override: true - - name: Cache target and registry directory uses: actions/cache@v2.1.4 with: path: | target ~/.cargo/registry - key: rust-${{ matrix.target }}-test-${{ hashFiles('Cargo.lock') }}-v1 + key: rust-${{ matrix.target }}-test-${{ hashFiles('Cargo.lock') }}-${{ hashFiles('rust-toolchain') }}-v1 - name: Run test ${{ matrix.test_name }} run: cargo test --package swap --all-features --test ${{ matrix.test_name }} "" diff --git a/rust-toolchain b/rust-toolchain index 97e6da5f..b431082c 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1,3 @@ -nightly-2021-01-31 +[toolchain] +channel = "nightly-2021-01-31" +components = ["rustfmt", "clippy"]