Skip to content

Commit

Permalink
Merge pull request #22 from alloy-rs/zerosnacks/add-github-workflows
Browse files Browse the repository at this point in the history
Add Github CI workflow
  • Loading branch information
zerosnacks authored Mar 27, 2024
2 parents 3a3cfe0 + d9ff19d commit ecee2d8
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 15 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Runs weeky `cargo update` to keep dependencies current.

name: Update dependencies

on:
schedule:
# Run weekly
- cron: "0 0 * * SUN"
workflow_dispatch:
# Needed so we can run it manually

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: cargo-update
TITLE: "chore(deps): weekly `cargo update`"
BODY: |
Automation to keep dependencies in `Cargo.lock` current.
<details><summary><strong>cargo update log</strong></summary>
<p>
```log
$cargo_update_log
```
</p>
</details>
jobs:
update:
name: Update
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly

- name: cargo update
# Remove first line that always just says "Updating crates.io index"
run: cargo update --color never 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log

- name: craft commit message and PR body
id: msg
run: |
export cargo_update_log="$(cat cargo_update.log)"
echo "commit_message<<EOF" >> $GITHUB_OUTPUT
printf "$TITLE\n\n$cargo_update_log\n" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$BODY" | envsubst >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
add-paths: ./Cargo.lock
commit-message: ${{ steps.msg.outputs.commit_message }}
title: ${{ env.TITLE }}
body: ${{ steps.msg.outputs.body }}
branch: ${{ env.BRANCH }}
74 changes: 74 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Runs Alloy integration tests daily to ensure compatibility with the latest version of Alloy.

name: Alloy integration test

on:
schedule:
# Run daily
- cron: "0 0 * * *"
workflow_dispatch:
# Needed so we can run it manually

jobs:
update:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: foundry-rs/foundry-toolchain@v1
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Run examples
run: |
# Get the list of runable examples
export examples="$(
cargo run --example 2>&1 \
| grep -E '^ ' \
| grep -v \
-e 'trezor_signer' \
-e 'ledger_signer' \
-e 'yubi_signer' \
-e 'ipc' \
-e 'ws' \
-e 'ws_auth' \
| xargs -n1 echo
)"
# Run the examples with the current version of Alloy
for example in $examples; do
cargo run --example $example --quiet 1>/dev/null
if [ $? -ne 0 ]; then
echo "Failed to run: $example"
exit 1
else
echo "Successfully ran: $example"
fi
done
# Fetch the latest commit hash of the main branch from the Alloy repository
export latest_alloy_commit=$(git ls-remote https://github.com/alloy-rs/alloy.git \
| grep refs/heads/main \
| cut -f 1)
# Use the commit hash to update the rev in Cargo.toml
sed -i 's/\(alloy = { git = "https:\/\/github.com\/alloy-rs\/alloy", rev = "\)[^"]*/\1'"$latest_alloy_commit"'/' \
Cargo.toml
# Update to the latest commit
cargo update
# Run the examples with the latest version of Alloy
for example in $examples; do
cargo run --example $example --quiet 1>/dev/null
if [ $? -ne 0 ]; then
echo "Failed to run: $example"
exit 1
else
echo "Successfully ran: $example"
fi
done
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: CI
# Runs `clippy` and `cargo fmt` checks.

name: Lint

on:
push:
Expand All @@ -15,7 +17,7 @@ concurrency:
jobs:
clippy:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@clippy
Expand All @@ -28,7 +30,7 @@ jobs:

fmt:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Runs build checks and examples.

name: Test

on:
push:
branches: [main]
pull_request:

env:
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
checks:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: cargo hack
run: cargo hack check --feature-powerset --depth 2

