name: Build

on:
  push:
    branches:
      - 'main'
    paths-ignore:
      - 'docs/**'
      - '*.md'
  pull_request:
    paths-ignore:
      - 'docs/**'
      - '*.md'

env:
  DOTNET_CLI_TELEMETRY_OPTOUT: false
  DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

jobs:
  build:
    runs-on: windows-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Add msbuild to PATH
      uses: microsoft/setup-msbuild@v1.1

    - name: Install .NET 7 SDK
      uses: actions/setup-dotnet@v2
      with:
        dotnet-version: 7.0.100

    - name: Pack
      run: dotnet pack Vortice.Win32.sln --configuration Release --output artifacts

    - name: Publish to NuGet
      if: github.event_name == 'push'
      run: dotnet nuget push artifacts/**/*.nupkg -k ${{secrets.NUGET_TOKEN}} --skip-duplicate --source https://api.nuget.org/v3/index.json

    - name: Upload Package Artifacts
      uses: actions/upload-artifact@v3
      with:
        name: Packages
        path: artifacts\*.nupkg
        if-no-files-found: error
