From 3147c4eb2c91c5edd9144e19fd033cf514c9e567 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Tue, 9 Jan 2024 18:48:31 +0100 Subject: [PATCH 1/7] github CI action cronjob --- .github/workflows/update-artifacts.yml | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/update-artifacts.yml diff --git a/.github/workflows/update-artifacts.yml b/.github/workflows/update-artifacts.yml new file mode 100644 index 0000000000..03d947daf0 --- /dev/null +++ b/.github/workflows/update-artifacts.yml @@ -0,0 +1,58 @@ +name: Rust + +on: + schedule: + - cron: "0 0 * * 1" # weekly on Monday at 00:00 UTC + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + +jobs: + check: + name: Renew Artifacts + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + # We run this (up-to-date) node locally to fetch metadata from it for the artifacts + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + # Runs two processes asynchronously: + # - one for the substrate node, timing out after 60s, + # - and one to fetch the metadata from it with the `scripts/artifacts.sh` script. + - name: Fetch artifacts + run: | + { timeout 60s substrate-node --dev --tmp; } & { sleep 15s && scripts/artifacts.sh; } + + # Generate the polkadot.rs file we use for verifying the codegen + - name: Generate polkadot.rs file + run: cargo run --bin subxt -- codegen --file artifacts/polkadot_metadata_full.scale | rustfmt > testing/integration-tests/src/full_client/codegen/polkadot.rs + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + base: master + branch: update-artifacts + branch-suffix: timestamp + title: Update Artifacts (auto-generated) + body: | + This PR updates the artifacts by fetching fresh metadata from a substrate node. + It also recreates the polkadot.rs file used in the integration tests. + + It was created automatically by a Weekly GitHub Action Cronjob. From f5814e960d91f98e709ea35f29bb3b1e2ecae133 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Tue, 9 Jan 2024 18:50:16 +0100 Subject: [PATCH 2/7] add commit message --- .github/workflows/update-artifacts.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-artifacts.yml b/.github/workflows/update-artifacts.yml index 03d947daf0..7aacd06e03 100644 --- a/.github/workflows/update-artifacts.yml +++ b/.github/workflows/update-artifacts.yml @@ -36,12 +36,12 @@ jobs: # Runs two processes asynchronously: # - one for the substrate node, timing out after 60s, # - and one to fetch the metadata from it with the `scripts/artifacts.sh` script. - - name: Fetch artifacts + - name: Fetch Artifacts run: | { timeout 60s substrate-node --dev --tmp; } & { sleep 15s && scripts/artifacts.sh; } # Generate the polkadot.rs file we use for verifying the codegen - - name: Generate polkadot.rs file + - name: Generate polkadot.rs File run: cargo run --bin subxt -- codegen --file artifacts/polkadot_metadata_full.scale | rustfmt > testing/integration-tests/src/full_client/codegen/polkadot.rs - name: Create Pull Request @@ -49,6 +49,7 @@ jobs: with: base: master branch: update-artifacts + commit-message: Update Artifacts (auto-generated) branch-suffix: timestamp title: Update Artifacts (auto-generated) body: | From 36f149402a5d953489f8044ebe160d8441d5bcaf Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Wed, 10 Jan 2024 13:02:35 +0100 Subject: [PATCH 3/7] fix the CI yml files --- .editorconfig | 3 + .github/workflows/build-substrate.yml | 2 +- .github/workflows/nightly.yml | 1 - .github/workflows/rust.yml | 682 ++++++++++++------------- .github/workflows/update-artifacts.yml | 105 ++-- 5 files changed, 399 insertions(+), 394 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9fb23ce694..f0735cedfb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,6 @@ trim_trailing_whitespace = true insert_final_newline = true indent_style = space indent_size = 4 + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/build-substrate.yml b/.github/workflows/build-substrate.yml index 5c660c769a..5f9566a25f 100644 --- a/.github/workflows/build-substrate.yml +++ b/.github/workflows/build-substrate.yml @@ -41,4 +41,4 @@ jobs: name: nightly-substrate-binary path: target/release/substrate-node retention-days: 2 - if-no-files-found: error \ No newline at end of file + if-no-files-found: error diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 3b6dfc0ea4..495d9122fe 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -5,7 +5,6 @@ on: # Run at 8am every day, well after the new binary is built - cron: "0 8 * * *" - env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f47bba5fa3..6c366a9d56 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,350 +1,350 @@ name: Rust on: - push: - # Run jobs when commits are pushed to - # master or release-like branches: - branches: - - master - pull_request: - # Run jobs for any external PR that wants - # to merge to master, too: - branches: - - master + push: + # Run jobs when commits are pushed to + # master or release-like branches: + branches: + - master + pull_request: + # Run jobs for any external PR that wants + # to merge to master, too: + branches: + - master concurrency: - group: ${{ github.ref }}-${{ github.workflow }} - cancel-in-progress: true + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true env: - CARGO_TERM_COLOR: always - # Increase wasm test timeout from 20 seconds (default) to 1 minute. - WASM_BINDGEN_TEST_TIMEOUT: 60 + CARGO_TERM_COLOR: always + # Increase wasm test timeout from 20 seconds (default) to 1 minute. + WASM_BINDGEN_TEST_TIMEOUT: 60 jobs: - check: - name: Cargo check - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Install cargo-hack - uses: baptiste0928/cargo-install@v2 - with: - crate: cargo-hack - version: 0.5 - - # A basic check over all targets together. This may lead to features being combined etc, - # and doesn't test combinations of different features. - - name: Cargo check all targets. - run: cargo check --all-targets - - # Next, check subxt features. - # - `native` feature must always be enabled - # - `web` feature is always ignored. - # - This means, don't check --no-default-features and don't try enabling --all-features; both will fail - - name: Cargo hack; check each subxt feature - run: cargo hack -p subxt --each-feature check --exclude-no-default-features --exclude-all-features --exclude-features web --features native - - # Subxt-signer has the "subxt" features enabled in the "check all targets" test. Run it on its own to - # check it without. We can't enable subxt or web features here, so no cargo hack. - - name: Cargo check subxt-signer - run: | - cargo check -p subxt-signer - cargo check -p subxt-signer --no-default-features --features sr25519,native - cargo check -p subxt-signer --no-default-features --features ecdsa,native - - # We can't enable web features here, so no cargo hack. - - name: Cargo check subxt-lightclient - run: cargo check -p subxt-lightclient - - # Next, check each other package in isolation. - - name: Cargo hack; check each feature/crate on its own - run: cargo hack --exclude subxt --exclude subxt-signer --exclude subxt-lightclient --exclude-all-features --each-feature check --workspace - - # Check the parachain-example code, which isn't a part of the workspace so is otherwise ignored. - - name: Cargo check parachain-example - run: cargo check --manifest-path examples/parachain-example/Cargo.toml - - wasm_check: - name: Cargo check (WASM) - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - target: wasm32-unknown-unknown - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - # Check WASM examples, which aren't a part of the workspace and so are otherwise missed: - - name: Cargo check WASM examples - run: | - cargo check --manifest-path examples/wasm-example/Cargo.toml --target wasm32-unknown-unknown - - fmt: - name: Cargo fmt - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install Rust nightly toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Cargo fmt - uses: actions-rs/cargo@v1.0.3 - with: - command: fmt - args: --all -- --check - - docs: - name: Check documentation and run doc tests - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Check internal documentation links - run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items - - - name: Run cargo test on documentation - uses: actions-rs/cargo@v1.0.3 - with: - command: test - args: --doc - - tests: - name: "Test (Native)" - runs-on: ubuntu-latest-16-cores - timeout-minutes: 45 - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Install cargo-nextest - run: cargo install cargo-nextest - - - name: Run tests - uses: actions-rs/cargo@v1.0.3 - with: - command: nextest - args: run --workspace - - unstable_backend_tests: - name: "Test (Unstable Backend)" - runs-on: ubuntu-latest-16-cores - timeout-minutes: 45 - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Install cargo-nextest - run: cargo install cargo-nextest - - - name: Run tests - uses: actions-rs/cargo@v1.0.3 - with: - command: nextest - args: run --workspace --features unstable-backend-client - - light_client_tests: - name: "Test (Light Client)" - runs-on: ubuntu-latest-16-cores - timeout-minutes: 45 - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Run tests - uses: actions-rs/cargo@v1.0.3 - with: - command: test - args: --release --package integration-tests --features unstable-light-client - - wasm_tests: - name: Test (WASM) - runs-on: ubuntu-latest - timeout-minutes: 45 - env: - # Set timeout for wasm tests to be much bigger than the default 20 secs. - WASM_BINDGEN_TEST_TIMEOUT: 300 - - steps: - - uses: actions/checkout@v4 - - - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - - - name: Install firefox - uses: browser-actions/setup-firefox@latest - - - name: Install chrome - uses: browser-actions/setup-chrome@latest - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Run subxt WASM tests - run: | - # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. - # `node-key` provides a deterministic p2p address. - substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & - wasm-pack test --headless --firefox - wasm-pack test --headless --chrome - pkill substrate-node - working-directory: testing/wasm-rpc-tests - - - name: Run subxt-lightclient WASM tests - run: | - # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. - # `node-key` provides a deterministic p2p address. - substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & - wasm-pack test --headless --firefox - wasm-pack test --headless --chrome - pkill substrate-node - working-directory: testing/wasm-lightclient-tests - - - name: Run subxt-signer WASM tests - run: | - wasm-pack test --headless --firefox - wasm-pack test --headless --chrome - working-directory: signer/wasm-tests - - clippy: - name: Cargo clippy - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - components: clippy - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all-targets -- -D warnings - machete: - name: "Check unused dependencies" - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - - name: Install cargo-machete - run: cargo install cargo-machete - - - name: Check unused dependencies - uses: actions-rs/cargo@v1.0.3 - with: - command: machete + check: + name: Cargo check + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Install cargo-hack + uses: baptiste0928/cargo-install@v2 + with: + crate: cargo-hack + version: 0.5 + + # A basic check over all targets together. This may lead to features being combined etc, + # and doesn't test combinations of different features. + - name: Cargo check all targets. + run: cargo check --all-targets + + # Next, check subxt features. + # - `native` feature must always be enabled + # - `web` feature is always ignored. + # - This means, don't check --no-default-features and don't try enabling --all-features; both will fail + - name: Cargo hack; check each subxt feature + run: cargo hack -p subxt --each-feature check --exclude-no-default-features --exclude-all-features --exclude-features web --features native + + # Subxt-signer has the "subxt" features enabled in the "check all targets" test. Run it on its own to + # check it without. We can't enable subxt or web features here, so no cargo hack. + - name: Cargo check subxt-signer + run: | + cargo check -p subxt-signer + cargo check -p subxt-signer --no-default-features --features sr25519,native + cargo check -p subxt-signer --no-default-features --features ecdsa,native + + # We can't enable web features here, so no cargo hack. + - name: Cargo check subxt-lightclient + run: cargo check -p subxt-lightclient + + # Next, check each other package in isolation. + - name: Cargo hack; check each feature/crate on its own + run: cargo hack --exclude subxt --exclude subxt-signer --exclude subxt-lightclient --exclude-all-features --each-feature check --workspace + + # Check the parachain-example code, which isn't a part of the workspace so is otherwise ignored. + - name: Cargo check parachain-example + run: cargo check --manifest-path examples/parachain-example/Cargo.toml + + wasm_check: + name: Cargo check (WASM) + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + target: wasm32-unknown-unknown + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + # Check WASM examples, which aren't a part of the workspace and so are otherwise missed: + - name: Cargo check WASM examples + run: | + cargo check --manifest-path examples/wasm-example/Cargo.toml --target wasm32-unknown-unknown + + fmt: + name: Cargo fmt + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Rust nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Cargo fmt + uses: actions-rs/cargo@v1.0.3 + with: + command: fmt + args: --all -- --check + + docs: + name: Check documentation and run doc tests + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Check internal documentation links + run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items + + - name: Run cargo test on documentation + uses: actions-rs/cargo@v1.0.3 + with: + command: test + args: --doc + + tests: + name: "Test (Native)" + runs-on: ubuntu-latest-16-cores + timeout-minutes: 45 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Install cargo-nextest + run: cargo install cargo-nextest + + - name: Run tests + uses: actions-rs/cargo@v1.0.3 + with: + command: nextest + args: run --workspace + + unstable_backend_tests: + name: "Test (Unstable Backend)" + runs-on: ubuntu-latest-16-cores + timeout-minutes: 45 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Install cargo-nextest + run: cargo install cargo-nextest + + - name: Run tests + uses: actions-rs/cargo@v1.0.3 + with: + command: nextest + args: run --workspace --features unstable-backend-client + + light_client_tests: + name: "Test (Light Client)" + runs-on: ubuntu-latest-16-cores + timeout-minutes: 45 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Run tests + uses: actions-rs/cargo@v1.0.3 + with: + command: test + args: --release --package integration-tests --features unstable-light-client + + wasm_tests: + name: Test (WASM) + runs-on: ubuntu-latest + timeout-minutes: 45 + env: + # Set timeout for wasm tests to be much bigger than the default 20 secs. + WASM_BINDGEN_TEST_TIMEOUT: 300 + + steps: + - uses: actions/checkout@v4 + + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - name: Install firefox + uses: browser-actions/setup-firefox@latest + + - name: Install chrome + uses: browser-actions/setup-chrome@latest + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Run subxt WASM tests + run: | + # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. + # `node-key` provides a deterministic p2p address. + substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & + wasm-pack test --headless --firefox + wasm-pack test --headless --chrome + pkill substrate-node + working-directory: testing/wasm-rpc-tests + + - name: Run subxt-lightclient WASM tests + run: | + # `listen-addr` is used to configure p2p to accept websocket connections instead of TCP. + # `node-key` provides a deterministic p2p address. + substrate-node --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws > /dev/null 2>&1 & + wasm-pack test --headless --firefox + wasm-pack test --headless --chrome + pkill substrate-node + working-directory: testing/wasm-lightclient-tests + + - name: Run subxt-signer WASM tests + run: | + wasm-pack test --headless --firefox + wasm-pack test --headless --chrome + working-directory: signer/wasm-tests + + clippy: + name: Cargo clippy + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: clippy + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Run clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets -- -D warnings + machete: + name: "Check unused dependencies" + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + - name: Install cargo-machete + run: cargo install cargo-machete + + - name: Check unused dependencies + uses: actions-rs/cargo@v1.0.3 + with: + command: machete diff --git a/.github/workflows/update-artifacts.yml b/.github/workflows/update-artifacts.yml index 7aacd06e03..18d324ef38 100644 --- a/.github/workflows/update-artifacts.yml +++ b/.github/workflows/update-artifacts.yml @@ -1,59 +1,62 @@ -name: Rust +name: Update Artifacts on: - schedule: - - cron: "0 0 * * 1" # weekly on Monday at 00:00 UTC + workflow_dispatch: # Allows manual triggering + schedule: + - cron: "0 0 * * 1" # weekly on Monday at 00:00 UTC concurrency: - group: ${{ github.ref }}-${{ github.workflow }} - cancel-in-progress: true + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true env: - CARGO_TERM_COLOR: always + CARGO_TERM_COLOR: always jobs: - check: - name: Renew Artifacts - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - # We run this (up-to-date) node locally to fetch metadata from it for the artifacts - - name: Use substrate-node binary - uses: ./.github/workflows/actions/use-substrate - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - - # Runs two processes asynchronously: - # - one for the substrate node, timing out after 60s, - # - and one to fetch the metadata from it with the `scripts/artifacts.sh` script. - - name: Fetch Artifacts - run: | - { timeout 60s substrate-node --dev --tmp; } & { sleep 15s && scripts/artifacts.sh; } - - # Generate the polkadot.rs file we use for verifying the codegen - - name: Generate polkadot.rs File - run: cargo run --bin subxt -- codegen --file artifacts/polkadot_metadata_full.scale | rustfmt > testing/integration-tests/src/full_client/codegen/polkadot.rs - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - base: master - branch: update-artifacts - commit-message: Update Artifacts (auto-generated) - branch-suffix: timestamp - title: Update Artifacts (auto-generated) - body: | - This PR updates the artifacts by fetching fresh metadata from a substrate node. - It also recreates the polkadot.rs file used in the integration tests. - - It was created automatically by a Weekly GitHub Action Cronjob. + check: + name: Renew Artifacts + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + # We run this (up-to-date) node locally to fetch metadata from it for the artifacts + - name: Use substrate-node binary + uses: ./.github/workflows/actions/use-substrate + + - name: Install Rust stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Rust Cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 + + # Needs to be built before, so that it starts quickly when called by artifacts script. + - name: Build the CLI tool) + run: cargo build --bin subxt + + # Runs two processes asynchronously: + # - one for the substrate node, timing out after 120s. + # - and one to fetch the metadata from it with the `scripts/artifacts.sh` script. This waits for 30s first to give the node enough time to start up. + - name: Fetch Artifacts + run: | + { timeout 120s substrate-node --dev --tmp; } & { sleep 30s && ./scripts/artifacts.sh; } + # Generate the polkadot.rs file we use for verifying the codegen + - name: Generate polkadot.rs File + run: cargo run --bin subxt -- codegen --file artifacts/polkadot_metadata_full.scale | rustfmt > testing/integration-tests/src/full_client/codegen/polkadot.rs + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + base: master + branch: update-artifacts + commit-message: Update Artifacts (auto-generated) + branch-suffix: timestamp + title: Update Artifacts (auto-generated) + body: | + This PR updates the artifacts by fetching fresh metadata from a substrate node. + It also recreates the polkadot.rs file used in the integration tests. + It was created automatically by a Weekly GitHub Action Cronjob. From 1d730edd39b9f802395113db80bd6385bb83eb56 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Thu, 11 Jan 2024 14:22:30 +0100 Subject: [PATCH 4/7] binary crate for CI script with substrate-runner --- Cargo.lock | 7 +++ Cargo.toml | 1 + scripts/artifacts.sh | 9 +++- scripts/artifacts/.gitignore | 1 + scripts/artifacts/Cargo.lock | 14 ++++++ scripts/artifacts/Cargo.toml | 14 ++++++ scripts/artifacts/src/main.rs | 89 +++++++++++++++++++++++++++++++++++ 7 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 scripts/artifacts/.gitignore create mode 100644 scripts/artifacts/Cargo.lock create mode 100644 scripts/artifacts/Cargo.toml create mode 100644 scripts/artifacts/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index dcc77df9ce..e8e6d55cee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -331,6 +331,13 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "artifacts" +version = "0.33.0" +dependencies = [ + "substrate-runner", +] + [[package]] name = "assert_matches" version = "1.5.0" diff --git a/Cargo.toml b/Cargo.toml index 1aab4d59a8..6ec8ae5b34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ "metadata", "signer", "subxt", + "scripts/artifacts" ] # We exclude any crates that would depend on non mutually diff --git a/scripts/artifacts.sh b/scripts/artifacts.sh index f201e7cf81..3f4750af1d 100755 --- a/scripts/artifacts.sh +++ b/scripts/artifacts.sh @@ -1,5 +1,5 @@ -# # Generates the 3 metadata files in `/artifacts` and the polkadot.rs file for integration tests -# +# # Generates the 4 metadata files in `/artifacts` and the polkadot.rs file for integration tests. + # This script is to be run from the root of the repository: `scripts/artifacts.sh` # # It expects a local polkadot node to be running a JSON-RPC HTTP server at 127.0.0.1:9933 @@ -10,6 +10,11 @@ # cargo build --release # ./target/release/polkadot --dev --tmp # ``` +# +# Instead of this script you can also use the binary crate "scripts/artifacts", +# which you can run with `cargo run --bin artifacts` from the root of the repository. +# It will spawn up a substrate node and generate the artifacts (This is to be preferred for CI jobs) +# # get the full metadata cargo run --bin subxt metadata --version 15 > artifacts/polkadot_metadata_full.scale diff --git a/scripts/artifacts/.gitignore b/scripts/artifacts/.gitignore new file mode 100644 index 0000000000..c41cc9e35e --- /dev/null +++ b/scripts/artifacts/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/scripts/artifacts/Cargo.lock b/scripts/artifacts/Cargo.lock new file mode 100644 index 0000000000..d1fb446b78 --- /dev/null +++ b/scripts/artifacts/Cargo.lock @@ -0,0 +1,14 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "artifacts" +version = "0.1.0" +dependencies = [ + "substrate-runner", +] + +[[package]] +name = "substrate-runner" +version = "0.33.0" diff --git a/scripts/artifacts/Cargo.toml b/scripts/artifacts/Cargo.toml new file mode 100644 index 0000000000..b06ea9da56 --- /dev/null +++ b/scripts/artifacts/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "artifacts" +authors.workspace = true +edition.workspace = true +version.workspace = true +rust-version.workspace = true +license.workspace = true +repository.workspace = true +documentation.workspace = true +homepage.workspace = true +description = "Internal tool to regenerate artifacts" + +[dependencies] +substrate-runner = { workspace = true } diff --git a/scripts/artifacts/src/main.rs b/scripts/artifacts/src/main.rs new file mode 100644 index 0000000000..fa3ecb4315 --- /dev/null +++ b/scripts/artifacts/src/main.rs @@ -0,0 +1,89 @@ +use std::{ + fs::File, + process::{Command, Stdio}, +}; + +use substrate_runner::SubstrateNode; + +/// A Script to generate artifacts that are used in the integration tests. +/// +/// Run with `cargo run --bin artifacts` from the root of the repository. +fn main() { + let mut node_builder = SubstrateNode::builder(); + node_builder.binary_paths(["substrate-node", "substrate"]); + + // Spawn the node and retrieve a ws URL to it: + let proc = node_builder + .spawn() + .map_err(|e| e.to_string()) + .expect("Could not spawn node"); + let node_url = format!("ws://127.0.0.1:{}", proc.ws_port()); + + // Get the full metadata from the spawned substrate node + Command::make(&format!( + "cargo run --bin subxt metadata --version 15 --url {node_url}" + )) + .out("artifacts/polkadot_metadata_full.scale"); + + // Use it to generate polkadot.rs + Command::make("cargo run --bin subxt codegen --file artifacts/polkadot_metadata_full.scale") + .pipe("rustfmt") + .out("testing/integration-tests/src/full_client/codegen/polkadot.rs"); + + // Generate a metadata file that only contains a few pallets that we need for our examples. + Command::make(r#"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets "Balances,Staking,System,Multisig,Timestamp,ParaInherent""#) + .out("artifacts/polkadot_metadata_small.scale"); + + // Generate a metadata file that contains no pallets + Command::make(r#"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets """#) + .out("artifacts/polkadot_metadata_tiny.scale"); + + // Generate a metadata file that only contains some custom metadata + Command::make("cargo run --bin generate-custom-metadata") + .out("artifacts/metadata_with_custom_values.scale"); + + // Generate the polkadot chain spec. + Command::make("cargo run --features chain-spec-pruning --bin subxt chain-spec --url wss://rpc.polkadot.io:443 --output-file artifacts/demo_chain_specs/polkadot.json --state-root-hash --remove-substitutes").spawn().unwrap().wait().unwrap(); +} + +trait CommandT { + /// Creates a new command, parsing the arg_string provided. + fn make(arg_string: &str) -> Self; + + /// Pipes the output of the current command to the next command. + fn pipe(self, arg_string: &str) -> Self; + + /// Writes bytes from stdout to a new file at path. + fn out(self, path: &str); +} + +impl CommandT for Command { + fn make(arg_string: &str) -> Self { + // Note: simple space splitting, no fancy parsing of e.g. quotes surrounding whitespace. + let mut parts = arg_string.split(' '); + let program = parts.next().expect("no program in command string"); + let mut command = Command::new(program); + for e in parts { + command.arg(e); + } + command + } + + fn pipe(mut self, arg_string: &str) -> Self { + // execute self + let old_cmd = self.stdout(Stdio::piped()).spawn().unwrap(); + let mut next_cmd = Self::make(arg_string); + next_cmd.stdin(Stdio::from(old_cmd.stdout.unwrap())); + next_cmd + } + + fn out(mut self, path: &str) { + dbg!(path); + let file = File::create(path).unwrap(); + self.stdout(Stdio::from(file)) + .spawn() + .unwrap() + .wait() + .unwrap(); + } +} From 0fe81589dedaecd99d77126c217b3b264d093ff9 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Thu, 11 Jan 2024 14:22:56 +0100 Subject: [PATCH 5/7] update the CI script --- .github/workflows/update-artifacts.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/update-artifacts.yml b/.github/workflows/update-artifacts.yml index 18d324ef38..fefed66a3d 100644 --- a/.github/workflows/update-artifacts.yml +++ b/.github/workflows/update-artifacts.yml @@ -34,19 +34,13 @@ jobs: - name: Rust Cache uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - # Needs to be built before, so that it starts quickly when called by artifacts script. - - name: Build the CLI tool) - run: cargo build --bin subxt - - # Runs two processes asynchronously: - # - one for the substrate node, timing out after 120s. - # - and one to fetch the metadata from it with the `scripts/artifacts.sh` script. This waits for 30s first to give the node enough time to start up. + # This starts a substrate node and runs a few subxt cli child processes to fetch metadata from it and generate code. + # In particular it generates: + # - 4 metadata (*.scale) files in the `artifacts` directory + # - a polkadot.rs file from the full metadata that is checked in integration tests + # - a polkadot.json in the `artifacts/demo_chain_specs` directory - name: Fetch Artifacts - run: | - { timeout 120s substrate-node --dev --tmp; } & { sleep 30s && ./scripts/artifacts.sh; } - # Generate the polkadot.rs file we use for verifying the codegen - - name: Generate polkadot.rs File - run: cargo run --bin subxt -- codegen --file artifacts/polkadot_metadata_full.scale | rustfmt > testing/integration-tests/src/full_client/codegen/polkadot.rs + run: cargo build --bin artifacts - name: Create Pull Request uses: peter-evans/create-pull-request@v5 From a3c7899a5e6554a7c8649d2d51dcb073e736d1eb Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Thu, 11 Jan 2024 14:58:47 +0100 Subject: [PATCH 6/7] correct the artifacts script --- scripts/artifacts.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/artifacts.sh b/scripts/artifacts.sh index 3f4750af1d..6cae3ca2f6 100755 --- a/scripts/artifacts.sh +++ b/scripts/artifacts.sh @@ -1,8 +1,6 @@ -# # Generates the 4 metadata files in `/artifacts` and the polkadot.rs file for integration tests. - # This script is to be run from the root of the repository: `scripts/artifacts.sh` # -# It expects a local polkadot node to be running a JSON-RPC HTTP server at 127.0.0.1:9933 +# It expects a local polkadot node to be running a JSON-RPC HTTP server at 127.0.0.1:9944 # A local polkadot node can be run via: # ``` # git clone https://github.com/paritytech/polkadot.git From 2bccb275e300d799e188aaeaff4df77cc743312f Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Tue, 16 Jan 2024 11:38:00 +0100 Subject: [PATCH 7/7] remove bash script --- scripts/artifacts.sh | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100755 scripts/artifacts.sh diff --git a/scripts/artifacts.sh b/scripts/artifacts.sh deleted file mode 100755 index 6cae3ca2f6..0000000000 --- a/scripts/artifacts.sh +++ /dev/null @@ -1,29 +0,0 @@ -# This script is to be run from the root of the repository: `scripts/artifacts.sh` -# -# It expects a local polkadot node to be running a JSON-RPC HTTP server at 127.0.0.1:9944 -# A local polkadot node can be run via: -# ``` -# git clone https://github.com/paritytech/polkadot.git -# cd polkadot -# cargo build --release -# ./target/release/polkadot --dev --tmp -# ``` -# -# Instead of this script you can also use the binary crate "scripts/artifacts", -# which you can run with `cargo run --bin artifacts` from the root of the repository. -# It will spawn up a substrate node and generate the artifacts (This is to be preferred for CI jobs) -# - -# get the full metadata -cargo run --bin subxt metadata --version 15 > artifacts/polkadot_metadata_full.scale -# use it to generate polkadot.rs -cargo run --bin subxt codegen --file artifacts/polkadot_metadata_full.scale | rustfmt > testing/integration-tests/src/full_client/codegen/polkadot.rs -# generate a metadata file that only contains a few pallets that we need for our examples. -cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets "Balances,Staking,System,Multisig,Timestamp,ParaInherent" > artifacts/polkadot_metadata_small.scale -# generate a metadata file that contains no pallets -cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets "" > artifacts/polkadot_metadata_tiny.scale -# generate a metadata file that only contains some custom metadata -cargo run --bin generate-custom-metadata > artifacts/metadata_with_custom_values.scale - -# Generate the polkadot chain spec. -cargo run --features chain-spec-pruning --bin subxt chain-spec --url wss://rpc.polkadot.io:443 --output-file artifacts/demo_chain_specs/polkadot.json --state-root-hash --remove-substitutes