image: barichello/godot-ci:mono-4.4

workflow:
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'

include:
  - component: $CI_SERVER_FQDN/guided-explorations/ci-components/ultimate-auto-semversioning/ultimate-auto-semversioning@1.2.8

# NOTE: If your `project.godot` is at the repository root, set `PROJECT_PATH` below to ".".

# Cache imported assets between runs
cache:
  key: import-assets
  paths:
    - .godot/imported/

stages:
  - import-assets
  - export
  - deploy

variables:
  EXPORT_NAME: Cirno_No_Reason
  PROJECT_PATH: .

# Open the editor to import assets in case the cache was empty or outdated
import-assets:
  stage: import-assets
  script:
    - godot --headless --verbose --editor --quit

linux:
  stage: export
  script:
    - mkdir -v -p build/linux
    - GIT_ASSEMBLY_SEM_FILE_VER="${GitVersion_Major}.${GitVersion_Minor}.${GitVersion_Patch}.0"
    - GIT_ASSEMBLY_SEM_VER="${GitVersion_Major}.${GitVersion_Minor}.${GitVersion_Patch}.0"
    - EXPORT_DIR="$(readlink -f build)"
    - cd $PROJECT_PATH
    - godot --headless --verbose --export-release "Linux" "$EXPORT_DIR/linux/$EXPORT_NAME.x86_64"
  artifacts:
    name: $EXPORT_NAME-$CI_JOB_NAME
    paths:
      - build/linux

windows:
  stage: export
  script:
    - mkdir -v -p build/windows
    - GIT_ASSEMBLY_SEM_FILE_VER="${GitVersion_Major}.${GitVersion_Minor}.${GitVersion_Patch}.0"
    - GIT_ASSEMBLY_SEM_VER="${GitVersion_Major}.${GitVersion_Minor}.${GitVersion_Patch}.0"
    - EXPORT_DIR="$(readlink -f build)"
    - cd $PROJECT_PATH
    - godot --headless --verbose --export-release "Windows Desktop" "$EXPORT_DIR/windows/$EXPORT_NAME.exe"
  artifacts:
    name: $EXPORT_NAME-$CI_JOB_NAME
    paths:
      - build/windows

# Itch.io Deploy
itchio:linux:
  stage: deploy
  script:
    - butler push ./build/linux $ITCHIO_USERNAME/$ITCHIO_GAME:linux --userversion ${GitVersion_FullSemVer}
  dependencies:
    - linux

itchio:windows:
  stage: deploy
  script:
    - butler push ./build/windows $ITCHIO_USERNAME/$ITCHIO_GAME:windows --userversion ${GitVersion_FullSemVer}
  dependencies:
    - windows

