[tools]
node = "latest"
pnpm = "latest"
"cargo:prek" = "latest"
"prettier" = "3.6.2"
"npm:@commitlint/cli" = "19.7.1"
"npm:@commitlint/config-conventional" = "19.7.1"
"cargo:wasm-pack" = "latest"
"cargo:hyperfine" = "latest"
"cargo:mdbook" = "0.4.52"
"cargo:mdbook-callouts" = "0.2.2"
"cargo:mdbook-inline-highlighting" = "1.0.0"
"cargo:rumdl" = "0.1.18"


[settings]
# Note: If you have cargo-binstall installed, this will make tool installs much faster
cargo.binstall = true

[tasks.'install-nightly']
description = "Install rust nightly, which is needed for clippy"
run = [
  "rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt clippy",
]

[tasks.build]
description = "Build default targets. Run with --release for a release build."
run = "cargo build --workspace"

[tasks.example]
description = "Run an example"
run = "cargo run --example {{arg(name='example', default='')}}"

[tasks.examples]
description = "Run all examples"
run = '''
for example in $(cargo build --example 2>&1 | tail -n +3); do \
  mise run example "$example"; \
done
'''

[tasks.docs]
description = "Build the Rust cli docs, API docs and Ixa website"
run = '''
  cargo run --features write_cli_usage --example basic-infection -- --markdown-help
  cargo doc --all-features --no-deps
  rm -rf website/doc
  cp -r target/doc website
  mdbook build docs/book -d ../../website/book
'''

[tasks.test-all]
description = "Run all tests"
depends = ["test:unit", "test:wasm"]

[tasks.test]
description = "Run rust tests. Faster than test-all"
depends = ["test:unit"]

[tasks.'test:unit']
description = "Run all unit tests"
run = "cargo test --all-targets --workspace"

[tasks.'test:core']
description = "Run just the core ixa tests (much faster)"
run = "cargo test -p ixa"

[tasks.'test:book']
description = "Build and run the Ixa Book disease model example against local ixa"
dir = "docs/book/models/disease_model"
run = '''
  cargo run \
    --config 'patch."https://github.com/CDCgov/ixa".ixa.path="../../../.."'
'''

[tasks.'test:wasm']
description = "Run wasm integration tests"
dir = "integration-tests/ixa-wasm-tests"
depends = ["wasm:pnpm", "wasm:compile"]
run = "pnpm exec playwright test"

[tasks.'test:features']
description = "Run just the core ixa tests (much faster)"
run = "cargo test --no-default-features"

[tasks.'wasm:pnpm']
dir = "integration-tests/ixa-wasm-tests"
run = ["pnpm install", "pnpm exec playwright install"]
sources = ['package.json', 'pnpm-lock.yaml', 'mise.toml']
outputs = 'node_modules/.pnpm/lock.yaml'

[tasks.'wasm:compile']
env.RUSTFLAGS = '--cfg getrandom_backend="wasm_js"'
dir = "integration-tests/ixa-wasm-tests"
run = "wasm-pack build --target web"
sources = ["src/*.rs", "Cargo.toml"]
outputs = "pkg"

[tasks.'bench']
description = "Run all benchmarks"
run = ["mise run bench:hyperfine", "mise run bench:criterion"]

[tasks.'bench:criterion']
description = "Run all Criterion benchmarks (optionally pass a specific name)"
run = "cargo bench -p ixa-bench {{arg(name='name', default='')}}"

[tasks.'bench:create']
description = "Compare benchmarks against a Criterion baseline"
run = "cargo bench -p ixa-bench {{arg(name='name', default='')}} -- --save-baseline {{arg(name='baseline')}}"

[tasks.'bench:compare']
description = "Compare benchmarks against a Criterion baseline"
run = [
  "cargo bench -p ixa-bench {{arg(name='name', default='')}} -- --baseline {{arg(name='baseline')}}",
  "cargo run -q -p ixa-bench --bin check_criterion_regressions",
]

[tasks.'build:hyperfine']
description = "Build the benchmark utilities binaries"
run = "cargo build -p ixa-bench --release"
sources = ["ixa-bench/src/**/*.rs", 'Cargo.toml', "ixa-bench/Cargo.toml"]
outputs = "target/release/hyperfine"

[tasks.'test:hyperfine']
description = "Run one hyperfine run"
run = "mise bench:hyperfine --warmup=0 --runs=1"

[tasks.'bench:hyperfine']
depends = "build:hyperfine"
run = './target/release/hyperfine'

[tasks.check-all]
run = ["mise run check:*"]

[tasks.check]
description = "Run rust checks. Faster than check-all"
depends = ["check:rust"]

[tasks.'check:rust']
depends = "install-nightly"
run = [
  # cargo check compiles everything without the final step of code generation
  # --all-targets ensures we include --lib --bins --tests --benches --examples
  "cargo check --all-targets --workspace --all-features",
  "cargo +nightly fmt --check",
  "cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings",
]

[tasks.prettier]
description = "Run prettier on all supported files"
run = '''prettier --cache --{{arg(name='action', default='check')}} \
  "*.{yml,yaml}" "{.github,.devcontainer,.claude,.vscode}/**/*.{json,yml,yaml}" \
  "{docs,examples,integration-tests,ixa-derive,ixa-fips,ixa-bench}/**/*.{json,yml,yaml}" \
  --ignore-path ./.gitignore \
  --ignore-path ./integration-tests/ixa-wasm-tests/.gitignore
'''

[tasks.'check:markdown']
run = "rumdl check ."

[tasks.'lint:commit-msg']
description = "Lint commit messages (Conventional Commits)"
run = "commitlint --config ./commitlint.config.cjs --edit {{arg(name='file', default='.git/COMMIT_EDITMSG')}}"

[tasks.fix-all]
description = "Auto-fix formatting and linting issues"
depends = "fix:*"

[tasks.fix]
description = "Fix rust code. Faster than fix-all"
depends = ["fix:rust"]

[tasks.'fix:markdown']
run = "rumdl check --fix ."

[tasks.'fix:rust']
run = [
  "cargo +nightly clippy --fix --workspace --all-targets --allow-dirty --all-features -- -D warnings",
  "cargo +nightly fmt",
]

[tasks.clean]
description = "Remove build artifacts"
run = '''
  cargo clean
  rm -rf pkg integration-tests/ixa-wasm-tests/{pkg,node_modules}
  rm -rf website/{doc,debug,book}
  rm -f website/{.rustc_info.json,.rustdoc_fingerprint.json}
  rm -rf examples/**/output/*.csv
'''

[tasks.precommit]
depends = ['check-all']

[tasks.prepush]
description = "Check everything before pushing"
env.RUSTFLAGS = "-D warnings"
run = ["mise precommit", "mise examples", "mise docs", "mise test-all"]

[tasks.'docker:build']
run = "docker build -t ixa-bench ."

[tasks.'docker:run']
depends = "docker:build"
run = "docker run --rm -it -v \"$PWD\":/home/runner/ixa ixa-bench"

[tasks.'hooks:install']
run = "prek install --hook-type pre-commit --hook-type commit-msg"

[tasks.'hooks:clear']
description = "Remove all hooks"
run = "rm -rf .git/hooks"
