Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ name: build
# windows-latest ships the .NET 8/9/10 SDKs, Windows SDK 10.0.26100 and the
# .NET Framework 4.7.2 targeting pack, which between them cover every TFM in
# NAudio.sln - so no setup-dotnet step and no Windows SDK install is needed.
# (The Azure pipeline this replaces installed Windows SDK 10.1.18362 via
# (The retired Azure pipeline installed Windows SDK 10.1.18362 via
# chocolatey, dating from when NAudio.Uap was a UWP project. It now targets
# net9.0-windows10.0.26100 and gets its Windows projections from the
# Microsoft.Windows.SDK.NET.Ref NuGet package instead.)
#
# Publishing to NuGet is done by release.yml, not from these artifacts.

on:
pull_request:
Expand All @@ -31,7 +33,7 @@ jobs:
- name: Restore
run: dotnet restore NAudio.sln

# Any CPU matches what the Azure pipeline built. Note that
# Any CPU matches what the retired Azure pipeline built. Note that
# NAudioUniversalDemo (WinUI 3) has no Release|Any CPU Build entry in
# NAudio.sln - it has no AnyCPU platform - so it is restored but not
# built, exactly as before.
Expand All @@ -56,13 +58,10 @@ jobs:
--results-directory ${{ runner.temp }}/TestResults

# All nine package projects set GeneratePackageOnBuild, so the Release
# build above already produced the .nupkg files. Uploading them lets a
# release be pushed from a CI-built artifact instead of a local build.
#
# The glob wildcards start at the repo root, so upload-artifact roots the
# zip there and preserves <Package>/bin/Release/<Package>.<version>.nupkg
# - the exact layout publish.ps1 globs for. Extract into an empty
# directory, drop publish.ps1 alongside, and it runs unchanged.
# build above already produced the .nupkg files - and ran package
# validation against the baseline release (see Directory.Build.targets).
# They are uploaded so a PR's packages can be tried out; releases are
# built and pushed by release.yml.
- name: Upload packages
uses: actions/upload-artifact@v4
with:
Expand Down
252 changes: 252 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
name: release

# Publishes NAudio 2.x maintenance releases. Adapted from release.yml on main
# (NAudio 3); keep the two in step where they overlap.
#
# Two triggers:
# - workflow_dispatch (manual): cuts a pre-release, "<VersionPrefix>-preview.<run_number>"
# by default; an optional `milestone` input overrides the suffix (e.g. "rc.1").
# - push of a v* tag on a release/2.x commit: cuts a final release matching <VersionPrefix>.
#
# Why this file has the same name as main's: GitHub only lists dispatchable workflows
# that exist on the default branch, but runs the copy from the branch you pick. With the
# same name, "release" in the Actions tab (or `gh workflow run release.yml --ref release/2.x`)
# runs this file. Tag pushes run the workflow file at the tagged commit, so v2.* tags run this
# file and v3.* tags run main's. The NuGet trusted-publishing policy is keyed on the workflow
# file name, so it covers both.
on:
workflow_dispatch:
inputs:
milestone:
description: "Optional pre-release label (e.g. rc.1). Leave blank for auto preview.<run_number>."
required: false
type: string
push:
tags: ['v*']

permissions:
id-token: write # for NuGet trusted publishing (OIDC)
contents: write # for `gh release create`

jobs:
release:
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Dispatch must come from release/2.x. Tag pushes are unrestricted because
# the tag itself is the gate (and must match VersionPrefix, checked below).
- name: Verify branch (dispatch only)
if: github.event_name == 'workflow_dispatch'
shell: pwsh
run: |
if ($env:GITHUB_REF -ne 'refs/heads/release/2.x') {
Write-Error "2.x release dispatch must be from release/2.x (got $env:GITHUB_REF)."
exit 1
}

- name: Determine version
id: version
shell: pwsh
run: |
[xml]$props = Get-Content Directory.Build.props
$prefix = @($props.Project.PropertyGroup | ForEach-Object { $_.VersionPrefix } | Where-Object { $_ })[0]
if (-not $prefix) {
Write-Error "VersionPrefix not found in Directory.Build.props"
exit 1
}
if (-not $prefix.StartsWith('2.')) {
Write-Error "VersionPrefix $prefix is not a 2.x version; this is the release/2.x release workflow."
exit 1
}

if ($env:GITHUB_REF -like 'refs/tags/v*') {
$tagVersion = $env:GITHUB_REF -replace 'refs/tags/v',''
if ($tagVersion -ne $prefix) {
Write-Error "Tag v$tagVersion does not match VersionPrefix $prefix in Directory.Build.props. Bump the prefix and retag."
exit 1
}
$version = $tagVersion
$packArgs = ""
$isFinal = 'true'
} else {
$milestone = '${{ inputs.milestone }}'
if ([string]::IsNullOrWhiteSpace($milestone)) {
$suffix = "preview.${{ github.run_number }}"
} else {
$suffix = $milestone.Trim()
}
$version = "$prefix-$suffix"
$packArgs = "-p:VersionSuffix=$suffix"
$isFinal = 'false'
}

