Skip to content

v0.1.3

v0.1.3 #12

Workflow file for this run

# 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.Net
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 9 SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x' # Use the specific .NET 9 SDK
- name: Restore dependencies
run: dotnet restore ObsWebSocket.sln
- name: Build Solution
run: dotnet build ObsWebSocket.sln --configuration Release --no-restore
- 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] # Depends only on build job which now creates the artifact on release
# Trigger ONLY on published releases
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
permissions:
contents: read # Needed for download-artifact
steps:
- name: Download NuGet Package Artifact
uses: actions/download-artifact@v4
with:
name: nuget-package # Must match the upload artifact name
path: ${{ env.NuGetDirectory }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
- name: Display Package Information
run: Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg | ForEach-Object { $_.FullName }
- 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 "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}