image: rust:1.82-alpine
stages:
  - test
cache: &global_cache
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .cargo/bin
    - .cargo/registry/index
    - .cargo/registry/cache
    - target/debug/deps
    - target/debug/build
  policy: pull-push

variables:
  CARGO_HOME: ${CI_PROJECT_DIR}/.cargo

lint:
  stage: test
  script:
    - cargo fmt --all --check
    - cargo clippy --offline --frozen --locked -- -D warnings
  cache:
    <<: *global_cache
    policy: pull

test:
  stage: test
  script:
    - cargo install junitify
    - cargo test -- --format=json -Z unstable-options --report-time | junitify --out $CI_PROJECT_DIR/tests/
  artifacts:
    when: always
    reports:
      junit: $CI_PROJECT_DIR/tests/*.xml

package:
  stage: test
  script:
    - cargo package --release
  dependencies:
    - test
    - lint