name: Windows Kernel Build

#Запускаем только кнопкой "Run workflow" в Actions -> Build Windows
#Или если есть коммпит в папку lib в ветке main
on:
  workflow_dispatch:
  push:
    branches:
      - main
    paths:
      - 'lib/**'

jobs:
  build:
    runs-on: windows-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
      
      - name: Install Node.js
        uses: actions/setup-node@v6
        with:
          node-version: '22'

      # Кэш для electron-builder
      - name: Cache electron-builder
        uses: actions/cache@v5
        with:
          path: |
            ${{ env.LOCALAPPDATA }}\\electron-builder\\Cache
            ${{ env.LOCALAPPDATA }}\\electron\\Cache
          key: ${{ runner.os }}-electron-builder-${{ hashFiles('**/electron-builder.yml') }}
          restore-keys: |
            ${{ runner.os }}-electron-builder-
          if-no-files-found: ignore
      
      - name: NPM offline setup
        shell: powershell
        run: |
          npm config set cache "$env:LOCALAPPDATA\npm-cache" --global
          npm config set prefer-offline true --global

      - name: Install npm dependencies
        run: npm install --prefer-offline --no-audit --no-fund
      
      - name: Build the application
        run: npm run kernel:win
      
      - name: Upload to SSH using WinSCP Powershell
        shell: powershell
        run: |
          & "$env:GITHUB_WORKSPACE\.gitea\workflows\sshupload.ps1" `
            -LocalFilePath "dist/builds/win/x64/Rosetta-*.exe" `
            -RemoteFolderPath "${{ secrets.SDU_SSH_KERNEL }}/win32/x64" `
            -ServerAddress "${{ secrets.SDU_SSH_HOST }}" `
            -Username "${{ secrets.SDU_SSH_USERNAME }}" `
            -PasswordParam '${{ secrets.SDU_SSH_PASSWORD }}'
