variables:
  GIT_DEPTH: "1"

stages:
  - prepare
  - build
  - deploy

macOS_bin:
  stage: prepare
  tags:
    - linux
  artifacts:
    paths:
      - bin
  script:
    - mkdir -p bin
    - curl --location --retry 5 https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-osx-darwin.tar.bz2 | tar --strip-components=2 -C bin -jxf - aria2-1.35.0/bin/aria2c

windows_bin:
  stage: prepare
  tags:
    - linux
  artifacts:
    paths:
      - bin
  script:
    - mkdir -p bin
    #- wget https://cdn01.moecube.com/ygopro-build-materials/mycard-binaries.zip
    #- 7z x -y mycard-binaries.zip
    - curl --location --retry 5 --output aria2-1.35.0-win-32bit-build1.zip https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0-win-32bit-build1.zip
    - unzip -o aria2-1.35.0-win-32bit-build1.zip aria2-1.35.0-win-32bit-build1/aria2c.exe
    - mv aria2-1.35.0-win-32bit-build1/aria2c.exe bin
    - rm -rf aria2-1.35.0-win-32bit-build1 aria2-1.35.0-win-32bit-build1.zip
    - curl --location --retry 5 "http://downloads.sourceforge.net/project/msys2/REPOS/MSYS2/i686/bsdtar-3.4.2-2-i686.pkg.tar.xz" | tar --strip-components=2 -C bin -Jxf - usr/bin/bsdtar.exe
    - curl --location --retry 5 "http://downloads.sourceforge.net/project/msys2/Base/i686/msys2-base-i686-20200517.tar.xz" | tar --strip-components=3 -C bin -Jxf - msys32/usr/bin/msys-2.0.dll msys32/usr/bin/msys-bz2-1.dll msys32/usr/bin/msys-expat-1.dll msys32/usr/bin/msys-gcc_s-1.dll msys32/usr/bin/msys-iconv-2.dll msys32/usr/bin/msys-lz4-1.dll msys32/usr/bin/msys-lzma-5.dll msys32/usr/bin/msys-z.dll msys32/usr/bin/msys-zstd-1.dll msys32/usr/bin/sha256sum.exe

windows:
  stage: build
  dependencies:
    - windows_bin
  tags:
    - vs
  script:
    - npm ci
    - npm run dist:windows
    #- dir dist
  artifacts:
    paths:
      - dist/
linux:
  image: node:16
  stage: build
  tags:
    - linux
  script:
    - apt update ; apt -y install python3 build-essential git
    - npm ci
    - npm run dist
    #- ls -la dist
  artifacts:
    paths:
      - dist/
macOS:
  stage: build
  dependencies:
    - macOS_bin
  tags:
    - macOS
  variables:
    CSC_KEY_PASSWORD: $MACOS_CSC_KEY_PASSWORD
    CSC_LINK: $MACOS_CSC_LINK
    APPLE_ID: $MACOS_NOTARIZE_USERNAME
    APPLE_ID_PASSWORD: $MACOS_NOTARIZE_PASSWORD
    TEAM_SHORT_NAME: $MACOS_ASC_PROVIDER
  script:
    - npm ci
    - npm run dist
    #- ls -la dist
  artifacts:
    paths:
      - dist/

#macOS_notarize:
#  stage: deploy
#  dependencies:
#    - macOS
#  tags:
#    - macOS
#  script: ./.ci/macos-notarize.sh
#  only:
#    - tags

upload_to_minio:
  stage: deploy
  dependencies:
    - macOS
    - windows
    - linux
  tags:
    - linux
  script:
    - aws s3 --endpoint=https://minio.mycard.moe:9000 sync dist/ s3://mycard/downloads
  only:
    - tags
    #- v3
