feat(ci): rust caching in `test` workflow (#4015)

- draft: improve rust target caching in ci
- separate caches for e2e-cosmwasm, e2e-noncosmwasm, cli-e2e test
- drive-by adding `restore-keys`

test expectation:
- 1st commit of rust changes will take the full required time as it'll
have to do a fresh build and then cache
- subsequent builds of a particular rust change will be faster because
it'll pickup the rust cache from before

---------

Signed-off-by: Paul Balaji <10051819+paulbalaji@users.noreply.github.com>
pull/4022/head
Paul Balaji 5 months ago committed by GitHub
parent c84a1dc73b
commit 0d12ff31cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      .github/workflows/rust.yml
  2. 86
      .github/workflows/test.yml
  3. 6
      typescript/cli/ci-test.sh

@ -39,8 +39,7 @@ jobs:
- name: rust cache - name: rust cache
uses: Swatinem/rust-cache@v2 uses: Swatinem/rust-cache@v2
with: with:
prefix-key: "v2-rust" prefix-key: "v3-rust"
shared-key: "test"
workspaces: | workspaces: |
./rust ./rust
- name: Free disk space - name: Free disk space
@ -69,8 +68,7 @@ jobs:
- name: rust cache - name: rust cache
uses: Swatinem/rust-cache@v2 uses: Swatinem/rust-cache@v2
with: with:
prefix-key: "v2-rust" prefix-key: "v3-rust"
shared-key: "lint"
workspaces: | workspaces: |
./rust ./rust
- name: Free disk space - name: Free disk space

@ -254,6 +254,14 @@ jobs:
toolchain: stable toolchain: stable
profile: minimal profile: minimal
- name: rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "v1-${{ runner.os }}-rust-cache"
shared-key: ${{ matrix.e2e-type }}
workspaces: |
./rust
- name: Free disk space - name: Free disk space
run: | run: |
# Based on https://github.com/actions/runner-images/issues/2840#issuecomment-790492173 # Based on https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
@ -296,22 +304,15 @@ jobs:
key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }} key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }}
fail-on-cache-miss: true fail-on-cache-miss: true
- name: cargo-cache
uses: actions/cache@v4
with:
path: |
~/.cargo
key: ${{ runner.os }}-cargo-cache-${{ hashFiles('./rust/Cargo.lock') }}
- name: agent tests with CosmWasm - name: agent tests with CosmWasm
run: cargo test --release --package run-locally --bin run-locally --features cosmos -- cosmos::test --nocapture run: cargo test --release --package run-locally --bin run-locally --features cosmos test-utils -- cosmos::test --nocapture
if: matrix.e2e-type == 'cosmwasm' if: matrix.e2e-type == 'cosmwasm'
working-directory: ./rust working-directory: ./rust
env: env:
RUST_BACKTRACE: 'full' RUST_BACKTRACE: 'full'
- name: agent tests excluding CosmWasm - name: agent tests excluding CosmWasm
run: cargo run --release --bin run-locally run: cargo run --release --bin run-locally --features test-utils
if: matrix.e2e-type == 'non-cosmwasm' if: matrix.e2e-type == 'non-cosmwasm'
working-directory: ./rust working-directory: ./rust
env: env:
@ -330,10 +331,60 @@ jobs:
echo "All e2e-matrix jobs have completed." echo "All e2e-matrix jobs have completed."
# You can add additional commands here to report the result as needed # You can add additional commands here to report the result as needed
prebuild-cli-e2e:
runs-on: larger-runner
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.base_ref == 'main') || github.event_name == 'merge_group'
needs: [checkout-registry]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive
- name: setup rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
- name: rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "v1-${{ runner.os }}-rust-cache"
shared-key: "cli-e2e"
workspaces: |
./rust
- name: Free disk space
run: |
# Based on https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Install mold linker
uses: rui314/setup-mold@v1
with:
mold-version: 2.0.0
make-default: true
- name: Build validator
run: cargo build --bin validator --features test-utils
working-directory: ./rust
env:
RUST_BACKTRACE: 'full'
- name: Build relayer
run: cargo build --bin relayer --features test-utils
working-directory: ./rust
env:
RUST_BACKTRACE: 'full'
cli-e2e: cli-e2e:
runs-on: larger-runner runs-on: larger-runner
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.base_ref == 'main') || github.event_name == 'merge_group' if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.base_ref == 'main') || github.event_name == 'merge_group'
needs: [yarn-build, checkout-registry] needs: [yarn-build, prebuild-cli-e2e]
strategy: strategy:
matrix: matrix:
include: include:
@ -359,6 +410,14 @@ jobs:
toolchain: stable toolchain: stable
profile: minimal profile: minimal
- name: rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "v1-${{ runner.os }}-rust-cache"
shared-key: "cli-e2e"
workspaces: |
./rust
- name: Free disk space - name: Free disk space
run: | run: |
# Based on https://github.com/actions/runner-images/issues/2840#issuecomment-790492173 # Based on https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
@ -401,13 +460,6 @@ jobs:
key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }} key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }}
fail-on-cache-miss: true fail-on-cache-miss: true
- name: cargo-cache
uses: actions/cache@v4
with:
path: |
~/.cargo
key: ${{ runner.os }}-cargo-cache-${{ hashFiles('./rust/Cargo.lock') }}
- name: cli e2e tests - name: cli e2e tests
run: ./typescript/cli/ci-test.sh ${{ matrix.test-type }} run: ./typescript/cli/ci-test.sh ${{ matrix.test-type }}

@ -254,7 +254,7 @@ run_hyperlane_send_message() {
run_validator() { run_validator() {
echo -e "\nPre-building validator with cargo" echo -e "\nPre-building validator with cargo"
cargo build --bin validator cargo build --bin validator --features test-utils
# set some default agent env vars, used by both validators and relayer # set some default agent env vars, used by both validators and relayer
export HYP_CHAINS_${CHAIN1_CAPS}_BLOCKS_REORGPERIOD=0 export HYP_CHAINS_${CHAIN1_CAPS}_BLOCKS_REORGPERIOD=0
@ -290,7 +290,7 @@ run_validator() {
echo "Validator running, sleeping to let it sync" echo "Validator running, sleeping to let it sync"
# This needs to be long to allow time for the cargo build to finish # This needs to be long to allow time for the cargo build to finish
sleep 15 sleep 20
echo "Done sleeping" echo "Done sleeping"
for CHAIN in ${CHAIN1} ${CHAIN2} for CHAIN in ${CHAIN1} ${CHAIN2}
@ -308,7 +308,7 @@ run_validator() {
run_relayer() { run_relayer() {
echo -e "\nPre-building relayer with cargo" echo -e "\nPre-building relayer with cargo"
cargo build --bin relayer cargo build --bin relayer --features test-utils
echo "Running relayer" echo "Running relayer"
export CONFIG_FILES=/tmp/agent-config.json export CONFIG_FILES=/tmp/agent-config.json

Loading…
Cancel
Save