Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: checks tool #1385

Closed
wants to merge 77 commits into from
Closed

chore!: checks tool #1385

wants to merge 77 commits into from

Conversation

segfault-magnet
Copy link
Contributor

@segfault-magnet segfault-magnet commented May 17, 2024

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:

  • fuzzy checks
  • compiles with minimum rust
  • public API breakage
  • minimal versions of deps used (e.g. 1.4.3 used when we could have used 1.4.1 -- buys flexibility for our users)
  • check that we don't have more feature flags than we expected (i.e. using optional dependencies for example produces a feature flag)

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

  • I have linked to any relevant issues.
  • I have updated the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary labels.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@segfault-magnet segfault-magnet marked this pull request as ready for review May 21, 2024 19:20
@hal3e hal3e deleted the bug/fix_deps branch June 10, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech-debt Improves code quality or safety
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants