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

variables:
  BINARY_FOLDER: game_core
  BINARY_NAME: trader_tales
  OUTPUT_NAME: trader_tales

stages:
  - build
  - package

build-windows:
  stage: build
  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 -p ${BINARY_FOLDER} --target x86_64-pc-windows-gnu
  artifacts:
    expire_in: 1 day
    paths:
      - target/x86_64-pc-windows-gnu/release/trader_tales.exe
  only:
    - trunk

build-linux:
  stage: build
  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 -p ${BINARY_FOLDER} --target x86_64-unknown-linux-gnu
  artifacts:
    expire_in: 1 day
    paths:
      - target/x86_64-unknown-linux-gnu/release/trader_tales
  only:
    - trunk

package-all:
  stage: package
  script:
    - mkdir -p dist/
    - make assets
    - cp -r assets dist/assets
    - ls target/x86_64-unknown-linux-gnu/release/
    - ls target/x86_64-pc-windows-gnu/release/
    - cp target/x86_64-unknown-linux-gnu/release/${BINARY_NAME} "dist/${OUTPUT_NAME}"
    - cp target/x86_64-pc-windows-gnu/release/${BINARY_NAME}.exe "dist/${OUTPUT_NAME}.exe"
    - cd "${CI_PROJECT_DIR}/dist" && zip -r "windows.zip" "./${OUTPUT_NAME}.exe" ./assets
    - cd "${CI_PROJECT_DIR}/dist" && zip -r "linux.x86.zip" "./${OUTPUT_NAME}" ./assets
  dependencies:
    - build-windows
    - build-linux
  artifacts:
    expire_in: 7 days
    paths:
      - dist/windows.zip
      - dist/linux.x86.zip
  only:
    - trunk
