Build, Test, and Publish ObsWebSocket.Core #35
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
| # GitHub Actions workflow for building, testing, packing, and publishing the ObsWebSocket.Core library. | |
| # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
| name: Build, Test, and Publish ObsWebSocket.Core | |
| on: | |
| workflow_dispatch: # Allow running the workflow manually from the GitHub UI | |
| push: | |
| branches: [ master ] # Run build & test on pushes to master | |
| pull_request: | |
| branches: [ master ] # Run build & test on PRs to master | |
| release: | |
| types: | |
| - published # Trigger build, test, pack AND publish when a release is PUBLISHED | |
| env: | |
| # Prevent the .NET SDK from displaying telemetry welcome messages/banners | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
| # Disable the .NET SDK logo banner | |
| DOTNET_NOLOGO: true | |
| # Define a directory for NuGet package output | |
| NuGetDirectory: ${{ github.workspace}}/nuget | |
| defaults: | |
| run: | |
| shell: pwsh # Use PowerShell | |
| jobs: | |
| build_and_test: | |
| name: Build, Test, and Pack | |
| runs-on: ubuntu-latest # Use the latest Ubuntu runner | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for MinVer to determine the version from Git history | |
| - name: Setup .NET 10 SDK | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '10.x' | |
| - name: Restore dependencies | |
| run: dotnet restore ObsWebSocket.sln | |
| - name: Build Solution | |
| run: dotnet build ObsWebSocket.sln --configuration Release --no-restore | |
| - name: Restore Example for AOT RID graph | |
| run: > | |
| dotnet restore ObsWebSocket.Example/ObsWebSocket.Example.csproj | |
| -p:TargetFramework=net10.0 | |
| --runtime linux-x64 | |
| -p:SelfContained=true | |
| -p:PublishAot=true | |
| - name: Native AOT Smoke Publish (ObsWebSocket.Example) | |
| run: > | |
| dotnet publish ObsWebSocket.Example/ObsWebSocket.Example.csproj | |
| --configuration Release | |
| --framework net10.0 | |
| --runtime linux-x64 | |
| --self-contained true | |
| /p:PublishAot=true | |
| /p:ILLinkTreatWarningsAsErrors=true | |
| /p:IlcTreatWarningsAsErrors=true | |
| /p:WarningsNotAsErrors=IL2104%3BIL3053 | |
| - name: Run Unit Tests | |
| # Run tests specifically for the ObsWebSocket.Tests project | |
| # Exclude integration tests which require a live OBS instance | |
| run: > | |
| dotnet test ObsWebSocket.Tests/ObsWebSocket.Tests.csproj | |
| --configuration Release | |
| --no-build | |
| --verbosity normal | |
| --filter "TestCategory!=Integration" | |
| # --- Packing is now done on push to master OR on release event --- | |
| - name: Pack Library (on master push or release) | |
| # Pack if it's a push to master OR if the event is a release | |
| if: (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event_name == 'release' | |
| run: > | |
| dotnet pack ObsWebSocket.Core/ObsWebSocket.Core.csproj | |
| --configuration Release | |
| --no-build | |
| --output ${{ env.NuGetDirectory }} | |
| # --- Upload artifact on push to master OR on release event --- | |
| - name: Upload NuGet Package Artifact (on master push or release) | |
| # Upload if it's a push to master OR if the event is a release (so publish job can get it) | |
| if: (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event_name == 'release' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-package | |
| if-no-files-found: error | |
| retention-days: 7 | |
| path: ${{ env.NuGetDirectory }}/*.nupkg | |
| publish_nuget: | |
| name: Publish NuGet Package | |
| needs: [build_and_test] | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Download NuGet Package Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ${{ env.NuGetDirectory }} | |
| - name: Setup .NET SDK | |
| uses: actions/setup-dotnet@v4 | |
| - name: NuGet login | |
| uses: NuGet/login@v1 | |
| id: login | |
| with: | |
| user: Agash | |
| - name: Publish NuGet package to NuGet.org | |
| run: | | |
| foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) { | |
| Write-Host "Pushing package: $($file.FullName)" | |
| dotnet nuget push $file --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| } |