From 0d9a357c1a507f304dc3c1095049bcdffea9207a Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Sat, 22 Jun 2024 12:58:14 -0500 Subject: [PATCH] ci setup --- .github/workflows/main.yml | 72 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + bencher/Cargo.toml | 3 ++ bencher/tests/markdown.rs | 1 + harness/Cargo.toml | 2 +- harness/benches/ips.rs | 14 ++++--- harness/tests/bpf_program.rs | 4 +- rustfmt.toml | 5 +++ 8 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 rustfmt.toml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..397c2a8 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,72 @@ +name: Main + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + NIGHTLY_TOOLCHAIN: nightly-2023-10-05 + SOLANA_VERSION: 1.18.14 + +jobs: + rust_fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ~/.rustup/toolchains/${{ env.NIGHTLY_TOOLCHAIN }} + key: ${{ runner.os }}-rust-toolchain-${{ env.NIGHTLY_TOOLCHAIN }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.NIGHTLY_TOOLCHAIN }} + components: rustfmt + - name: Run format + run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} fmt --all -- --check + + rust_clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ~/.rustup/toolchains/${{ env.NIGHTLY_TOOLCHAIN }} + key: ${{ runner.os }}-rust-toolchain-${{ env.NIGHTLY_TOOLCHAIN }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.NIGHTLY_TOOLCHAIN }} + components: clippy + - name: Run clippy + run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} clippy --all -- --deny=warnings + + cargo_build_test: + name: Cargo Build and Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ~/.local/share/solana/install/active_release/bin/solana + key: ${{ runner.os }}-solana-${{ env.SOLANA_VERSION }} + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + - uses: metaplex-foundation/actions/install-solana@v1 + with: + version: ${{ env.SOLANA_VERSION }} + - name: Build test program + run: cargo build-sbf --manifest-path test-program/Cargo.toml + - name: Test + run: cargo test diff --git a/Cargo.toml b/Cargo.toml index 617aa4c..250159e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ bincode = "1.3.3" num-format = "0.4.4" serde_json = "1.0.117" solana-bpf-loader-program = "1.18.14" +solana-logger = "1.18.14" solana-program = "1.18.14" solana-program-runtime = "1.18.14" solana-system-program = "1.18.14" diff --git a/bencher/Cargo.toml b/bencher/Cargo.toml index 7e648d3..3c20e8b 100644 --- a/bencher/Cargo.toml +++ b/bencher/Cargo.toml @@ -9,3 +9,6 @@ mollusk = { path = "../harness" } num-format = { workspace = true } serde_json = { workspace = true } solana-sdk = { workspace = true } + +[dev-dependencies] +solana-logger = { workspace = true } \ No newline at end of file diff --git a/bencher/tests/markdown.rs b/bencher/tests/markdown.rs index 9f32ef4..ec3ac31 100644 --- a/bencher/tests/markdown.rs +++ b/bencher/tests/markdown.rs @@ -7,6 +7,7 @@ use { #[test] fn test_markdown() { std::env::set_var("SBF_OUT_DIR", "../target/deploy"); + solana_logger::setup_with(""); let program_id = Pubkey::new_unique(); diff --git a/harness/Cargo.toml b/harness/Cargo.toml index 9b5edb8..4ca0262 100644 --- a/harness/Cargo.toml +++ b/harness/Cargo.toml @@ -9,7 +9,7 @@ solana-bpf-loader-program = { workspace = true } solana-program-runtime = { workspace = true } solana-system-program = { workspace = true } solana-sdk = { workspace = true } -solana-logger = "2.0.0" +solana-logger = { workspace = true } [[bench]] diff --git a/harness/benches/ips.rs b/harness/benches/ips.rs index 30aac2b..7b62d5e 100644 --- a/harness/benches/ips.rs +++ b/harness/benches/ips.rs @@ -1,11 +1,13 @@ //! Benches Mollusk invocation (instructions per second) -use criterion::{criterion_group, criterion_main, Criterion, Throughput}; -use mollusk::{result::Check, Mollusk}; -use solana_sdk::{ - account::AccountSharedData, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, system_instruction, - system_program, +use { + criterion::{criterion_group, criterion_main, Criterion, Throughput}, + mollusk::{result::Check, Mollusk}, + solana_sdk::{ + account::AccountSharedData, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, + system_instruction, system_program, + }, + solana_system_program::system_processor::DEFAULT_COMPUTE_UNITS, }; -use solana_system_program::system_processor::DEFAULT_COMPUTE_UNITS; fn transfer_checked_unchecked(c: &mut Criterion) { let sender = Pubkey::new_unique(); diff --git a/harness/tests/bpf_program.rs b/harness/tests/bpf_program.rs index 274ac05..2c0365a 100644 --- a/harness/tests/bpf_program.rs +++ b/harness/tests/bpf_program.rs @@ -207,7 +207,7 @@ fn test_close_account() { ], &[ Check::err(ProgramError::MissingRequiredSignature), - Check::compute_units(597), + Check::compute_units(598), ], ); } @@ -222,7 +222,7 @@ fn test_close_account() { ], &[ Check::success(), - Check::compute_units(2557), + Check::compute_units(2558), Check::account(&key) .data(&[]) .lamports(0) diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..47fe23a --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,5 @@ +comment_width = 80 +format_strings = true +group_imports = "One" +imports_granularity = "One" +wrap_comments = true \ No newline at end of file