# swy: some useful references; the MSVC part of the CI script is based on the one from bind9, by Michał Kępień:
# https://gitlab.com/gitlab-org/ci-cd/shared-runners/images/gcp/windows-containers/blob/master/cookbooks/preinstalled-software/README.md
# https://gitlab.isc.org/isc-projects/bind9/commit/facc6a051fcac70fbbc61cb92a37be8c3e4db5ec#587d266bb27a4dc3022bbed44dfa19849df3044c_718_731
# https://www.kittell.net/code/powershell-unix-sed-equivalent-change-text-file/
# https://powershell.org/forums/topic/how-to-use-ansi-vt100-formatting-in-powershell-ooh-pretty-colors/

#-----------------------------------------------------------------------#
# OpenRGB GitLab CI Configuration                                       #
#-----------------------------------------------------------------------#

.shared_windows_runners:
  tags:
  - shared-windows
  - windows
  - windows-1809

stages:
  - build
  - test

before_script:
 - echo "started by ${GITLAB_USER_NAME}"

#reusable templates
.ccache_init: &ccache_init
  before_script:
    - export QT_SELECT=qt5
    - export APPIMAGE_EXTRACT_AND_RUN=1

#-----------------------------------------------------------------------#
# Supported Devices Build Target                                        #
#-----------------------------------------------------------------------#
"Supported Devices":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:bullseye-64
  stage: build
  script:
  - qmake
  - make -j$(nproc)
  - ./scripts/build-supported-devices-md.sh $CI_PROJECT_DIR $CI_COMMIT_SHORT_SHA

  artifacts:
    name: "${CI_PROJECT_NAME}_Supported_Devices_${CI_COMMIT_SHORT_SHA}"
    paths:
    - ./*.md
    - Supported Devices.csv
    exclude:
    - README.md
    - CONTRIBUTING.md
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (AppImage) 32-bit Build Target                                  #
#-----------------------------------------------------------------------#
"Linux 32 AppImage":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:bullseye-32
  stage: build
  script:
  - export $(dpkg-architecture)
  - ./scripts/build-appimage.sh

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_32_${CI_COMMIT_SHORT_SHA}"
    paths:
    - OpenRGB-i386.AppImage
    - 60-openrgb.rules
    - README.md
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (AppImage) 64-bit Build Target                                  #
#-----------------------------------------------------------------------#
"Linux 64 AppImage":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:bullseye-64
  stage: build
  script:
  - export $(dpkg-architecture)
  - ./scripts/build-appimage.sh

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_64_${CI_COMMIT_SHORT_SHA}"
    paths:
    - OpenRGB-x86_64.AppImage
    - 60-openrgb.rules
    - README.md
    expire_in: 30 days

#-----------------------------------------------------------------------#
# Linux (.deb) Debian Buster (Legacy) 32-bit Build Target               #
#-----------------------------------------------------------------------#
"Linux 32 .deb (Debian Buster)":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:buster-32
  stage: build
  script:
  - ./scripts/build-package-files.sh debian/changelog
  - dpkg-architecture -l
  - dpkg-buildpackage --target-arch i386 -us -B
  - rm -v ../openrgb-dbgsym*.*deb
  - mv -v ../openrgb*.deb ./

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_32_deb_${CI_COMMIT_SHORT_SHA}"
    paths:
    - openrgb*.deb
    exclude:
    - openrgb-dbgsym*.*deb
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (.deb) Debian Buster (Legacy) 64-bit Build Target               #
#-----------------------------------------------------------------------#
"Linux 64 .deb (Debian Buster)":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:buster-64
  stage: build
  script:
  - ./scripts/build-package-files.sh debian/changelog
  - dpkg-architecture -l
  - dpkg-buildpackage -us -B
  - rm -v ../openrgb-dbgsym*.*deb
  - mv -v ../openrgb*.deb ./

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_64_deb_${CI_COMMIT_SHORT_SHA}"
    paths:
    - openrgb*.deb
    exclude:
    - openrgb-dbgsym*.*deb
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (.deb) Debian Bullseye 32-bit Build Target                      #
#-----------------------------------------------------------------------#
"Linux 32 .deb (Debian Bullseye)":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:bullseye-32
  stage: build
  script:
  - ./scripts/build-package-files.sh debian/changelog
  - dpkg-architecture -l
  - dpkg-buildpackage --target-arch i386 -us -B
  - rm -v ../openrgb-dbgsym*.*deb
  - mv -v ../openrgb*.deb ./

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_32_deb_${CI_COMMIT_SHORT_SHA}"
    paths:
    - openrgb*.deb
    exclude:
    - openrgb-dbgsym*.*deb
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (.deb) Debian Bullseye 64-bit Build Target                      #
#-----------------------------------------------------------------------#
"Linux 64 .deb (Debian Bullseye)":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:bullseye-64
  stage: build
  script:
  - ./scripts/build-package-files.sh debian/changelog
  - dpkg-architecture -l
  - dpkg-buildpackage -us -B
  - rm -v ../openrgb-dbgsym*.*deb
  - mv -v ../openrgb*.deb ./

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_64_deb_${CI_COMMIT_SHORT_SHA}"
    paths:
    - openrgb*.deb
    exclude:
    - openrgb-dbgsym*.*deb
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (.deb) Debian Bookworm 32-bit Build Target                      #
#-----------------------------------------------------------------------#
"Linux 32 .deb (Debian Bookworm)":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:bookworm-32
  stage: build
  script:
  - ./scripts/build-package-files.sh debian/changelog
  - dpkg-architecture -l
  - dpkg-buildpackage --target-arch i386 -us -B
  - rm -v ../openrgb-dbgsym*.deb
  - mv -v ../openrgb*.deb ./

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_32_deb_${CI_COMMIT_SHORT_SHA}"
    paths:
    - openrgb*.deb
    exclude:
    - openrgb-dbgsym*.deb
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (.deb) Debian Bookworm 64-bit Build Target                      #
#-----------------------------------------------------------------------#
"Linux 64 .deb (Debian Bookworm)":
  <<: *ccache_init
  image: registry.gitlab.com/openrgbdevelopers/openrgb-linux-ci-deb-builder:bookworm-64
  stage: build
  script:
  - ./scripts/build-package-files.sh debian/changelog
  - dpkg-architecture -l
  - dpkg-buildpackage -us -B
  - rm -v ../openrgb-dbgsym*.deb
  - mv -v ../openrgb*.deb ./

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_64_deb_${CI_COMMIT_SHORT_SHA}"
    paths:
    - openrgb*.deb
    exclude:
    - openrgb-dbgsym*.deb
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (.rpm, f35) 64-bit Build Target                                 #
#-----------------------------------------------------------------------#
"Linux 64 f35 rpm":
  image: fedora:35
  stage: build
  script:
  - dnf install rpmdevtools dnf-plugins-core -y
  - rpmdev-setuptree
  - ./scripts/build-package-files.sh fedora/OpenRGB.spec
  - ls /root/
  - cp fedora/OpenRGB.spec /root/rpmbuild/SPECS
  - cp ../OpenRGB /root/rpmbuild/SOURCES/ -r
  - cd /root/rpmbuild/SOURCES
  - tar -cf OpenRGB.tar.gz OpenRGB/
  - cd ..
  - dnf builddep SPECS/OpenRGB.spec -y
  - rpmbuild -ba SPECS/OpenRGB.spec
  - cd RPMS/x86_64/
  - mv openrgb*.rpm ${CI_PROJECT_DIR}/
  - cd ${CI_PROJECT_DIR}

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_64_rpm_${CI_COMMIT_SHORT_SHA}"
    paths:
    - openrgb*.rpm
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Linux (.rpm, f36) 64-bit Build Target                                 #
#-----------------------------------------------------------------------#
"Linux 64 f36 rpm":
  image: fedora:36
  stage: build
  script:
  - dnf install rpmdevtools dnf-plugins-core libcurl-devel qt5-qtbase-devel -y
  - rpmdev-setuptree
  - ./scripts/build-package-files.sh fedora/OpenRGB.spec
  - ls /root/
  - cp fedora/OpenRGB.spec /root/rpmbuild/SPECS
  - cp ../OpenRGB /root/rpmbuild/SOURCES/ -r
  - cd /root/rpmbuild/SOURCES
  - tar -cf OpenRGB.tar.gz OpenRGB/
  - cd ..
  - dnf builddep SPECS/OpenRGB.spec -y
  - rpmbuild -ba SPECS/OpenRGB.spec
  - cd RPMS/x86_64/
  - mv openrgb*.rpm ${CI_PROJECT_DIR}/
  - cd ${CI_PROJECT_DIR}

  artifacts:
    name: "${CI_PROJECT_NAME}_Linux_64_rpm_${CI_COMMIT_SHORT_SHA}"
    paths:
    - openrgb*.rpm
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Debian 32 Buster test                                                 #
#-----------------------------------------------------------------------#
"Debian 32 Buster":
  image: i386/debian:buster
  stage: test
  script:
  - apt update
  - DEBIAN_FRONTEND=noninteractive apt install -yq --no-install-recommends ./openrgb*i386.deb
  - openrgb --version
  - apt remove -y openrgb
  dependencies:
  - "Linux 32 .deb (Debian Buster)"
  needs:
  - "Linux 32 .deb (Debian Buster)"

#-----------------------------------------------------------------------#
# Debian 64 Buster test                                                 #
#-----------------------------------------------------------------------#
"Debian 64 Buster":
  image: amd64/debian:buster
  stage: test
  script:
  - apt update
  - DEBIAN_FRONTEND=noninteractive apt install -yq --no-install-recommends ./openrgb*amd64.deb
  - openrgb --version
  - apt remove -y openrgb
  dependencies:
  - "Linux 64 .deb (Debian Buster)"
  needs:
  - "Linux 64 .deb (Debian Buster)"

#-----------------------------------------------------------------------#
# Debian 32 Bullseye test                                               #
#-----------------------------------------------------------------------#
"Debian 32 Bullseye":
  image: i386/debian:bullseye
  stage: test
  script:
  - apt update
  - DEBIAN_FRONTEND=noninteractive apt install -yq --no-install-recommends ./openrgb*i386.deb
  - openrgb --version
  - apt remove -y openrgb
  dependencies:
  - "Linux 32 .deb (Debian Bullseye)"
  needs:
  - "Linux 32 .deb (Debian Bullseye)"

#-----------------------------------------------------------------------#
# Debian 64 Bullseye test                                               #
#-----------------------------------------------------------------------#
"Debian 64 Bullseye":
  image: amd64/debian:bullseye
  stage: test
  script:
  - apt update
  - DEBIAN_FRONTEND=noninteractive apt install -yq --no-install-recommends ./openrgb*amd64.deb
  - openrgb --version
  - apt remove -y openrgb
  dependencies:
  - "Linux 64 .deb (Debian Bullseye)"
  needs:
  - "Linux 64 .deb (Debian Bullseye)"

#-----------------------------------------------------------------------#
# Debian 32 Bookworm test                                               #
#-----------------------------------------------------------------------#
"Debian 32 Bookworm":
  image: i386/debian:bookworm
  stage: test
  script:
  - apt update
  - DEBIAN_FRONTEND=noninteractive apt install -yq --no-install-recommends ./openrgb*i386.deb
  - openrgb --version
  - apt remove -y openrgb
  dependencies:
  - "Linux 32 .deb (Debian Bookworm)"
  needs:
  - "Linux 32 .deb (Debian Bookworm)"

#-----------------------------------------------------------------------#
# Debian 64 Bookworm test                                               #
#-----------------------------------------------------------------------#
"Debian 64 Bookworm":
  image: amd64/debian:bookworm
  stage: test
  script:
  - apt update
  - DEBIAN_FRONTEND=noninteractive apt install -yq --no-install-recommends ./openrgb*amd64.deb
  - openrgb --version
  - apt remove -y openrgb
  dependencies:
  - "Linux 64 .deb (Debian Bookworm)"
  needs:
  - "Linux 64 .deb (Debian Bookworm)"

#-----------------------------------------------------------------------#
# Ubuntu 64 20.04LTS test                                               #
#-----------------------------------------------------------------------#
"Ubuntu 64 20.04LTS":
  image: ubuntu:focal
  stage: test
  script:
  - apt update
  - DEBIAN_FRONTEND=noninteractive apt install -yq --no-install-recommends ./openrgb*amd64.deb
  - openrgb --version
  - apt remove -y openrgb
  dependencies:
  - "Linux 64 .deb (Debian Buster)"
  needs:
  - "Linux 64 .deb (Debian Buster)"

#-----------------------------------------------------------------------#
# Ubuntu 64 22.04 test                                                  #
#-----------------------------------------------------------------------#
"Ubuntu 64 22.04LTS":
  image: ubuntu:jammy
  stage: test
  script:
  - apt update
  - DEBIAN_FRONTEND=noninteractive apt install -yq --no-install-recommends ./openrgb*amd64.deb
  - openrgb --version
  - apt remove -y openrgb
  dependencies:
  - "Linux 64 .deb (Debian Bookworm)"
  needs:
  - "Linux 64 .deb (Debian Bookworm)"

#-----------------------------------------------------------------------#
# Fedora 64 v35 test                                                    #
#-----------------------------------------------------------------------#
"Fedora 64 v35":
  image: fedora:35
  stage: test
  script:
  - yum -y localinstall ./openrgb*64.rpm
  - openrgb --version
  - yum -y remove openrgb
  dependencies:
  - "Linux 64 f35 rpm"
  needs:
  - "Linux 64 f35 rpm"

#-----------------------------------------------------------------------#
# Fedora 64 v36 test                                                    #
#-----------------------------------------------------------------------#
"Fedora 64 v36":
  image: fedora:36
  stage: test
  script:
  - yum -y localinstall ./openrgb*64.rpm
  - openrgb --version
  - yum -y remove openrgb
  dependencies:
  - "Linux 64 f36 rpm"
  needs:
  - "Linux 64 f36 rpm"

#-----------------------------------------------------------------------#
# Windows (32-bit) Build Target                                         #
#-----------------------------------------------------------------------#
"Windows 32":
  extends:
  - .shared_windows_runners
  stage: build
  script:
  - $esc = "$([char]27)"
  - $count = 0
  - function _unix_tmsec_ { [int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds }
  - function _fold_start_ { param( [string]$TEXT_TAG ) $t=_unix_tmsec_; $global:count += 1; Write-Host -NoNewLine "`r`n`r`nsection_start:${t}:sect_${count}`r${esc}[0K${esc}[33m${TEXT_TAG}${esc}[39m`r`n"; }
  - function _fold_final_ {                            $t=_unix_tmsec_;                     Write-Host -NoNewLine   "`r`n`r`nsection_end:${t}:sect_${count}`r${esc}[0K`r`n"           ; }


  - _fold_start_ 'configuring the msvc environment variables'
  - Push-Location "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Auxiliary/Build"
  - '& cmd.exe /C "vcvarsall.bat x86 & set" | Foreach-Object { if ($_ -match "(.*?)=(.*)") { Set-Item -force -path "Env:\$($matches[1])" -value "$($matches[2])" } }'
  - Pop-Location
  - _fold_final_

  - _fold_start_ 'downloading precompiled versions of qtbase, qttools (for windeployqt) and jom (for a more parallel nmake)'
  - mkdir _qt
  - mkdir _qt_download
  - Push-Location _qt_download
  - curl.exe -LJ -o qt-base.7z  'https://gitlab.com/OpenRGBDevelopers/openrgb-linux-ci-deb-builder/-/package_files/55610076/download'
  - curl.exe -LJ -o qt-tools.7z 'https://gitlab.com/OpenRGBDevelopers/openrgb-linux-ci-deb-builder/-/package_files/55610097/download'
  - curl.exe -LJ -o qt-jom.zip  'https://gitlab.com/OpenRGBDevelopers/openrgb-linux-ci-deb-builder/-/package_files/55610138/download'
  - _fold_final_

  - _fold_start_ 'extracting the downloaded qt binaries'
  - 7z x qt-base.7z  '-o../_qt' -y
  - 7z x qt-tools.7z '-o../_qt' -y
  - 7z x qt-jom.zip  '-o../_qt' -y
  - _fold_final_

  - _fold_start_ 'turn the qt install from enterprise to foss; remove the licensing checks'
  - ${qconfig-pri-folder} = '..\_qt\5.15.0\msvc2019\mkspecs\qconfig.pri'
  - (Get-Content ${qconfig-pri-folder}).replace('QT_EDITION = Enterprise', 'QT_EDITION = OpenSource') | Set-Content ${qconfig-pri-folder}
  - (Get-Content ${qconfig-pri-folder}).replace('QT_LICHECK = licheck.exe', '')                       | Set-Content ${qconfig-pri-folder}
  - Pop-Location
  - _fold_final_

  - _fold_start_ 'run qmake and generate the msvc nmake makefile'
  - mkdir _build; cd _build
  - ..\_qt\5.15.0\msvc2019\bin\qmake ..\OpenRGB.pro
  - _fold_final_

  - _fold_start_ 'start the actual build with jom instead of nmake; for speed'
  - ..\_qt\jom
  - _fold_final_

  - _fold_start_ 'run windeployqt to automatically copy the needed dll files'
  - ..\_qt\5.15.0\msvc2019\bin\windeployqt --no-angle --no-translations --no-opengl-sw --no-system-d3d-compiler --no-compiler-runtime --no-webkit2 .\release\
  - _fold_final_

  - _fold_start_ 'Moving results for upload'
  - mv release ../'OpenRGB Windows 32-bit'
  - _fold_final_
#  cache:
#    key: same-key
#    paths:
#    - C:\vcpkg\installed\
  artifacts:
    name: "${CI_PROJECT_NAME}_Windows_32_${CI_COMMIT_SHORT_SHA}"
    paths:
    - 'OpenRGB Windows 32-bit'
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

#-----------------------------------------------------------------------#
# Windows (64-bit) Build Target                                         #
#-----------------------------------------------------------------------#
"Windows 64":
  extends:
  - .shared_windows_runners
  stage: build
  script:
  - $esc = "$([char]27)"
  - $count = 0
  - function _unix_tmsec_ { [int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds }
  - function _fold_start_ { param( [string]$TEXT_TAG ) $t=_unix_tmsec_; $global:count += 1; Write-Host -NoNewLine "`r`n`r`nsection_start:${t}:sect_${count}`r${esc}[0K${esc}[33m${TEXT_TAG}${esc}[39m`r`n"; }
  - function _fold_final_ {                            $t=_unix_tmsec_;                     Write-Host -NoNewLine   "`r`n`r`nsection_end:${t}:sect_${count}`r${esc}[0K`r`n"           ; }


  - _fold_start_ 'configuring the msvc environment variables'
  - Push-Location "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Auxiliary/Build"
  - '& cmd.exe /C "vcvarsall.bat x64 & set" | Foreach-Object { if ($_ -match "(.*?)=(.*)") { Set-Item -force -path "Env:\$($matches[1])" -value "$($matches[2])" } }'
  - Pop-Location
  - _fold_final_

  - _fold_start_ 'downloading precompiled versions of qtbase, qttools (for windeployqt) and jom (for a more parallel nmake)'
  - mkdir _qt
  - mkdir _qt_download
  - Push-Location _qt_download
  - curl.exe -LJ -o qt-base.7z  'https://gitlab.com/OpenRGBDevelopers/openrgb-linux-ci-deb-builder/-/package_files/55610116/download'
  - curl.exe -LJ -o qt-tools.7z 'https://gitlab.com/OpenRGBDevelopers/openrgb-linux-ci-deb-builder/-/package_files/55610131/download'
  - curl.exe -LJ -o qt-jom.zip  'https://gitlab.com/OpenRGBDevelopers/openrgb-linux-ci-deb-builder/-/package_files/55610138/download'
  - _fold_final_

  - _fold_start_ 'extracting the downloaded qt binaries'
  - 7z x qt-base.7z  '-o../_qt' -y
  - 7z x qt-tools.7z '-o../_qt' -y
  - 7z x qt-jom.zip  '-o../_qt' -y
  - _fold_final_

  - _fold_start_ 'turn the qt install from enterprise to foss; remove the licensing checks'
  - ${qconfig-pri-folder} = '..\_qt\5.15.0\msvc2019_64\mkspecs\qconfig.pri'
  - (Get-Content ${qconfig-pri-folder}).replace('QT_EDITION = Enterprise', 'QT_EDITION = OpenSource') | Set-Content ${qconfig-pri-folder}
  - (Get-Content ${qconfig-pri-folder}).replace('QT_LICHECK = licheck.exe', '')                       | Set-Content ${qconfig-pri-folder}
  - Pop-Location
  - _fold_final_

  - _fold_start_ 'run qmake and generate the msvc nmake makefile'
  - mkdir _build; cd _build
  - ..\_qt\5.15.0\msvc2019_64\bin\qmake ..\OpenRGB.pro
  - _fold_final_

  - _fold_start_ 'start the actual build with jom instead of nmake; for speed'
  - ..\_qt\jom
  - _fold_final_

  - _fold_start_ 'run windeployqt to automatically copy the needed dll files'
  - ..\_qt\5.15.0\msvc2019_64\bin\windeployqt --no-angle --no-translations --no-opengl-sw --no-system-d3d-compiler --no-compiler-runtime --no-webkit2 .\release\
  - _fold_final_

  - _fold_start_ 'Moving results for upload'
  - mv release ../'OpenRGB Windows 64-bit'
  - _fold_final_
#  cache:
#    key: same-key
#    paths:
#    - C:\vcpkg\installed\
  artifacts:
    name: "${CI_PROJECT_NAME}_Windows_64_${CI_COMMIT_SHORT_SHA}"
    paths:
    - 'OpenRGB Windows 64-bit'
    expire_in: 30 days

#-----------------------------------------------------------------------#
# MacOS Build Target                                                    #
#-----------------------------------------------------------------------#
"MacOS ARM64":
  tags:
  - macos
  stage: build
  script:
  - eval $(/opt/homebrew/bin/brew shellenv)
  - qmake OpenRGB.pro
  - make -j16
  - macdeployqt OpenRGB.app -codesign=OpenRGB

  artifacts:
    name: "${CI_PROJECT_NAME}_MacOS_ARM64_${CI_COMMIT_SHORT_SHA}"
    paths:
    - OpenRGB.app
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: '$BUILD_MACOS =~ /.+/'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true

"MacOS Intel":
  tags:
  - macos
  stage: build
  script:
  - eval $(/usr/local/bin/brew shellenv)
  - arch -x86_64 /usr/local/bin/qmake OpenRGB.pro
  - arch -x86_64 make -j16
  - arch -x86_64 macdeployqt OpenRGB.app -codesign=OpenRGB

  artifacts:
    name: "${CI_PROJECT_NAME}_MacOS_Intel_${CI_COMMIT_SHORT_SHA}"
    paths:
    - OpenRGB.app
    expire_in: 30 days

  rules:
  - if: '$CI_PROJECT_PATH == "CalcProgrammer1/OpenRGB"'
    when: on_success
  - if: '$BUILD_MACOS =~ /.+/'
    when: on_success
  - if: $CI_PIPELINE_SOURCE == "push"
    when: manual
    allow_failure: true
