image: rust:latest

.rust_cache: &rust_cache
  cache:
    # key: $CI_COMMIT_REF_SLUG
    paths:
      # Don't include `incremental` to save space
      # Debug
      - target/debug/build/
      - target/debug/deps/
      - target/debug/.fingerprint/
      - target/debug/.cargo-lock
      # Release
      - target/release/build/
      - target/release/deps/
      - target/release/.fingerprint/
      - target/release/.cargo-lock

before_script:
  - apt-get update -qq && apt-get install -y -qq libinput-dev libseat-dev libudev-dev libgtk-3-dev grep llvm clang libclang-dev libsdl2-dev libsdl2-gfx-dev

stages:
  - format
  - check
  - test
  - release
  - deploy

format:
  except:
    - tags
  <<: *rust_cache
  script:
    - echo "nightly" > rust-toolchain
    - rustup component add rustfmt
    - cargo fmt --check

check:
  except:
    - tags
  <<: *rust_cache
  script:
    - rustup component add clippy
    - cargo check
    # deny currently catches too much
    #- cargo install cargo-deny && cargo deny
    - cargo install cargo-cranky && cargo cranky

test:
  except:
    - tags
  <<: *rust_cache
  script:
    - mkdir -p .git/hooks > /dev/null
    - cargo test --all

release:
  only:
    - tags
  <<: *rust_cache
  script:
    - cargo install cargo-vendor-filterer
    - make && make vendor
  artifacts:
    paths:
      - vendor_asusctl*.tar.xz
      - cargo-config

pages:
  stage: deploy
  only:
    - tags
  <<: *rust_cache
  script:
    - cargo doc --document-private-items --no-deps --workspace
    - rm -rf public
    - mkdir public
    - cp -R target/doc/* public
    - cp extra/index.html public
  artifacts:
    paths:
      - public

variables:
  GIT_SUBMODULE_STRATEGY: normal
