name: Build 3proxy with MSYS2 UCRT64

on:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  ci:
    name: "msys2-ucrt64"
    runs-on: windows-2022
    steps:
    - uses: actions/checkout@v7
    - name: Setup MSYS2 (UCRT64)
      uses: msys2/setup-msys2@v2
      with:
        msystem: UCRT64
        update: true
        install: >-
          make
          mingw-w64-ucrt-x86_64-gcc
          mingw-w64-ucrt-x86_64-pcre2
          mingw-w64-ucrt-x86_64-openssl
          mingw-w64-ucrt-x86_64-zlib
    - name: set date
      shell: pwsh
      run: |
        $NOW = Get-Date -Format "yyMMddHHmmss"
        $RELEASE = Get-Content -Path "RELEASE" -Raw
        echo "NOW=$NOW" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
        echo "RELEASE=$RELEASE" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
    - name: make Windows (Makefile.win)
      shell: msys2 {0}
      env:
        LIBSTATIC: 'true'
      run: make -f Makefile.win
    - name: make dist dir
      shell: cmd
      run: |
        mkdir dist
        mkdir dist\3proxy
        mkdir dist\3proxy\bin
        mkdir dist\3proxy\cfg
        mkdir dist\3proxy\cfg\sql
        mkdir dist\3proxy\doc
        mkdir dist\3proxy\doc\ru
        mkdir dist\3proxy\doc\html
        mkdir dist\3proxy\doc\html\plugins
        mkdir dist\3proxy\doc\html\man5
        mkdir dist\3proxy\doc\html\man8
        mkdir dist\3proxy\doc\html\devel
        copy bin\3proxy.exe dist\3proxy\bin\
        copy bin\*.dll dist\3proxy\bin\
        copy bin\3proxy_crypt.exe dist\3proxy\bin\
        copy cfg\*.* dist\3proxy\cfg\
        copy cfg\sql\*.* dist\3proxy\cfg\sql\
        copy doc\ru\*.* dist\3proxy\doc\ru\
        copy doc\html\*.* dist\3proxy\doc\html\
        copy doc\html\plugins\*.* dist\3proxy\doc\html\plugins\
        copy doc\html\man8\*.* dist\3proxy\doc\html\man8\
        copy doc\html\man5\*.* dist\3proxy\doc\html\man5\
        copy doc\html\devel\*.* dist\3proxy\doc\html\devel\
        copy copying dist\3proxy\
        copy authors dist\3proxy\
        copy README.md dist\3proxy\
        copy rus.3ps dist\3proxy\
    - name: Get artifact
      uses: actions/upload-artifact@v7
      with:
        name: "3proxy-${{ env.RELEASE }}-msys2-ucrt64"
        path: dist/