examples:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: foundry-rs/foundry-toolchain@v1
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Run examples
run: |
# Get the list of runable examples
export examples="$(
cargo run --example 2>&1 \
| grep -E '^ ' \
| grep -v \
-e 'trezor_signer' \
-e 'ledger_signer' \
-e 'yubi_signer' \
-e 'ipc' \
-e 'ws' \
-e 'ws_auth' \
| xargs -n1 echo
)"
# Run the examples
for example in $examples; do
cargo run --example $example --quiet 1>/dev/null
if [ $? -ne 0 ]; then
echo "Failed to run: $example"
exit 1
else
echo "Successfully ran: $example"
fi
done
2 changes: 1 addition & 1 deletion examples/anvil/examples/fork_anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use eyre::Result;
async fn main() -> Result<()> {
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().fork("https://eth.llamarpc.com").try_spawn()?;
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

println!("Anvil running at `{}`", anvil.endpoint());

Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/examples/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sol!(
async fn main() -> Result<()> {
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().fork("https://eth.llamarpc.com").try_spawn()?;
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

// Create a provider.
let provider =
Expand Down
6 changes: 4 additions & 2 deletions examples/providers/examples/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
// Setup the HTTP transport which is consumed by the RPC client
let anvil = Anvil::new().spawn();
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().block_time(1).try_spawn()?;

let pk = &anvil.keys()[0];
let from = anvil.addresses()[0];
let signer = Wallet::from(pk.to_owned());

// Setup the HTTP transport which is consumed by the RPC client
let rpc_client = RpcClient::new_http(anvil.endpoint().parse().unwrap());
let provider_with_signer = ProviderBuilder::new()
.signer(EthereumSigner::from(signer))
Expand Down
5 changes: 4 additions & 1 deletion examples/subscriptions/examples/event_multiplexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ sol!(

#[tokio::main]
async fn main() -> Result<()> {
let anvil = Anvil::new().block_time(1).spawn();
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().block_time(1).try_spawn()?;

let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint());
let provider = RootProvider::<Ethereum, _>::new(RpcClient::connect_pubsub(ws).await?);

Expand Down
5 changes: 4 additions & 1 deletion examples/subscriptions/examples/subscribe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use futures_util::{stream, StreamExt};

#[tokio::main]
async fn main() -> Result<()> {
let anvil = Anvil::new().block_time(1).spawn();
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().block_time(1).try_spawn()?;

let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint());
let provider = RootProvider::<Ethereum, _>::new(RpcClient::connect_pubsub(ws).await?);

Expand Down
3 changes: 2 additions & 1 deletion examples/subscriptions/examples/watch_contract_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ sol!(

#[tokio::main]
async fn main() -> Result<()> {
let anvil = Anvil::new().block_time(1).spawn();
let anvil = Anvil::new().block_time(1).try_spawn()?;

let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint());
let provider = RootProvider::<Ethereum, _>::new(RpcClient::connect_pubsub(ws).await?);

Expand Down
5 changes: 4 additions & 1 deletion examples/transactions/examples/gas_price_usd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ sol!(

#[tokio::main]
async fn main() -> Result<()> {
let anvil = Anvil::new().fork("https://eth.merkle.io").spawn();
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

let url = anvil.endpoint().parse().unwrap();
let provider = HttpProvider::<Ethereum>::new_http(url);

Expand Down
5 changes: 4 additions & 1 deletion examples/transactions/examples/trace_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use reqwest::Url;

#[tokio::main]
async fn main() -> Result<()> {
let anvil = Anvil::new().fork("https://eth.merkle.io").spawn();
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

let provider =
HttpProvider::<Ethereum>::new_http("https://eth.merkle.io".parse::<Url>().unwrap());

Expand Down
5 changes: 4 additions & 1 deletion examples/transactions/examples/trace_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
let anvil = Anvil::new().fork("https://eth.merkle.io").spawn();
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

let url = anvil.endpoint().parse().unwrap();
let provider = HttpProvider::<Ethereum>::new_http(url);
let hash = fixed_bytes!("97a02abf405d36939e5b232a5d4ef5206980c5a6661845436058f30600c52df7"); // Hash of the tx we want to trace
Expand Down
5 changes: 4 additions & 1 deletion examples/transactions/examples/transfer_erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ sol!(ERC20Example, "examples/contracts/ERC20Example.json");

#[tokio::main]
async fn main() -> Result<()> {
let anvil = Anvil::new().fork("https://eth.merkle.io").spawn();
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

let url = anvil.endpoint().parse().unwrap();
let provider = HttpProvider::<Ethereum>::new_http(url);

Expand Down
5 changes: 4 additions & 1 deletion examples/transactions/examples/transfer_eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
let anvil = Anvil::new().fork("https://eth.merkle.io").spawn();
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

let url = anvil.endpoint().parse().unwrap();
let provider = HttpProvider::<Ethereum>::new_http(url);

Expand Down

0 comments on commit ecee2d8

Please sign in to comment.