This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish to NuGet | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- '*' | |
release: | |
types: | |
- published # Run the workflow when a new GitHub release is published | |
jobs: | |
build-and-test: | |
name: Build and Test | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- os: windows-latest | |
artifactName: 'nuget-windows' | |
- os: macOS-latest | |
artifactName: 'nuget-macos' | |
- os: ubuntu-latest | |
artifactName: 'nuget-linux' | |
max-parallel: 3 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
- name: Restore dependencies | |
run: dotnet restore --verbosity Detailed | |
- name: Build | |
run: dotnet build --configuration Release --verbosity Detailed | |
- name: Test | |
run: dotnet test --configuration Release --verbosity Detailed --collect "Code coverage" | |
- name: Pack CI | |
run: dotnet pack --output ${{ github.workspace }}/artifacts/ci --configuration Release --verbosity Detailed /p:VersionSuffix=ci-${{ github.run_number }} | |
- name: Pack Release | |
run: dotnet pack --output ${{ github.workspace }}/artifacts/release --configuration Release --verbosity Detailed | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.artifactName }} | |
path: ${{ github.workspace }}/artifacts/ | |
build-samples: | |
needs: [build-and-test] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- os: windows-latest | |
artifactName: 'samples-windows' | |
- os: macOS-latest | |
artifactName: 'samples-macos' | |
- os: ubuntu-latest | |
artifactName: 'samples-linux' | |
max-parallel: 3 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
- name: Publish Samples | |
run: dotnet publish ${{ github.workspace }}/**/samples/**/*.csproj --configuration Release --output ${{ github.workspace }}/samples/ | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: ${{ matrix.artifactName }} | |
path: ${{ github.workspace }}/samples/ | |
deploy: | |
if: github.event_name == 'release' | |
runs-on: ubuntu-latest | |
needs: [ build-and-test, build-samples ] | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: nuget | |
path: ${{ github.workspace }}/artifacts/ | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v4 | |
- name: Publish NuGet package | |
run: | | |
foreach($file in (Get-ChildItem "${{ github.workspace }}/artifacts/" -Recurse -Include *.nupkg)) { | |
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate | |
} |