stages:
  - prepare
  - build
  - sign
  - pack
  - deploy

variables:
  GIT_DEPTH: "1"
  #USE_IRRKLANG: "1"

mat_lua:
  stage: prepare
  tags: 
    - linux
  script:
    - apt update; apt -y install wget tar
    - wget -O - https://cdn01.moecube.com/ygopro-build-materials/lua-5.3.6.tar.gz | tar zfx -
    - mv lua-5.3.6 lua
    - cp premake/lua/premake5.lua lua/;
  artifacts:
    paths:
      - lua

mat_linux:
  stage: prepare
  tags:
    - linux
  script:
    - apt update; apt -y install git wget tar
    #- git clone --depth=1 https://code.mycard.moe/mycard/irrlicht irrlicht_linux
    - wget -O - https://cdn01.moecube.com/ygopro-build-materials/premake-5.0.0-beta1-linux.tar.gz | tar zfx -
  artifacts:
    paths:
      - premake5
      #- irrlicht_linux

mat_windows:
  stage: prepare
  tags:
    - linux
  script:
    - apt update; apt -y install wget tar patch p7zip-full
    # premake5.exe
    - wget https://cdn01.moecube.com/ygopro-build-materials/premake-5.0.0-beta1-windows.zip
    - 7z x -y premake-5.0.0-beta1-windows.zip
    # event
    - wget -O - https://cdn01.moecube.com/ygopro-build-materials/libevent-2.0.22-stable.tar.gz | tar zfx -
    - mv libevent-2.0.22-stable event
    # sqlite3
    - wget https://cdn01.moecube.com/ygopro-build-materials/sqlite-amalgamation-3310100.zip
    - 7z x -y sqlite-amalgamation-3310100.zip
    - mv sqlite-amalgamation-3310100 sqlite3
  artifacts:
    paths:
      - premake5.exe
      - event
      - sqlite3

exec_windows:
  stage: build
  tags:
    - vs
  dependencies:
    - mat_lua
    - mat_windows
  #variables:
  #  irrklang_pro: '1'
  cache:
    paths:
      - bin/
      - obj/
  script:
    - git submodule update --init
    - bash -c 'cp -rf premake/* .'
    #- cmd /C "patch -p0 < irrlicht\irrlicht.patch"
    - '.\premake5.exe vs2019'
    - cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" build\YGOPro.sln /m /p:Configuration=Release'
    - copy bin\release\ygopro.exe .
  artifacts:
    paths:
      - ygopro.exe

exec_linux:
  stage: build
  tags:
    - linux
  dependencies:
    #- mat_irrklang
    - mat_lua
    - mat_linux
  cache:
    paths:
      - bin/
      - obj/
  script:
    - apt update; apt -y install git build-essential libevent-dev libsqlite3-dev
    - git submodule update --init
    - ./premake5 gmake
    - cd build
    - make config=release -j$(nproc)
    - cd ..
    - mv bin/release/ygopro .
    - strip ygopro
  artifacts:
    paths:
      - ygopro

#win_server_pack:
#  stage: pack
#  dependencies:
#    - exec_windows
#  tags:
#    - linux
#  script:
#    - apt update; apt -y install p7zip-full wget
#    - wget https://nodejs.org/dist/v14.17.0/node-v14.17.0-win-x64.7z


upload_to_minio:
  stage: deploy
  dependencies:
    - exec_windows
  tags: 
    - linux
  image: python
  script:
    - pip install -U -i https://mirrors.aliyun.com/pypi/simple/ awscli
    - aws s3 --endpoint=https://minio.mycard.moe:9000 cp ygopro.exe s3://mycard/mcpro-server/ygopro.exe
  only:
    - server