Write-Host "Resolved version: $version (is_final=$isFinal)"
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"is_final=$isFinal" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"pack_args=$packArgs" | Out-File -FilePath $env:GITHUB_OUTPUT -Append

# Final releases use the '### <version>' section of RELEASE_NOTES.md (and must
# have one); pre-releases use '### Unreleased' if present. The same file feeds
# the package release notes and the GitHub Release body (finals only).
- name: Extract RELEASE_NOTES.md section
shell: pwsh
run: |
$version = '${{ steps.version.outputs.version }}'
$isFinal = '${{ steps.version.outputs.is_final }}' -eq 'true'

if ($isFinal) {
$pattern = "^### $([regex]::Escape($version))(\s|$)"
$label = "### $version"
} else {
$pattern = "^### Unreleased(\s|$)"
$label = "### Unreleased"
}

$lines = Get-Content RELEASE_NOTES.md
$start = -1
$end = $lines.Length
for ($i = 0; $i -lt $lines.Length; $i++) {
if ($lines[$i] -match $pattern) {
$start = $i + 1
} elseif ($start -ge 0 -and $lines[$i] -match "^### ") {
$end = $i
break
}
}

if ($start -lt 0) {
if ($isFinal) {
Write-Error "RELEASE_NOTES.md has no '$label (...)' section. Rename '### Unreleased' to '### $version (DD MMM YYYY)' before tagging."
exit 1
} else {
Write-Warning "RELEASE_NOTES.md has no '$label' section; package release notes will be empty."
"" | Out-File -FilePath release-body.md -Encoding utf8
}
} else {
$body = ''
if ($end -gt $start) { $body = $lines[$start..($end - 1)] -join "`n" }
$body = [regex]::Replace($body, '<!--[\s\S]*?-->', '').Trim()

# NuGet.org caps PackageReleaseNotes at 35,000 characters and rejects an
# oversized package at push time. Fail here instead, before anything is built.
$limit = 35000
if ($body.Length -gt $limit) {
Write-Error "Release notes section '$label' is $($body.Length) chars, over NuGet's $limit-character PackageReleaseNotes limit."
exit 1
}

$body | Out-File -FilePath release-body.md -Encoding utf8
Write-Host "Extracted '$label' ($($body.Length) of $limit chars) to release-body.md."
}

- name: Restore
run: dotnet restore NAudio.sln

# The package projects set GeneratePackageOnBuild, so this build also packs them
# and runs package validation against the baseline release (see Directory.Build.targets).
# Any CPU matches build.yml; NAudioUniversalDemo has no Any CPU entry and is skipped.
- name: Build
run: dotnet build NAudio.sln --configuration Release --no-restore ${{ steps.version.outputs.pack_args }}

# VSTest-mode spelling (positional project, --logger), as in build.yml: this
# branch has no global.json opting into Microsoft.Testing.Platform.
- name: Test
run: >
dotnet test NAudioTests/NAudioTests.csproj
--configuration Release
--no-build
--filter "TestCategory!=IntegrationTest"

# Pack the packages explicitly, into one folder and with the release notes, so the
# tool/sample apps are never shipped. A new package must be added to this list.
- name: Pack
shell: pwsh
run: |
$packages = @(
'NAudio.Core',
'NAudio.Asio',
'NAudio.WinForms',
'NAudio.Midi',
'NAudio.WinMM',
'NAudio.Wasapi',
'NAudio.Uap',
'NAudio',
'NAudio.Extras'
)
$notesPath = Join-Path $env:GITHUB_WORKSPACE "release-body.md"
New-Item -ItemType Directory -Force -Path artifacts | Out-Null
foreach ($pkg in $packages) {
dotnet pack "$pkg/$pkg.csproj" `
--configuration Release `
--no-build `
--output artifacts `
-p:PackageReleaseNotesFile="$notesPath" `
${{ steps.version.outputs.pack_args }}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
$count = @(Get-ChildItem artifacts\*.nupkg).Count
if ($count -ne $packages.Count) {
Write-Error "Expected $($packages.Count) packages in artifacts/, found $count."
exit 1
}

- name: Upload package artifacts
uses: actions/upload-artifact@v4
with:
name: nupkg-${{ steps.version.outputs.version }}
path: artifacts/*.nupkg
if-no-files-found: error

# NuGet trusted publishing via OIDC - the same policy and NUGET_USER variable as main.
- name: NuGet login (trusted publishing)
id: nuget-login
uses: NuGet/login@v1
with:
user: ${{ vars.NUGET_USER }}

# dotnet nuget push doesn't expand globs and PowerShell doesn't expand wildcards
# for external commands, so loop explicitly (also gives per-package errors).
- name: Push to NuGet
shell: pwsh
run: |
$packages = Get-ChildItem -Path "artifacts\*.nupkg"
if (-not $packages) {
Write-Error "No .nupkg files found in artifacts/"
exit 1
}
foreach ($pkg in $packages) {
Write-Host "Pushing $($pkg.Name)"
dotnet nuget push $pkg.FullName `
--api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} `
--source https://api.nuget.org/v3/index.json `
--skip-duplicate
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to push $($pkg.Name)"
exit $LASTEXITCODE
}
}

