name: buildProject
on:
  push:
    tags:
      - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
  build:

    runs-on: windows-latest
    permissions:
      contents: write

    steps:
    - uses: actions/checkout@v4
    - name: Setup NodeJs
      uses: actions/setup-node@v4
      with: 
        node-version: 22.x
    - name: Setup .NET
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: 8.0.x
    - name: build
      run: |
        mkdir release
        mkdir release/LocalServer/wwwroot
        mkdir release/RemoteServer
        mkdir release/JsScript
        cd Tool/webtool
        npm install
        npm run build
        cd ../../Server
        dotnet restore
        cd LocalServer
        dotnet publish -o ../../release/Localserver --no-restore
        cd ../RemoteServer
        dotnet publish -o ../../release/RemoteServer --no-restore
        cd ../../
    - name: Package
      run: |
        cp Tool/JsScript/* release/JsScript/
        Compress-Archive -Path "release/*" -DestinationPath "FS_win_dotnet8.zip" -Force
        $version = $env:GITHUB_REF -replace 'refs/tags/', ''
        Write-Host "VERSION=$version" >> $env:GITHUB_ENV
    - name: Release
      uses: softprops/action-gh-release@v2
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: |
          FS_win_dotnet8.zip
          LICENSE
        name: ${{ env.VERSION}}
        draft: false
        prerelease: true
