ci: improve main CI jobs

This commit is contained in:
DaniPopes 2023-02-24 20:45:48 +01:00
parent f7963d0fb4
commit 50a4b2a8a2
No known key found for this signature in database
GPG Key ID: 0F09640DDB7AC692
2 changed files with 205 additions and 198 deletions

45
.github/scripts/install_test_binaries.sh vendored Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Installs Solc and Geth binaries
set -e
GETH_BUILD=${GETH_BUILD:-"1.11.2-73b01f40"}
SOLC_VERSION=${SOLC_VERSION:-"0.8.19"}
DIR="$HOME/bin"
# DIR="$HOME/github/danipopes/ethers-rs/test_bin"
mkdir -p "$DIR"
cd "$DIR"
export PATH="$DIR:$PATH"
echo "Installing Geth"
PLATFORM="$(uname -s)"
case "$PLATFORM" in
Linux|Darwin)
GETH_ARCHIVE_NAME="geth-${PLATFORM,,}-amd64-$GETH_BUILD"
curl "https://gethstore.blob.core.windows.net/builds/$GETH_ARCHIVE_NAME.tar.gz" | tar -xzvf -
mv -f "$GETH_ARCHIVE_NAME/geth" ./
rm -rf "$GETH_ARCHIVE_NAME"
chmod +x geth
;;
*)
GETH_ARCHIVE_NAME="geth-windows-amd64-$GETH_BUILD"
wget -q "https://gethstore.blob.core.windows.net/builds/$GETH_ARCHIVE_NAME.zip"
unzip "$GETH_ARCHIVE_NAME.zip"
mv -f "$GETH_ARCHIVE_NAME/geth.exe" ./
rm -rf "$GETH_ARCHIVE_NAME" "$GETH_ARCHIVE_NAME.zip"
;;
esac
geth version
echo "Installing Solc"
cargo install --locked svm-rs
# install only if it doesn't exist already
if command -v solc; then
if [ -z "$(solc --version | grep "$SOLC_VERSION" || true)" ]; then
svm install "$SOLC_VERSION"
fi
svm use "$SOLC_VERSION"
fi
solc --version

View File

