# .github/workflows/release.yml

on:
  push:
    branches:
    - release

jobs:
  build:
    runs-on: windows-latest  # For a list of available runner types, refer to
                             # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
    steps:
    - name: Install .NET Core
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: 8.0.x
    - name: Checkout
      uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: release
    - name: Build
      run: dotnet build Needlework.Net -c Release
    - name: Publish
      run: dotnet publish Needlework.Net -c Release -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=None -p:DebugSymbols=false -o publish -r win-x64 --self-contained=false
    - name: Get Version
      id: version
      shell: powershell
      run: |
        $xml=[xml](Get-Content .\Needlework.Net\Needlework.Net.csproj)
        $ver=($xml.Project.PropertyGroup).AssemblyVersion
        $ver="VERSION=$ver"
        $ver=$ver -replace '\s',''
        echo $ver >> $env:GITHUB_OUTPUT
    - name: Zip Files
      run: 7z a -tzip NeedleworkDotNet-win-x64.zip ./Publish/* README.md LICENSE
    - name: Release
      uses: softprops/action-gh-release@v1
      with:
        name: "Needlework.Net v${{ steps.version.outputs.VERSION }}"
        prerelease: false
        tag_name: "${{ steps.version.outputs.VERSION }}"
        files: |
          NeedleworkDotNet-win-x64.zip