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

feat(zk_toolbox): Update lint CI with zk_toolbox #2694

Merged
merged 59 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3f33ef9
Add linter ci
matias-gonz Aug 20, 2024
1c35d1a
Update lint ci
matias-gonz Aug 20, 2024
3b50db8
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 20, 2024
0a3c31a
Add build step to code lint
matias-gonz Aug 20, 2024
84fe2f4
Merge branch 'matias-migrate-lint-ci' of github.com:matter-labs/zksyn…
matias-gonz Aug 20, 2024
25f4756
Add need option
matias-gonz Aug 20, 2024
fea982f
Add ZKSYNC_HOME
matias-gonz Aug 20, 2024
3bd0d9a
Update lint ci
matias-gonz Aug 22, 2024
834f951
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 22, 2024
4b208c1
Add external build workflow
matias-gonz Aug 26, 2024
2317867
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 26, 2024
fa3d0f6
Update build workflow
matias-gonz Aug 26, 2024
4e927fb
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 26, 2024
deebec3
Update ci if
matias-gonz Aug 26, 2024
5620311
Merge branch 'matias-migrate-lint-ci' of github.com:matter-labs/zksyn…
matias-gonz Aug 26, 2024
180eae7
Add wait for workflow
matias-gonz Aug 26, 2024
75698b3
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 26, 2024
8548f9f
trigger ci
matias-gonz Aug 26, 2024
7d54fca
Merge branch 'matias-migrate-lint-ci' of github.com:matter-labs/zksyn…
matias-gonz Aug 26, 2024
64bbfbf
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 26, 2024
baa8426
restore changes
matias-gonz Aug 26, 2024
56c7db4
update lint
matias-gonz Aug 26, 2024
3a23838
Add dep installation
matias-gonz Aug 26, 2024
6575f84
add ci_run
matias-gonz Aug 26, 2024
ab41306
Add db check
matias-gonz Aug 26, 2024
f07bb46
Add ecosystem init
matias-gonz Aug 26, 2024
02f681a
Update safe dir
matias-gonz Aug 26, 2024
3368ed7
move git config
matias-gonz Aug 26, 2024
faa2b91
Disable db check
matias-gonz Aug 26, 2024
a537644
Make contract lint an option
matias-gonz Aug 26, 2024
4ba7452
Remove unstable features flag
matias-gonz Aug 26, 2024
e821056
lint
matias-gonz Aug 26, 2024
9ca1599
lint
matias-gonz Aug 26, 2024
3f208fa
Add database check
matias-gonz Aug 26, 2024
c4dd88c
Add permissions
matias-gonz Aug 26, 2024
d98babc
Pre create volume dir
matias-gonz Aug 26, 2024
10d6db6
Add postgres volume
matias-gonz Aug 26, 2024
495e70f
Add rethdata dir
matias-gonz Aug 26, 2024
812b266
update ci_localnet_up
matias-gonz Aug 26, 2024
b12939c
fix
matias-gonz Aug 26, 2024
50b3b7b
use zk service for db
matias-gonz Aug 26, 2024
4099f2e
Fix db check command
matias-gonz Aug 26, 2024
400e107
Add ecosystem init
matias-gonz Aug 26, 2024
c96aa6c
Setup db with zk
matias-gonz Aug 27, 2024
6977249
Move db check to other ci
matias-gonz Aug 27, 2024
eb6360f
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 27, 2024
866b66d
Remove reth chaindata creation from ci
matias-gonz Aug 27, 2024
1bf1a35
Merge branch 'matias-migrate-lint-ci' of github.com:matter-labs/zksyn…
matias-gonz Aug 27, 2024
0c36ba9
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 27, 2024
631a805
Remove not needed `bach -c`
matias-gonz Aug 27, 2024
9af6149
Merge branch 'matias-migrate-lint-ci' of github.com:matter-labs/zksyn…
matias-gonz Aug 27, 2024
4e33283
Use zkt
matias-gonz Aug 27, 2024
a669e16
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 27, 2024
d2a991c
Merge branch 'main' into matias-migrate-lint-ci
matias-gonz Aug 27, 2024
e1a9995
Change extension to target
matias-gonz Aug 27, 2024
1ab5b37
Remove contracts option
matias-gonz Aug 27, 2024
63a50ac
Update readme
matias-gonz Aug 27, 2024
f732037
Merge branch 'main' of github.com:matter-labs/zksync-era into matias-…
matias-gonz Aug 27, 2024
a057740
Update ci
matias-gonz Aug 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .github/workflows/ci-core-lint-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions .github/workflows/ci-zk-toolbox-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
- name: Run server
run: |
ci_run zk_inception server --ignore-prerequisites &>server.log &
Expand Down
3 changes: 2 additions & 1 deletion zk_toolbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,12 @@ 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.
- `md`: Markdown files.
- `sol`: Solidity files.
- `js`: JavaScript files.
- `ts`: TypeScript files.
- `contracts`: files in `contracts` directory.
27 changes: 13 additions & 14 deletions zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ 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(());
}

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()?,
Expand Down Expand Up @@ -68,7 +68,7 @@ pub enum Formatter {
Contract,
Prettier {
#[arg(short, long)]
extensions: Vec<Extension>,
targets: Vec<Target>,
},
}

Expand All @@ -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 {
Expand All @@ -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()
}
Expand Down
69 changes: 31 additions & 38 deletions zk_toolbox/crates/zk_supervisor/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Extension>,
#[clap(long, short = 't')]
pub targets: Vec<Target>,
}

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)?,
}
}
Expand All @@ -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");
Expand All @@ -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"]);
}
Expand All @@ -79,34 +73,35 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R
Ok(())
}

fn get_linter(extension: &Extension) -> Vec<String> {
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<String> {
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![]
Expand All @@ -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");
Expand Down
7 changes: 4 additions & 3 deletions zk_toolbox/crates/zk_supervisor/src/commands/lint_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@ 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<Vec<String>> {
pub fn get_unignored_files(shell: &Shell, target: &Target) -> anyhow::Result<Vec<String>> {
let mut files = Vec::new();
let output = cmd!(shell, "git ls-files --recurse-submodules").read()?;

for line in output.lines() {
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);
}
Expand Down
23 changes: 10 additions & 13 deletions zk_toolbox/crates/zk_supervisor/src/messages.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<String> = 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<String> = 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";
Expand Down
Loading