Skip to content

Refactor

Refactor #7

name: Build and Publish to NuGet
on:
workflow_dispatch:
push:
branches:
- master
pull_request:
branches:
- '*'
release:
types:
- published
env:
dotnetVerbosity: 'Detailed'
libraryProjectPath: './src/Orneholm.PEAccountingNet/Orneholm.PEAccountingNet.csproj'
testProjectPath: './test/Orneholm.PEAccountingNet.Test/Orneholm.PEAccountingNet.Test.csproj'
samplesProjectPath: './samples/Orneholm.PEAccountingNet.ConsoleSample/Orneholm.PEAccountingNet.ConsoleSample.csproj'
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 ${{ env.dotnetVerbosity }}
- name: Build
run: dotnet build ${{ env.libraryProjectPath }} --configuration Release --verbosity ${{ env.dotnetVerbosity }}
- name: Test
run: dotnet test ${{ env.testProjectPath }} --configuration Release --verbosity ${{ env.dotnetVerbosity }} --collect "Code coverage"
shell: bash
- name: Pack CI
run: dotnet pack ${{ env.libraryProjectPath }} --output ./artifacts/ci --configuration Release --verbosity ${{ env.dotnetVerbosity }} /p:VersionSuffix=ci-${{ github.run_number }}
shell: bash
- name: Pack Release
run: dotnet pack ${{ env.libraryProjectPath }} --output ./artifacts/release --configuration Release --verbosity ${{ env.dotnetVerbosity }}
shell: bash
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifactName }}
path: ./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 ${{ env.samplesProjectPath }} --configuration Release --output ./samples/
shell: bash
- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifactName }}
path: ./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: ./artifacts/
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
- name: Publish NuGet package
run: |
foreach($file in (Get-ChildItem "./artifacts/" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}