FuelLabs / fuels-rs

Fuel Network Rust SDK
https://fuellabs.github.io/fuels-rs
Apache License 2.0
44.17k stars 1.34k forks source link

chore!: checks tool #1385

Closed segfault-magnet closed 4 months ago

segfault-magnet commented 4 months ago

Breaking

The feature of fuels called fuels-test-helpers is now called test-helpers.

Description

A single place to write all our code checks in the future. All CI checks are now calls to the checks binary. That means if it passes locally 99% your CI is going to pass.

There are three flavors of tests currently:

  -f, --flavor <FLAVOR>
          Used to enable/disable tests that take too long/are too resource intense [default: normal] [possible values: normal, hack-features, hack-deps]

normal gets you exactly what the CI is going to run. Basically tests, fmt, typos, clippy, check, doc tests, doc links, md anchors, etc, for all packages. Also wasm tests and e2e tests with various combinations of using the binary vs library, type paths vs no type paths.

hack-features will try out every feature combination on each of our workspace members separately while denying warnings. This catches invalid feature combinations and dead code.

hack-deps uses udeps and the nightly compiler to detect dependencies that should be feature-gated.

Planned flavors:

Running: Tasks are described in rust over in tasks/builder.rs. Choosing a flavor uses the builder to define what is run for each flavor.

The smallest unit of work is a Task. All tasks are run in parallel (might need to be controlled if you end up having issues due to slower hardware):

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Task {
    pub cwd: PathBuf,
    pub cmd: Command,
}

cwd is the folder from which the task is to be run cmd is defined as:

pub enum Command {
    Custom {
        program: String,
        args: Vec<String>,
        env: Vec<(String, String)>,
        deps: deps::Deps,
    },
    MdCheck,
}

Either a built in check MdCheck (this is the unused/missing anchors check) or a custom command. Any future custom logic will extend Command.

Deps is defined as:

pub struct Deps {
    pub fuel_core_binary: bool,
    pub rust: Option<Rust>,
    pub wasm: bool,
    pub cargo: Cargo,
    pub typos_cli: bool,
    pub sway_artifacts: Option<Sway>,
}

It details what is expected of the environment the tasks are to be run it. This is needed for setting up the CI.

You can list all the tasks available under a flavor by doing:

> cargo run --bin checks -- --root . --flavor normal --list-tasks
Task 3c3b5bf5db3dbf96, dir: "/home/segfault_magnet/fuel/fuels-rs", RUSTFLAGS='-Dwarnings' cargo clippy --workspace --all-features
Task b91aedfb88bd5e29, dir: "/home/segfault_magnet/fuel/fuels-rs", cargo-machete --skip-target-dir
Task 55083cd0351d2255, dir: "/home/segfault_magnet/fuel/fuels-rs", typos 
Task 9b8883a398eb92cd, dir: "/home/segfault_magnet/fuel/fuels-rs", MdCheck
Task 64b3c193d580125e, dir: "/home/segfault_magnet/fuel/fuels-rs/e2e", RUSTFLAGS='-Dwarnings' cargo fmt --verbose --check
Task 3bec6b98d024e8b1, dir: "/home/segfault_magnet/fuel/fuels-rs/e2e", RUSTFLAGS='-Dwarnings' cargo nextest run --features default,fuel-core-lib
Task 624b24c79b1b3f09, dir: "/home/segfault_magnet/fuel/fuels-rs/e2e", typos 
Task 6ecdf8c081ab8416, dir: "/home/segfault_magnet/fuel/fuels-rs/examples/codec", RUSTFLAGS='-Dwarnings' cargo clippy --all-targets --all-features --no-deps
/// more ....

You can use the CLI further choose tasks by their ID or their cwd.

The output is also written in a way that you can just copy-paste the command to run it in the terminal:

RUSTFLAGS='-Dwarnings' cargo clippy --workspace --all-features

is going to run just fine and produce the same result.

Jobs for the CI are generated by doing:

cargo run --bin checks -- --root . --dump-ci-config

You'll get a json array for each CI job that is to be run. Example:

  {
    "deps": {
      "fuel_core_binary": false,
      "rust": {
        "nightly": false,
        "components": "clippy,rustfmt"
      },
      "wasm": false,
      "cargo": {
        "hack": false,
        "nextest": true,
        "machete": false,
        "udeps": false
      },
      "typos_cli": true
    },
    "task_ids": "9a994aef339e078a,62b9f40762a9aad1,d921a49816b8b205,59c5e2771e680c36,7d8ca3b3df198bcf,9df99488b4c07d3d",
    "name": "packages/fuels-test-helpers",
    "cache_key": "ef302be3014a4a14"
  },
  // more

This details the ids of the tasks that are to be run as a single job in the CI. Rust should be setup with clippy and fmt, nextest needs to be available and the typos tool. The display name of this job is scripts/fuels-tests-helpers which will show up in the CI GUI.

The CI jobs are formed by grouping all generated tasks by the directory in which they are to be run. This is done so that we reuse the compiled artifacts rather than redo the work in multiple different jobs.

Whatever grouping of tasks we define, checks will unify all their dependencies and list them in the deps part of the CI job config so that the CI can install them.

Checklist