# ---------------------------------------------------------------
# Workflow File : build-on-Windows.yml
# File Authors  :  Aoran Zeng <ccmywish@qq.com>
# Contributors  :   Nul None  <nul@none.org>
#               |
# Created On    : <2023-09-14>
# Last Modified : <2025-07-22>
#
# Build chsrc on Windows and upload it to GitHub: the 'pre' release
# ---------------------------------------------------------------

name: 构建于 Windows
on:
  push:
    branches: [ "gh-build" ]

jobs:
  build-and-upload:
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}

    steps:

    - name: 检出代码
      uses: actions/checkout@v4

    - name: 安装 GCC
      uses: msys2/setup-msys2@v2
      with:
        msystem: UCRT64
        update: true
        install: |
          mingw-w64-ucrt-x86_64-gcc
          mingw-w64-ucrt-x86_64-make
          mingw-w64-i686-gcc
          mingw-w64-i686-make

    - name: 为 x64 构建
      run: |
        mingw32-make.exe build-in-ci-release-mode
        mv chsrc-ci-release.exe chsrc-x64-windows.exe

    - name: 为 x32 构建
      env:
        MSYSTEM: MINGW32
      run: |
        mingw32-make.exe build-in-ci-release-mode
        mv chsrc-ci-release.exe chsrc-x86-windows.exe

    - name: 为 Android 构建
      run: |
        compiler=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android21-clang

        # 检查编译器版本
        $compiler --version
        echo

        mingw32-make.exe build-in-ci-release-mode CC=$compiler CROSS_BUILD_WINDOWS_FOR_ANDROID=1
        echo

        # 让我们看看里面有啥
        ls
        echo

        mv chsrc-ci-release chsrc-arm64-android

    - name: List files
      run: ls *.exe

    - name: 上传至 'pre' release
      uses: softprops/action-gh-release@v2
      # if: startsWith(github.ref, 'refs/tags/')
      with:
        tag_name: pre
        files: |
          chsrc-x64-windows.exe
          chsrc-x86-windows.exe
          chsrc-arm64-android
        token: ${{ secrets.UPLOAD_TO_GITHUB }}
