diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml new file mode 100644 index 00000000..d6ab7bed --- /dev/null +++ b/.github/workflows/CI.yaml @@ -0,0 +1,135 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +defaults: + run: + working-directory: contracts # 👈 all cargo commands run in contracts/ + +jobs: + format: + name: Format Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - name: Check formatting + run: cargo fmt --all -- --check + + clippy: + name: Clippy Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - name: Cache cargo registry + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + contracts/target + key: ${{ runner.os }}-cargo-${{ hashFiles('contracts/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + - name: Run clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - name: Cache cargo registry + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + contracts/target + key: ${{ runner.os }}-cargo-test-${{ hashFiles('contracts/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-test- + ${{ runner.os }}-cargo- + - name: Run tests + run: cargo test --all --verbose + + build: + name: Build Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - name: Cache cargo registry + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + contracts/target + key: ${{ runner.os }}-cargo-build-${{ hashFiles('contracts/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-build- + ${{ runner.os }}-cargo- + - name: Build all crates + run: cargo build --all --verbose + + wasm-check: + name: WASM Compatibility Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + - name: Cache cargo registry + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + contracts/target + key: ${{ runner.os }}-cargo-wasm-${{ hashFiles('contracts/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-wasm- + ${{ runner.os }}-cargo- + - name: Build for WASM target + run: cargo build --all --target wasm32-unknown-unknown --verbose + + ci-success: + name: CI Success + runs-on: ubuntu-latest + needs: [format, clippy, test, build, wasm-check] + if: always() + defaults: + run: + working-directory: . + steps: + - name: Check all jobs + run: | + if [[ "${{ needs.format.result }}" != "success" || \ + "${{ needs.clippy.result }}" != "success" || \ + "${{ needs.test.result }}" != "success" || \ + "${{ needs.build.result }}" != "success" || \ + "${{ needs.wasm-check.result }}" != "success" ]]; then + echo "One or more CI jobs failed" + exit 1 + fi + echo "All CI jobs passed successfully" \ No newline at end of file diff --git a/contracts/.github/workflows/CI.yaml b/contracts/.github/workflows/CI.yaml deleted file mode 100644 index 6bdb17f5..00000000 --- a/contracts/.github/workflows/CI.yaml +++ /dev/null @@ -1,53 +0,0 @@ -name: CI -on: - pull_request: - branches: [main, develop] - push: - branches: [main, develop] - -jobs: - build-and-test: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Cache Rust dependencies - 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- - - - name: Install Rust stable toolchain - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - components: rustfmt, clippy - - - name: Install Rust nightly toolchain - uses: dtolnay/rust-toolchain@nightly - with: - toolchain: nightly - components: rustfmt, clippy - - - name: Install soroban-cli - run: cargo install soroban-cli --locked - - - name: Check formatting - run: cargo +nightly fmt --all -- --check - - - name: Check compilation - run: cargo +nightly check --all - - - name: Run clippy lints - run: cargo +nightly clippy --all -- -D warnings - - - name: Run unit tests - run: cargo +nightly test --all \ No newline at end of file diff --git a/contracts/assetsup_contract/src/lib.rs b/contracts/assetsup_contract/src/lib.rs index a27f9446..2ff3d4d4 100644 --- a/contracts/assetsup_contract/src/lib.rs +++ b/contracts/assetsup_contract/src/lib.rs @@ -1,10 +1,10 @@ #![no_std] -use soroban_sdk::{contract, contracttype, contractimpl, Address, Env}; +use soroban_sdk::{Address, Env, contract, contractimpl, contracttype}; #[contracttype] #[derive(Clone, Debug, Eq, PartialEq)] pub enum DataKey { - Admin + Admin, } #[contract] @@ -12,7 +12,7 @@ pub struct AssetUpContract; #[contractimpl] impl AssetUpContract { - pub fn initialize(env: Env, admin: Address){ + pub fn initialize(env: Env, admin: Address) { admin.require_auth(); if env.storage().persistent().has(&DataKey::Admin) { @@ -26,4 +26,4 @@ impl AssetUpContract { } } -mod tests; \ No newline at end of file +mod tests; diff --git a/contracts/assetsup_contract/src/tests/initialize.rs b/contracts/assetsup_contract/src/tests/initialize.rs index 11500f32..b1f865e3 100644 --- a/contracts/assetsup_contract/src/tests/initialize.rs +++ b/contracts/assetsup_contract/src/tests/initialize.rs @@ -1,10 +1,9 @@ - #![cfg(test)] extern crate std; -use soroban_sdk::{testutils::{Address as _,}, Address, Env}; use crate::{AssetUpContract, AssetUpContractClient}; +use soroban_sdk::{Address, Env, testutils::Address as _}; /// Setup test environment with contract and addresses pub fn setup_test_environment() -> (Env, AssetUpContractClient<'static>, Address) { @@ -13,9 +12,9 @@ pub fn setup_test_environment() -> (Env, AssetUpContractClient<'static>, Address let contract_id = env.register(AssetUpContract, ()); let client = AssetUpContractClient::new(&env, &contract_id); - + let admin = Address::generate(&env); - + (env, client, admin) } @@ -28,11 +27,10 @@ fn test_initialize() { assert_eq!(admin, saved_admin); } - #[test] #[should_panic()] fn test_initialize_panic() { let (_env, client, admin) = setup_test_environment(); client.initialize(&admin); client.initialize(&admin); -} \ No newline at end of file +} diff --git a/contracts/assetsup_contract/src/tests/mod.rs b/contracts/assetsup_contract/src/tests/mod.rs index 63ce31e6..1c89e973 100644 --- a/contracts/assetsup_contract/src/tests/mod.rs +++ b/contracts/assetsup_contract/src/tests/mod.rs @@ -1 +1 @@ -mod initialize; \ No newline at end of file +mod initialize;