@ -1,11 +1,10 @@
name: CI
on: on:
push: push:
branches: branches: [master]
- master
pull_request: pull_request:
name: Tests
# Yeah I know it's bad practice to have API keys, this is a read-only API key # Yeah I know it's bad practice to have API keys, this is a read-only API key
# so that we do not get rate limited by Etherscan (and it's free to generate as # so that we do not get rate limited by Etherscan (and it's free to generate as
# many as you want) # many as you want)
@ -13,215 +12,181 @@ env:
ETHERSCAN_API_KEY_ETHEREUM: I5BXNZYP5GEDWFINGVEZKYIVU2695NPQZB ETHERSCAN_API_KEY_ETHEREUM: I5BXNZYP5GEDWFINGVEZKYIVU2695NPQZB
ETHERSCAN_API_KEY_CELO: B13XSMUT6Q3Q4WZ5DNQR8RXDBA2KNTMT4M ETHERSCAN_API_KEY_CELO: B13XSMUT6Q3Q4WZ5DNQR8RXDBA2KNTMT4M
GOERLI_PRIVATE_KEY: "fa4a1a79e869a96fcb42727f75e3232d6865a82ea675bb95de967a7fe6a773b2" GOERLI_PRIVATE_KEY: "fa4a1a79e869a96fcb42727f75e3232d6865a82ea675bb95de967a7fe6a773b2"
GETH_BUILD: 1.10.26-e5eb32ac GETH_BUILD: "1.11.2-73b01f40"
SOLC_VERSION: "0.8.19"
RUSTFLAGS: "-D warnings"
jobs: jobs:
tests: tests:
name: ethereum tests name: tests ${{ matrix.toolchain }}-${{ matrix.job.target }}
runs-on: ubuntu-latest runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: ubuntu-latest
target: wasm32-unkown-unkown
toolchain: ["stable", "nightly"]
steps: steps:
- name: Checkout sources - uses: actions/checkout@v3
uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
targets: ${{ matrix.job.target }}
- name: Install Anvil - name: Install Anvil
uses: foundry-rs/foundry-toolchain@v1 uses: foundry-rs/foundry-toolchain@v1
with: with:
version: nightly version: nightly
- name: Install Solc - name: Install test binaries
run: | shell: bash
mkdir -p "$HOME/bin" run: ./.github/scripts/install_test_binaries.sh
wget -q https://github.com/ethereum/solidity/releases/download/v0.8.10/solc-static-linux -O $HOME/bin/solc - uses: Swatinem/rust-cache@v2
chmod u+x "$HOME/bin/solc"
export PATH=$HOME/bin:$PATH
solc --version
- name: Install geth
run: |
mkdir -p "$HOME/bin"
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
chmod u+x "$HOME/bin/geth"
export PATH=$HOME/bin:$PATH
geth version
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v1
with: with:
cache-on-failure: true cache-on-failure: true
- name: cargo test - name: test
shell: bash
run: | run: |
export PATH=$HOME/bin:$PATH export ETHERSCAN_API_KEY="$ETHERSCAN_API_KEY_ETHEREUM"
export ETHERSCAN_API_KEY=$ETHERSCAN_API_KEY_ETHEREUM rustup run ${{ matrix.toolchain }}-${{ matrix.job.target }} cargo test --workspace
cargo test
feature-tests: feature-tests:
name: celo tests name: feature tests ${{ matrix.toolchain }}-${{ matrix.job.target }}
runs-on: ubuntu-latest runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
toolchain: ["stable", "nightly"]
steps: steps:
- name: Checkout sources - uses: actions/checkout@v3
uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master
# TODO: can we combine these shared steps in github actions? with:
toolchain: ${{ matrix.toolchain }}
targets: ${{ matrix.job.target }}
- name: Install Anvil - name: Install Anvil
uses: foundry-rs/foundry-toolchain@v1 uses: foundry-rs/foundry-toolchain@v1
with: with:
version: nightly version: nightly
- name: Install Solc - name: Install test binaries
run: | shell: bash
mkdir -p "$HOME/bin" run: ./.github/scripts/install_test_binaries.sh
wget -q https://github.com/ethereum/solidity/releases/download/v0.8.10/solc-static-linux -O $HOME/bin/solc - uses: Swatinem/rust-cache@v2
chmod u+x "$HOME/bin/solc"
export PATH=$HOME/bin:$PATH
solc --version
- name: Install geth
run: |
mkdir -p "$HOME/bin"
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
chmod u+x "$HOME/bin/geth"
export PATH=$HOME/bin:$PATH
geth version
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v1
with: with:
cache-on-failure: true cache-on-failure: true
- name: cargo test (Celo) - name: test
shell: bash
run: | run: |
export PATH=$HOME/bin:$PATH export ETHERSCAN_API_KEY="$ETHERSCAN_API_KEY_CELO"
export ETHERSCAN_API_KEY=$ETHERSCAN_API_KEY_CELO rustup run ${{ matrix.toolchain }}-${{ matrix.job.target }} cargo test --workspace
cargo test --all-features
lint: features:
name: lints name: features
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout sources - uses: actions/checkout@v3
uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly
- name: Install toolchain - uses: Swatinem/rust-cache@v2
uses: actions-rs/toolchain@v1 - uses: taiki-e/install-action@cargo-hack
- name: cargo hack
run:
cargo hack check --all --feature-powerset --depth 2 -Z avoid-dev-deps --keep-going
clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with: with:
toolchain: nightly components: clippy
profile: minimal - uses: Swatinem/rust-cache@v2
components: rustfmt, clippy - name: clippy
override: true run: cargo clippy --workspace --tests --all-features
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: cargo fmt
run: cargo +nightly fmt --all -- --check
- name: cargo clippy
run: cargo +nightly clippy --all-features -- -D warnings
docs: docs:
name: docs name: docs
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout sources - uses: actions/checkout@v3
uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master
- name: Install toolchain
uses: actions-rs/toolchain@v1
with: with:
toolchain: nightly # TODO: Remove nightly override: rust-lang/rust#{108334,108378}
override: true toolchain: nightly-2023-02-07
- uses: Swatinem/rust-cache@v1 components: rust-docs
- uses: Swatinem/rust-cache@v2
- name: doc
run: cargo doc --lib --workspace --all-features
fmt:
name: fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with: with:
cache-on-failure: true components: rustfmt
- name: cargo doc - name: fmt --check
run: cargo +nightly doc --lib --all-features run: cargo fmt --all --check
env:
RUSTFLAGS: --cfg docsrs
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
wasm: wasm:
name: WASM name: WASM
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout sources - uses: actions/checkout@v3
uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable
- name: Install rust
uses: actions-rs/toolchain@v1
with: with:
toolchain: stable
target: wasm32-unknown-unknown target: wasm32-unknown-unknown
profile: minimal
override: true
- name: Install Anvil - name: Install Anvil
uses: foundry-rs/foundry-toolchain@v1 uses: foundry-rs/foundry-toolchain@v1
with: with:
version: nightly version: nightly
- uses: Swatinem/rust-cache@v1 - uses: Swatinem/rust-cache@v2
with: with:
cache-on-failure: true cache-on-failure: true
- name: Check - name: Check
uses: actions-rs/cargo@v1 run: rustup run wasm32-unknown-unknown cargo check --workspace
with: - name: Check all features
command: check run: rustup run wasm32-unknown-unknown cargo check --workspace --all-features
args: --target wasm32-unknown-unknown
- name: Launch Anvil
run:
anvil --block-time 2 -m "stuff inherit faith park genre spread huge knee ecology
private marble supreme" &
- name: Install wasm-pack - name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- uses: actions/setup-node@v3
- name: Wasm-pack test firefox with:
node-version: 16
cache: yarn
- name: Run wasm example
run: | run: |
cd examples/ethers-wasm cd examples/ethers-wasm
yarn
yarn anvil &
wasm-pack test --headless --firefox wasm-pack test --headless --firefox
- name: Wasm-pack test chrome
run: |
cd examples/ethers-wasm
wasm-pack test --headless --chrome wasm-pack test --headless --chrome
kill %1
examples: examples:
name: Examples name: Examples
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout sources - uses: actions/checkout@v3
uses: actions/checkout@v3
- name: Install geth (for state overrides example)
run: |
mkdir -p "$HOME/bin"
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
chmod u+x "$HOME/bin/geth"
export PATH=$HOME/bin:$PATH
geth version
- name: Install Anvil - name: Install Anvil
uses: foundry-rs/foundry-toolchain@v1 uses: foundry-rs/foundry-toolchain@v1
with: with:
version: nightly version: nightly
- name: Install test binaries
- name: Install Solc run: ./.github/scripts/install_test_binaries.sh
run: |
mkdir -p "$HOME/bin"
wget -q https://github.com/ethereum/solidity/releases/download/v0.8.10/solc-static-linux -O $HOME/bin/solc
chmod u+x "$HOME/bin/solc"
export PATH=$HOME/bin:$PATH
solc --version
- name: Install stable toolchain - name: Install stable toolchain
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
@ -229,60 +194,57 @@ jobs:
toolchain: stable toolchain: stable
override: true override: true
components: rustfmt, clippy components: rustfmt, clippy
- uses: Swatinem/rust-cache@v1 - uses: Swatinem/rust-cache@v2
with: with:
cache-on-failure: true cache-on-failure: true
- name: Build and run all examples - name: Build and run all examples
run: | run: ./scripts/examples.sh
export PATH=$HOME/bin:$PATH
chmod +x ./scripts/examples.sh
./scripts/examples.sh
windows-build: # windows-build:
runs-on: windows-latest # runs-on: windows-latest
name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }}) # name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
env: # env:
CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }} # CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
strategy: # strategy:
fail-fast: false # fail-fast: false
matrix: # matrix:
target: # target:
[ # [
i686-pc-windows-gnu, # i686-pc-windows-gnu,
i686-pc-windows-msvc, # i686-pc-windows-msvc,
x86_64-pc-windows-gnu, # x86_64-pc-windows-gnu,
x86_64-pc-windows-msvc, # x86_64-pc-windows-msvc,
] # ]
cfg_release_channel: [nightly] # cfg_release_channel: [nightly]
steps: # steps:
- name: checkout # - name: checkout
uses: actions/checkout@v3 # uses: actions/checkout@v3
# Run build # # Run build
- name: Update Rustup # - name: Update Rustup
run: | # run: |
# disable download progress bar # # disable download progress bar
$ProgressPreference = "SilentlyContinue" # $ProgressPreference = "SilentlyContinue"
rustup update # rustup update
rustup target add ${{ matrix.target }} # rustup target add ${{ matrix.target }}
shell: powershell # shell: powershell
- name: Add mingw32 to path for i686-gnu # - name: Add mingw32 to path for i686-gnu
run: | # run: |
echo "C:\msys64\mingw32\bin" >> $GITHUB_PATH # echo "C:\msys64\mingw32\bin" >> $GITHUB_PATH
if: matrix.target == 'i686-pc-windows-gnu' && matrix.channel == 'nightly' # if: matrix.target == 'i686-pc-windows-gnu' && matrix.channel == 'nightly'
shell: bash # shell: bash
- name: Add mingw64 to path for x86_64-gnu # - name: Add mingw64 to path for x86_64-gnu
run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH # run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH
if: matrix.target == 'x86_64-pc-windows-gnu' && matrix.channel == 'nightly' # if: matrix.target == 'x86_64-pc-windows-gnu' && matrix.channel == 'nightly'
shell: bash # shell: bash
- name: build # - name: build
run: | # run: |
rustc -Vv # rustc -Vv
cargo -V # cargo -V
# we test without --all-features on Windows so that sha2-asm is not activated. # # we test without --all-features on Windows so that sha2-asm is not activated.
cargo check # cargo check
shell: cmd # shell: cmd