image: "r.lcr.gr/microhacks/bevy-builder"

stages:
  - test
  - deploy

test-linux:
  stage: test
  before_script:
    - export CARGO_HOME="${CI_PROJECT_DIR}/.cargo"
    - export PATH="${CI_PROJECT_DIR}/.cargo/bin:$PATH"
  cache:
    key: build-cache-linux
    paths:
      - .cargo/registry/cache
      - .cargo/registry/index
      - .cargo/git/db
      - .cargo/bin/
      - target/
  script:
    - cargo test --release


build-linux:
  stage: deploy
  before_script:
    - export CARGO_HOME="${CI_PROJECT_DIR}/.cargo"
    - export PATH="${CI_PROJECT_DIR}/.cargo/bin:$PATH"
  cache:
    key: build-cache-linux
    paths:
      - .cargo/registry/cache
      - .cargo/registry/index
      - .cargo/git/db
      - .cargo/bin/
      - target/
  script:
    - cargo build --release
    - strip target/release/crunch
  artifacts:
    name: crunch.linux.x86
    paths:
      - target/release/crunch
    expire_in: 1 day
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - when: manual

build-windows:
  stage: deploy
  before_script:
    - export CARGO_HOME="${CI_PROJECT_DIR}/.cargo"
    - export PATH="${CI_PROJECT_DIR}/.cargo/bin:$PATH"
  cache:
    key: build-cache-windows
    paths:
      - .cargo/registry/cache
      - .cargo/registry/index
      - .cargo/git/db
      - .cargo/bin/
      - target/
  script:
    - cargo build --release --target x86_64-pc-windows-gnu
  artifacts:
    expire_in: 1 day
    paths:
      - target/x86_64-pc-windows-gnu/release/crunch.exe
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - when: manual

pages:
  image: node:18-alpine
  script:
    - cd docs
    - npm ci
    - npm run build
    - mv public ../
  artifacts:
    paths:
      - public
    expire_in: 4 days
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - when: manual