SDK Build and Release #28
Workflow file for this run
This file contains hidden or 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: SDK Build and Release | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [ "main" ] | |
| paths: | |
| - 'Kepware.Api/**' | |
| # - 'Kepware.Api.Sample/**' | |
| # - 'KepwareSync.Service/**' | |
| # - '.github/workflows/nuget-test-and-build.yml' | |
| - '!**/*.md' # Exclude markdown files | |
| pull_request: | |
| branches: [ "main" ] | |
| paths: | |
| - 'Kepware.Api/**' | |
| # - 'Kepware.Api.Sample/**' | |
| # - 'KepwareSync.Service/**' | |
| # - '.github/workflows/nuget-test-and-build.yml' | |
| - '!**/*.md' # Exclude markdown files | |
| jobs: | |
| draft-release: | |
| # Draft the release notes | |
| runs-on: ubuntu-latest | |
| env: | |
| PRODUCT: Kepware.Api SDK | |
| outputs: | |
| tag_name: ${{ steps.drafter.outputs.tag_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # avoid shallow clone so nbgv can do its work. | |
| - uses: dotnet/nbgv@master | |
| id: nbgv | |
| with: | |
| path: ./Kepware.Api | |
| setAllVars: true | |
| - name: Use Release Drafter | |
| if: ${{ github.event_name != 'pull_request'}} | |
| id: drafter | |
| uses: release-drafter/release-drafter@v6.1.0 | |
| with: | |
| config-name: nuget-release-drafter.yml | |
| version: ${{ steps.nbgv.outputs.SemVer2 }} | |
| name: ${{ env.PRODUCT }} v${{ steps.nbgv.outputs.SemVer2 }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build: | |
| # Build and test on both Windows and Ubuntu | |
| strategy: | |
| matrix: | |
| platform: [windows, ubuntu] | |
| runs-on: ${{ matrix.platform }}-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| packages: write | |
| actions: read | |
| checks: write | |
| needs: draft-release | |
| env: | |
| tag_name: ${{ needs.draft-release.outputs.tag_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # avoid shallow clone so nbgv can do its work. | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build --no-restore --configuration release | |
| - name: Test | |
| run: dotnet test Kepware.Api.Test/Kepware.Api.Test.csproj --no-build --verbosity normal --configuration Release --logger "trx;LogFilePrefix=${{ matrix.platform }}-test-results" | |
| - name: Publish Test Reports (${{ matrix.platform }}) | |
| if: ${{ github.event_name == 'pull_request' }} | |
| uses: dorny/test-reporter@v1 | |
| with: | |
| name: .NET Test Reports (${{ matrix.platform }}) | |
| path: "**/TestResults/**/*.trx" | |
| reporter: dotnet-trx | |
| - name: store NuGet package | |
| if: ${{ github.event_name != 'pull_request' && matrix.platform == 'ubuntu' }} | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: nuget-package-${{ matrix.platform }} | |
| path: ./Kepware.Api/bin/Release/*.nupkg | |
| publish: | |
| # Publish the NuGet package and create release assets | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name != 'pull_request' }} | |
| needs: [ build, draft-release ] | |
| env: | |
| tag_name: ${{ needs.draft-release.outputs.tag_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # avoid shallow clone so nbgv can do its work. | |
| - name: Download NuGet package | |
| uses: actions/download-artifact@v6 | |
| with: | |
| name: nuget-package-ubuntu | |
| - name: Push to GitHub Packages | |
| if: ${{ github.event_name != 'pull_request' }} | |
| run: | | |
| dotnet nuget push *.nupkg \ | |
| --api-key ${{ secrets.GITHUB_TOKEN }} \ | |
| --skip-duplicate \ | |
| --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" | |
| - name: Create and Upload Release Asset (Linux) | |
| if: ${{ github.event_name != 'pull_request' }} | |
| run: | | |
| # Upload the NuGet package | |
| gh release upload ${{ env.tag_name }} *.nupkg --clobber | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |