From a92f8093acfd28618bfed2ff3d21f9e8dadc67dc Mon Sep 17 00:00:00 2001 From: Shreevatsa N Date: Thu, 26 Sep 2024 17:43:32 +0530 Subject: [PATCH] Test CI Signed-off-by: Shreevatsa N --- .github/scripts/generate_lists.sh | 74 +++++++++++ .github/scripts/generate_package_lists.sh | 29 +++++ .../ci-on-pr-rustfmt-test-clippy-build.yml | 117 +++++++----------- 3 files changed, 151 insertions(+), 69 deletions(-) create mode 100755 .github/scripts/generate_lists.sh create mode 100755 .github/scripts/generate_package_lists.sh diff --git a/.github/scripts/generate_lists.sh b/.github/scripts/generate_lists.sh new file mode 100755 index 00000000..bcc2fa0c --- /dev/null +++ b/.github/scripts/generate_lists.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Define the input text with packages +input_text=$(cat << EOF +authority-membership = { path = "runtimes/common/authorities", default-features = false } +identifier = { package = "cord-identifier", path = "primitives/identifier", default-features = false } +cord-node-cli = { path = "node/cli", default-features = false } +cord-primitives = { path = "primitives/cord", default-features = false } +network-membership = { path = "primitives/network-membership", default-features = false } +cord-braid-runtime = { path = "runtimes/braid", default-features = false } +cord-braid-runtime-constants = { path = "runtimes/braid/constants", default-features = false } +cord-runtime-common = { path = "runtimes/common", default-features = false } +cord-loom-runtime = { path = "runtimes/loom", default-features = false } +cord-loom-runtime-constants = { path = "runtimes/loom/constants", default-features = false } +cord-weave-runtime = { path = "runtimes/weave", default-features = false } +cord-weave-runtime-constants = { path = "runtimes/weave/constants", default-features = false } +cord-node-service = { path = "node/service", default-features = false } +cord-node-inspect = { path = "node/inspect", default-features = false } +cord-node-rpc = { path = "node/rpc", default-features = false } +cord-node-testing = { path = "node/testing", default-features = false } +cord-test-utils = { path = "test-utils", default-features = false } +cord-service-test = { path = "test-utils/service", default-features = false } +cord-test-runtime = { path = "test-utils/runtime", default-features = false } +cord-test-client = { path = "test-utils/client", default-features = false } +cord-test-runtime-client = { path = "test-utils/runtime/client", default-features = false } +cord-test-runtime-transaction-pool = { path = "test-utils/runtime/transaction-pool", default-features = false } +cord-cli-test-utils = { path = "test-utils/cli", default-features = false } +cord-utilities = { path = "utilities", default-features = false } +pallet-membership = { path = 'pallets/membership/', default-features = false } +pallet-config = { path = 'pallets/config/', default-features = false } +pallet-did = { path = 'pallets/did', default-features = false } +pallet-did-name = { path = 'pallets/did-name', default-features = false } +pallet-schema = { path = 'pallets/schema', default-features = false } +pallet-chain-space = { path = 'pallets/chain-space', default-features = false } +pallet-statement = { path = 'pallets/statement', default-features = false } +pallet-network-membership = { path = 'pallets/network-membership', default-features = false } +pallet-runtime-upgrade = { path = 'pallets/runtime-upgrade', default-features = false } +pallet-identity = { path = 'pallets/identity', default-features = false } +pallet-offences = { path = 'pallets/offences', default-features = false } +pallet-node-authorization = { path = "pallets/node-authorization", default-features = false } +pallet-network-score = { path = 'pallets/network-score', default-features = false } +pallet-session-benchmarking = { path = 'pallets/session-benchmarking', default-features = false } +pallet-assets-runtime-api = { path = "runtimes/common/api/assets", default-features = false } +pallet-did-runtime-api = { path = "runtimes/common/api/did", default-features = false } +pallet-transaction-weight-runtime-api = { path = "runtimes/common/api/weight", default-features = false } +pallet-registries = { path = "pallets/registries", default-features = false } +pallet-entries = { path = "pallets/entries", default-features = false } +EOF +) + +# Define output files +packages_with_feature="packages_with_runtime_benchmarks.txt" +packages_without_feature="packages_without_runtime_benchmarks.txt" + +# Clear existing files +> $packages_with_feature +> $packages_without_feature + +# Process the input text +echo "$input_text" | while read -r line; do + # Extract the package name + package_name=$(echo "$line" | cut -d '=' -f 1 | tr -d ' ') + + # Check if it contains 'runtime-benchmarks' (adjust according to your context) + if echo "$line" | grep -q "runtime-benchmarks"; then + echo "$package_name" >> $packages_with_feature + else + echo "$package_name" >> $packages_without_feature + fi +done + +# Output the results +echo "Packages with 'runtime-benchmarks' feature are stored in $packages_with_feature" +echo "Packages without 'runtime-benchmarks' feature are stored in $packages_without_feature" diff --git a/.github/scripts/generate_package_lists.sh b/.github/scripts/generate_package_lists.sh new file mode 100755 index 00000000..979100f8 --- /dev/null +++ b/.github/scripts/generate_package_lists.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Files to store the package names +packages_with_feature="packages_with_runtime_benchmarks.txt" +packages_without_feature="packages_without_runtime_benchmarks.txt" + +# Empty the files if they already exist +> $packages_with_feature +> $packages_without_feature + +# Find Cargo.toml files and check for the feature +for cargo_file in $(find . -name "Cargo.toml"); do + if grep -q "\[features\]" "$cargo_file"; then + if grep -q "runtime-benchmarks" "$cargo_file"; then + package_name=$(basename $(dirname "$cargo_file")) + echo "$package_name" >> $packages_with_feature + else + package_name=$(basename $(dirname "$cargo_file")) + echo "$package_name" >> $packages_without_feature + fi + else + package_name=$(basename $(dirname "$cargo_file")) + echo "$package_name" >> $packages_without_feature + fi +done + +# Output the result +echo "Packages with 'runtime-benchmarks' feature are stored in $packages_with_feature" +echo "Packages without 'runtime-benchmarks' feature are stored in $packages_without_feature" diff --git a/.github/workflows/ci-on-pr-rustfmt-test-clippy-build.yml b/.github/workflows/ci-on-pr-rustfmt-test-clippy-build.yml index 7faceb8c..0962dd17 100644 --- a/.github/workflows/ci-on-pr-rustfmt-test-clippy-build.yml +++ b/.github/workflows/ci-on-pr-rustfmt-test-clippy-build.yml @@ -1,11 +1,10 @@ -name: ci +name: CI + on: pull_request: paths-ignore: - "**.md" - "doc/**" - - # Allows to run this workflow manually from the Actions tab workflow_dispatch: defaults: @@ -17,97 +16,77 @@ env: CARGO_TERM_COLOR: always jobs: - rustfmt: + setup: runs-on: ubuntu-latest steps: - - name: checkout repository + - name: Checkout repository uses: actions/checkout@v4.1.1 - - name: install dependencies + - name: Install dependencies run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libssl-dev - - name: install rust nightly - run: rustup toolchain install nightly - - - name: show active toolchain - run: rustup show active-toolchain - - - name: add nightly rustfmt - run: rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu - - - name: cache rust toolchain and dependencies + - name: Cache Cargo registry and target uses: actions/cache@v4 with: path: | - ~/.cargo/ + ~/.cargo/registry + ~/.cargo/git target/ - key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-rust- + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- - - name: rustfmt - run: cargo +nightly fmt --all -- --check + - name: Install Rust nightly + run: rustup toolchain install nightly - test: + - name: Show active toolchain + run: rustup show active-toolchain + + - name: Add nightly rustfmt and clippy + run: | + rustup component add rustfmt + rustup component add clippy + + rustfmt: runs-on: ubuntu-latest - needs: rustfmt + needs: setup steps: - - name: checkout repository + - name: Checkout repository uses: actions/checkout@v4.1.1 - - - name: install dependencies - run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libssl-dev - - - name: cache - uses: actions/cache@v4 - with: - path: | - ~/.cargo/ - target/ - key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-rust- - - - name: cargo test - run: rustup component add rust-src && cargo test --release --all --all-targets --features=runtime-benchmarks --no-fail-fast --verbose --color always + + - name: Run rustfmt + run: | + cargo +nightly fmt --all -- --check clippy: runs-on: ubuntu-latest needs: rustfmt steps: - - name: checkout repository + - name: Checkout repository uses: actions/checkout@v4.1.1 + + - name: Run cargo clippy + run: | + echo "Running clippy for the entire workspace" + cargo clippy --all --no-deps --features "runtime-benchmarks" -- -D warnings - - name: install dependencies - run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libssl-dev + test: + runs-on: ubuntu-latest + needs: rustfmt + steps: + - name: Checkout repository + uses: actions/checkout@v4.1.1 - - name: cache + - name: Cache Cargo registry and target uses: actions/cache@v4 with: path: | - ~/.cargo/ + ~/.cargo/registry + ~/.cargo/git target/ - key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-rust- - - - name: cargo clippy - run: rustup component add rust-src && cargo clippy --all --no-deps --all-targets --features=runtime-benchmarks -- -D warnings - - # build: - # runs-on: ubuntu-latest - # needs: rustfmt - # steps: - # - name: checkout repository - # uses: actions/checkout@v4.1.1 - # - name: install dependencies - # run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libssl-dev - - # - name: cache - # uses: actions/cache@v4 - # with: - # path: | - # ~/.cargo/ - # target/ - # key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} - # restore-keys: ${{ runner.os }}-rust- - # - name: cargo build - # run: rustup component add rust-src && cargo build --locked + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + - name: Run tests with runtime-benchmarks + run: | + echo "Running tests for all packages" + cargo test --release --all --features "runtime-benchmarks" --no-fail-fast