diff --git a/.github/workflows/ci-core-lint-reusable.yml b/.github/workflows/ci-core-lint-reusable.yml index 2fa6cde5fdeb..e7c8b5340194 100644 --- a/.github/workflows/ci-core-lint-reusable.yml +++ b/.github/workflows/ci-core-lint-reusable.yml @@ -19,23 +19,20 @@ jobs: - name: Start services run: | - mkdir -p ./volumes/postgres - run_retried docker compose pull zk postgres - docker compose up -d zk postgres + ci_localnet_up ci_run sccache --start-server - - name: Setup db + - name: Build run: | - ci_run zk - ci_run run_retried rustup show - ci_run zk db migrate + ci_run ./bin/zkt + ci_run yarn install + ci_run git config --global --add safe.directory /usr/src/zksync - name: Lints run: | - ci_run zk fmt --check - ci_run zk lint rust --check - ci_run zk lint toolbox --check - ci_run zk lint js --check - ci_run zk lint ts --check - ci_run zk lint md --check - ci_run zk db check-sqlx-data + ci_run zk_supervisor fmt --check + ci_run zk_supervisor lint -t md --check + ci_run zk_supervisor lint -t sol --check + ci_run zk_supervisor lint -t js --check + ci_run zk_supervisor lint -t ts --check + ci_run zk_supervisor lint -t rs --check diff --git a/.github/workflows/ci-zk-toolbox-reusable.yml b/.github/workflows/ci-zk-toolbox-reusable.yml index b2fc10c28aae..ed07174a66df 100644 --- a/.github/workflows/ci-zk-toolbox-reusable.yml +++ b/.github/workflows/ci-zk-toolbox-reusable.yml @@ -115,6 +115,10 @@ jobs: --prover-db-url=postgres://postgres:notsecurepassword@postgres:5432 \ --prover-db-name=zksync_prover_localhost_rollup + - name: Check Database + run: | + ci_run zk_supervisor database check-sqlx-data + - name: Run server run: | ci_run zk_inception server --ignore-prerequisites &>server.log & diff --git a/zk_toolbox/README.md b/zk_toolbox/README.md index debbb511df3f..ab567627d7bd 100644 --- a/zk_toolbox/README.md +++ b/zk_toolbox/README.md @@ -342,7 +342,7 @@ Lint code: zks lint ``` -By default, this command runs the linter on all files. To target specific file types, use the `--extension` option. +By default, this command runs the linter on all files. To target specific file types, use the `--target` option. Supported extensions include: - `rs`: Rust files. @@ -350,3 +350,4 @@ Supported extensions include: - `sol`: Solidity files. - `js`: JavaScript files. - `ts`: TypeScript files. +- `contracts`: files in `contracts` directory. diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs b/zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs index fa0f4cef7bfe..5ee0c4efb343 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs @@ -6,16 +6,16 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use crate::{ - commands::lint_utils::{get_unignored_files, Extension}, + commands::lint_utils::{get_unignored_files, Target}, messages::{ msg_running_fmt_for_extension_spinner, msg_running_fmt_for_extensions_spinner, msg_running_rustfmt_for_dir_spinner, MSG_RUNNING_CONTRACTS_FMT_SPINNER, }, }; -async fn prettier(shell: Shell, extension: Extension, check: bool) -> anyhow::Result<()> { - let spinner = Spinner::new(&msg_running_fmt_for_extension_spinner(extension)); - let files = get_unignored_files(&shell, &extension)?; +async fn prettier(shell: Shell, target: Target, check: bool) -> anyhow::Result<()> { + let spinner = Spinner::new(&msg_running_fmt_for_extension_spinner(target)); + let files = get_unignored_files(&shell, &target)?; if files.is_empty() { return Ok(()); @@ -23,7 +23,7 @@ async fn prettier(shell: Shell, extension: Extension, check: bool) -> anyhow::Re spinner.freeze(); let mode = if check { "--check" } else { "--write" }; - let config = format!("etc/prettier-config/{extension}.js"); + let config = format!("etc/prettier-config/{target}.js"); Ok( Cmd::new(cmd!(shell, "yarn --silent prettier {mode} --config {config}").args(files)) .run()?, @@ -68,7 +68,7 @@ pub enum Formatter { Contract, Prettier { #[arg(short, long)] - extensions: Vec, + targets: Vec, }, } @@ -85,8 +85,7 @@ pub async fn run(shell: Shell, args: FmtArgs) -> anyhow::Result<()> { match args.formatter { None => { let mut tasks = vec![]; - let extensions: Vec<_> = - vec![Extension::Js, Extension::Ts, Extension::Md, Extension::Sol]; + let extensions: Vec<_> = vec![Target::Js, Target::Ts, Target::Md, Target::Sol]; let spinner = Spinner::new(&msg_running_fmt_for_extensions_spinner(&extensions)); spinner.freeze(); for ext in extensions { @@ -108,13 +107,13 @@ pub async fn run(shell: Shell, args: FmtArgs) -> anyhow::Result<()> { } }); } - Some(Formatter::Prettier { mut extensions }) => { - if extensions.is_empty() { - extensions = vec![Extension::Js, Extension::Ts, Extension::Md, Extension::Sol]; + Some(Formatter::Prettier { mut targets }) => { + if targets.is_empty() { + targets = vec![Target::Js, Target::Ts, Target::Md, Target::Sol]; } - let spinner = Spinner::new(&msg_running_fmt_for_extensions_spinner(&extensions)); - for ext in extensions { - prettier(shell.clone(), ext, args.check).await? + let spinner = Spinner::new(&msg_running_fmt_for_extensions_spinner(&targets)); + for target in targets { + prettier(shell.clone(), target, args.check).await? } spinner.finish() } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/lint.rs b/zk_toolbox/crates/zk_supervisor/src/commands/lint.rs index 17c8680f1d24..1861d164ce44 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/lint.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/lint.rs @@ -4,7 +4,7 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use crate::{ - commands::lint_utils::{get_unignored_files, Extension}, + commands::lint_utils::{get_unignored_files, Target}, messages::{ msg_running_linter_for_extension_spinner, msg_running_linters_for_files, MSG_LINT_CONFIG_PATH_ERR, MSG_RUNNING_CONTRACTS_LINTER_SPINNER, @@ -17,31 +17,32 @@ const CONFIG_PATH: &str = "etc/lint-config"; pub struct LintArgs { #[clap(long, short = 'c')] pub check: bool, - #[clap(long, short = 'e')] - pub extensions: Vec, + #[clap(long, short = 't')] + pub targets: Vec, } pub fn run(shell: &Shell, args: LintArgs) -> anyhow::Result<()> { - let extensions = if args.extensions.is_empty() { + let targets = if args.targets.is_empty() { vec![ - Extension::Rs, - Extension::Md, - Extension::Sol, - Extension::Js, - Extension::Ts, + Target::Rs, + Target::Md, + Target::Sol, + Target::Js, + Target::Ts, + Target::Contracts, ] } else { - args.extensions.clone() + args.targets.clone() }; - logger::info(msg_running_linters_for_files(&extensions)); + logger::info(msg_running_linters_for_files(&targets)); let ecosystem = EcosystemConfig::from_file(shell)?; - for extension in extensions { - match extension { - Extension::Rs => lint_rs(shell, &ecosystem, args.check)?, - Extension::Sol => lint_contracts(shell, &ecosystem, args.check)?, + for target in targets { + match target { + Target::Rs => lint_rs(shell, &ecosystem, args.check)?, + Target::Contracts => lint_contracts(shell, &ecosystem, args.check)?, ext => lint(shell, &ecosystem, &ext, args.check)?, } } @@ -50,7 +51,7 @@ pub fn run(shell: &Shell, args: LintArgs) -> anyhow::Result<()> { } fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::Result<()> { - let spinner = Spinner::new(&msg_running_linter_for_extension_spinner(&Extension::Rs)); + let spinner = Spinner::new(&msg_running_linter_for_extension_spinner(&Target::Rs)); let link_to_code = &ecosystem.link_to_code; let lint_to_prover = &ecosystem.link_to_code.join("prover"); @@ -61,14 +62,7 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R for path in paths { let _dir_guard = shell.push_dir(path); let mut cmd = cmd!(shell, "cargo clippy"); - let common_args = &[ - "--locked", - "--", - "-D", - "warnings", - "-D", - "unstable_features", - ]; + let common_args = &["--locked", "--", "-D", "warnings"]; if !check { cmd = cmd.args(&["--fix", "--allow-dirty"]); } @@ -79,34 +73,35 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R Ok(()) } -fn get_linter(extension: &Extension) -> Vec { - match extension { - Extension::Rs => vec!["cargo".to_string(), "clippy".to_string()], - Extension::Md => vec!["markdownlint".to_string()], - Extension::Sol => vec!["solhint".to_string()], - Extension::Js => vec!["eslint".to_string()], - Extension::Ts => vec!["eslint".to_string(), "--ext".to_string(), "ts".to_string()], +fn get_linter(target: &Target) -> Vec { + match target { + Target::Rs => vec!["cargo".to_string(), "clippy".to_string()], + Target::Md => vec!["markdownlint".to_string()], + Target::Sol => vec!["solhint".to_string()], + Target::Js => vec!["eslint".to_string()], + Target::Ts => vec!["eslint".to_string(), "--ext".to_string(), "ts".to_string()], + Target::Contracts => vec![], } } fn lint( shell: &Shell, ecosystem: &EcosystemConfig, - extension: &Extension, + target: &Target, check: bool, ) -> anyhow::Result<()> { - let spinner = Spinner::new(&msg_running_linter_for_extension_spinner(extension)); + let spinner = Spinner::new(&msg_running_linter_for_extension_spinner(target)); let _dir_guard = shell.push_dir(&ecosystem.link_to_code); - let files = get_unignored_files(shell, extension)?; + let files = get_unignored_files(shell, target)?; let cmd = cmd!(shell, "yarn"); let config_path = ecosystem.link_to_code.join(CONFIG_PATH); - let config_path = config_path.join(format!("{}.js", extension)); + let config_path = config_path.join(format!("{}.js", target)); let config_path = config_path .to_str() .expect(MSG_LINT_CONFIG_PATH_ERR) .to_string(); - let linter = get_linter(extension); + let linter = get_linter(target); let fix_option = if check { vec![] @@ -128,8 +123,6 @@ fn lint( } fn lint_contracts(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::Result<()> { - lint(shell, ecosystem, &Extension::Sol, check)?; - let spinner = Spinner::new(MSG_RUNNING_CONTRACTS_LINTER_SPINNER); let _dir_guard = shell.push_dir(&ecosystem.link_to_code); let cmd = cmd!(shell, "yarn"); diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/lint_utils.rs b/zk_toolbox/crates/zk_supervisor/src/commands/lint_utils.rs index 92fac6ea815f..6d7bef6eb459 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/lint_utils.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/lint_utils.rs @@ -33,15 +33,16 @@ const IGNORED_FILES: [&str; 4] = [ #[derive(Debug, ValueEnum, EnumIter, strum::Display, PartialEq, Eq, Clone, Copy)] #[strum(serialize_all = "lowercase")] -pub enum Extension { +pub enum Target { Md, Sol, Js, Ts, Rs, + Contracts, } -pub fn get_unignored_files(shell: &Shell, extension: &Extension) -> anyhow::Result> { +pub fn get_unignored_files(shell: &Shell, target: &Target) -> anyhow::Result> { let mut files = Vec::new(); let output = cmd!(shell, "git ls-files --recurse-submodules").read()?; @@ -49,7 +50,7 @@ pub fn get_unignored_files(shell: &Shell, extension: &Extension) -> anyhow::Resu let path = line.to_string(); if !IGNORED_DIRS.iter().any(|dir| path.contains(dir)) && !IGNORED_FILES.contains(&path.as_str()) - && path.ends_with(&format!(".{}", extension)) + && path.ends_with(&format!(".{}", target)) { files.push(path); } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index de25be281328..00e49131de77 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -1,4 +1,4 @@ -use crate::commands::lint_utils::Extension; +use crate::commands::lint_utils::Target; // Ecosystem related messages pub(super) const MSG_CHAIN_NOT_FOUND_ERR: &str = "Chain not found"; @@ -152,28 +152,25 @@ pub(super) const MSG_CONTRACTS_CLEANING_FINISHED: &str = pub(super) const MSG_RUNNING_SNAPSHOT_CREATOR: &str = "Running snapshot creator"; // Lint related messages -pub(super) fn msg_running_linters_for_files(extensions: &[Extension]) -> String { - let extensions: Vec = extensions.iter().map(|e| format!(".{}", e)).collect(); - format!( - "Running linters for files with extensions: {:?}", - extensions - ) +pub(super) fn msg_running_linters_for_files(targets: &[Target]) -> String { + let targets: Vec = targets.iter().map(|e| format!(".{}", e)).collect(); + format!("Running linters for targets: {:?}", targets) } -pub(super) fn msg_running_linter_for_extension_spinner(extension: &Extension) -> String { - format!("Running linter for files with extension: .{}", extension) +pub(super) fn msg_running_linter_for_extension_spinner(target: &Target) -> String { + format!("Running linter for files with extension: .{}", target) } -pub(super) fn msg_running_fmt_for_extension_spinner(extension: Extension) -> String { - format!("Running prettier for: {extension:?}") +pub(super) fn msg_running_fmt_for_extension_spinner(target: Target) -> String { + format!("Running prettier for: {target:?}") } pub(super) fn msg_running_rustfmt_for_dir_spinner(dir: &str) -> String { format!("Running rustfmt for: {dir:?}") } -pub(super) fn msg_running_fmt_for_extensions_spinner(extensions: &[Extension]) -> String { - format!("Running prettier for: {extensions:?} and rustfmt") +pub(super) fn msg_running_fmt_for_extensions_spinner(targets: &[Target]) -> String { + format!("Running prettier for: {targets:?} and rustfmt") } pub(super) const MSG_LINT_CONFIG_PATH_ERR: &str = "Lint config path error";