image: cr.weirdboi.dev/base/rust:1-82
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 -- -D warnings
  cache:
    <<: *global_cache
    policy: pull

test:
  stage: test
  script:
    - cargo +nightly 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
  needs:
    - test
    - lint