name: Publish Package

on:
  push:
    branches:
    - 'master'
    paths-ignore:
    - 'docs/**'

env:
  DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
  DOTNET_CLI_TELEMETRY_OPTOUT: 1

jobs:

  publish:
    runs-on: 'windows-latest'

    steps:
    - uses: actions/checkout@v1

    - name: Set up .NET 6.0
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 6.0.100-preview.5.21302.13

    - name: Restore
      run: dotnet restore

    - name: Build
      run: dotnet build --configuration Release --no-restore

    - name: Unit Tests
      run: dotnet test --configuration Release tests\MySqlConnector.Tests --no-build

    - name: Pack
      run: dotnet pack --configuration Release --no-build

    - name: Install NuGet
      run: choco install nuget.commandline

    - name: Add NuGet source
      run: nuget sources Add -Name "GPR" -Source "https://nuget.pkg.github.com/mysql-net/index.json" -UserName bgrainger -Password ${{ secrets.GITHUB_TOKEN }}

    - name: Publish packages
      run: |
        $files = Get-ChildItem -Path src -Filter *.nupkg -Recurse
        foreach ($file in $files) {
          nuget push $file -Source GPR
        }

name: Publish Package

on:
  push:
    branches:
    - 'master'
    paths-ignore:
    - 'docs/**'

env:
  DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
  DOTNET_CLI_TELEMETRY_OPTOUT: 1

jobs:

  publish:
    runs-on: 'windows-latest'

    steps:
    - uses: actions/checkout@v1

    - name: Set up .NET 6.0
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 6.0.100-preview.5.21302.13

    - name: Restore
      run: dotnet restore

    - name: Build
      run: dotnet build --configuration Release --no-restore

    - name: Unit Tests
      run: dotnet test --configuration Release tests\MySqlConnector.Tests --no-build

    - name: Pack
      run: dotnet pack --configuration Release --no-build

    - name: Install gpr tool
      run: dotnet tool install -g gpr --no-cache -v q

    - name: Publish packages
      run: |
        $files = Get-ChildItem -Path src -Filter *.nupkg -Recurse
        foreach ($file in $files) {
          gpr push --api-key $GITHUB_ACCESS_TOKEN $file
        }

Use 'gpr' to push to GitHub Package Registry.
Use 'gpr' to push to GitHub Package Registry.

This is to try to avoid the following warnings from the workflow:

WARNING: No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/mysql-net'. To save an API Key for a source use the 'setApiKey' command.
Pushing MySqlConnector.1.3.12-beta.0.5.nupkg to 'https://nuget.pkg.github.com/mysql-net'...
  PUT https://nuget.pkg.github.com/mysql-net/
WARNING: Please use the --api-key option when publishing to GitHub Packages

This solution comes from https://github.community/t/github-package-registry-not-compatible-with-dotnet-nuget-client/14392/19.