# GitHub Release on final tag runs only. --latest=false is essential here: without it
# a 2.x release would become the repository's "Latest" release, displacing NAudio 3.
- name: Create GitHub Release (final only)
if: steps.version.outputs.is_final == 'true'
env:
GH_TOKEN: ${{ github.token }}
shell: pwsh
run: |
$assets = @(Get-ChildItem -Path "artifacts\*.nupkg" | ForEach-Object { $_.FullName })
if ($assets.Count -eq 0) {
Write-Error "No .nupkg files found in artifacts/ to attach to the release"
exit 1
}
gh release create "v${{ steps.version.outputs.version }}" `
--title "NAudio ${{ steps.version.outputs.version }}" `
--notes-file release-body.md `
--verify-tag `
--latest=false `
@assets
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<Project>
<PropertyGroup>
<!-- Lockstep version for all NAudio 2.x NuGet packages. The release workflow
adds a <VersionSuffix> on pre-release builds (e.g. preview.NN). The tool apps
(AudioFileInspector, MidiFileConverter, MixDiff) keep their own <Version>.
Bump this right after each stable release, so previews sort above it. -->
<VersionPrefix>2.4.1</VersionPrefix>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<!-- Enable analyzers but don't set default severities - .globalconfig controls rule severities -->
Expand Down
32 changes: 32 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project>
<!--
Settings for the nine NAudio NuGet packages only. They live here rather than in
Directory.Build.props because this file is imported after each csproj, so it can
tell the package projects (the ones that set GeneratePackageOnBuild) apart from
the tests, demos and tools.
-->
<PropertyGroup Condition="'$(GeneratePackageOnBuild)' == 'true'">
<!-- Package validation runs at pack time, which on this branch is every build.
It fails the build if a package drops a public API or a target framework that
the baseline release shipped, which a 2.x patch release must never do.
Keep the baseline on the latest stable 2.x release (see ReleaseInstructions.md
on main). Restore downloads the baseline package, which is why this is scoped
to the package projects. -->
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>2.4.0</PackageValidationBaselineVersion>
</PropertyGroup>

<!--
If PackageReleaseNotesFile is supplied (the release workflow passes
-p:PackageReleaseNotesFile=<path>), load its contents into PackageReleaseNotes
so NuGet displays them on the package page. No-op when the property is unset or
the file is missing, so local builds and packs keep working with no extra setup.
-->
<Target Name="LoadPackageReleaseNotesFromFile"
BeforeTargets="GenerateNuspec"
Condition="'$(PackageReleaseNotesFile)' != '' and Exists('$(PackageReleaseNotesFile)')">
<PropertyGroup>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText('$(PackageReleaseNotesFile)'))</PackageReleaseNotes>
</PropertyGroup>
</Target>
</Project>
1 change: 0 additions & 1 deletion NAudio.Asio/NAudio.Asio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0-windows</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Version>2.4.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>Mark Heath</Authors>
Expand Down
1 change: 0 additions & 1 deletion NAudio.Core/NAudio.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Mark Heath</Authors>
<Version>2.4.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SignAssembly>true</SignAssembly>
Expand Down
10 changes: 10 additions & 0 deletions NAudio.Extras/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:NAudio.Extras.AudioPlaybackEngine</Target>
<Left>lib/netcoreapp3.1/NAudio.Extras.dll</Left>
<Right>lib/net8.0/NAudio.Extras.dll</Right>
</Suppression>
</Suppressions>
1 change: 0 additions & 1 deletion NAudio.Extras/NAudio.Extras.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<RepositoryUrl>https://github.com/naudio/NAudio</RepositoryUrl>
<Copyright>© Mark Heath 2026</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>2.4.0</Version>
<PackageIcon>naudio-icon.png</PackageIcon>
</PropertyGroup>

Expand Down
1 change: 0 additions & 1 deletion NAudio.Midi/NAudio.Midi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.4.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>Mark Heath</Authors>
Expand Down
1 change: 0 additions & 1 deletion NAudio.Uap/NAudio.Uap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<!-- https://docs.microsoft.com/en-us/windows/uwp/updates-and-versions/choose-a-uwp-version -->
<TargetFramework>net9.0-windows10.0.26100</TargetFramework>
<Version>2.4.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>Mark Heath</Authors>
Expand Down
1 change: 0 additions & 1 deletion NAudio.Wasapi/NAudio.Wasapi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net9.0-windows10.0.26100</TargetFrameworks>
<Version>2.4.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>Mark Heath</Authors>
Expand Down
Loading
Loading