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
65 changes: 65 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: build

# Build & test on every PR, every push to master, and on demand.
on:
pull_request:
push:
branches: [master]
workflow_dispatch:

jobs:
build:
# windows-latest so the net9.0-windows TestApp (WinForms) builds too.
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Restore
run: dotnet restore NAudio.Vorbis.slnx

- name: Build
run: dotnet build NAudio.Vorbis.slnx --configuration Release --no-restore

- name: Test
run: >
dotnet test NAudio.Vorbis.slnx
--configuration Release
--no-build
--logger trx
--results-directory ${{ runner.temp }}/TestResults

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: ${{ runner.temp }}/TestResults/*.trx
if-no-files-found: warn

# The 1.0.0 line of NVorbis fixes decoder bugs that still affect us on the
# stable 0.10.5 (see "Known NVorbis limitations" in the README), so we keep
# a build honest against it. Allowed to fail: it tracks a prerelease we do
# not ship, and it should not gate a PR when NVorbis publishes a new rc.
build-against-nvorbis-preview:
runs-on: windows-latest
continue-on-error: true

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Build and test against the NVorbis 1.0 prerelease
run: |
dotnet test NAudio.Vorbis.slnx --configuration Release -p:NVorbisVersion=1.0.0-rc.2
244 changes: 244 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
name: release

# Two triggers:
# - workflow_dispatch (manual): cuts a pre-release. By default produces
# "<VersionPrefix>-preview.<run_number>"; an optional `milestone` input
# overrides the suffix (e.g. "alpha.1", "beta.2", "rc.1"). An optional
# `nvorbis_version` input builds the package against a different NVorbis
# than the repo default - that is how a preview on the NVorbis 1.0
# prerelease gets published.
# - push of a v* tag: cuts a final release matching <VersionPrefix>.
on:
workflow_dispatch:
inputs:
milestone:
description: "Optional pre-release label (e.g. alpha.1, beta.2, rc.1). Leave blank for auto preview.<run_number>."
required: false
type: string
nvorbis_version:
description: "Optional NVorbis version to build against (e.g. 1.0.0-rc.2). Leave blank for the repo default."
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 # full history so gh release --generate-notes can diff against the previous tag

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

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

- name: Determine version
id: version
shell: pwsh
run: |
[xml]$props = Get-Content Directory.Build.props
$group = $props.Project.PropertyGroup
$prefix = $group.VersionPrefix
if (-not $prefix) {
Write-Error "VersionPrefix not found in Directory.Build.props"
exit 1
}

# An explicit NVorbis version only applies to a dispatch; a tag build
# always uses the repo default.
$nvorbis = ''
if ($env:GITHUB_REF -notlike 'refs/tags/v*') {
$nvorbis = '${{ inputs.nvorbis_version }}'.Trim()
}
$effectiveNVorbis = if ($nvorbis) { $nvorbis } else { $group.NVorbisVersion.'#text' }

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
}
# A stable package must not carry a prerelease dependency (NU5104).
if ($effectiveNVorbis -like '*-*') {
Write-Error "Cannot cut a final release against prerelease NVorbis $effectiveNVorbis. Move Directory.Build.props to a stable NVorbis first."
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'
}

if ($nvorbis) {
$packArgs = "$packArgs -p:NVorbisVersion=$nvorbis"
}

Write-Host "Resolved version: $version (is_final=$isFinal, NVorbis $effectiveNVorbis)"
"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
"nvorbis=$effectiveNVorbis" | Out-File -FilePath $env:GITHUB_OUTPUT -Append

# Extract the right section from RELEASE_NOTES.md into release-body.md.
# Final releases use the '### <version>' section (and must have one, else
# fail-fast). Pre-releases use the '### Unreleased' section if it exists;
# otherwise the file is just empty and the package ships with no release
# notes. The same release-body.md feeds both the pack step (via
# -p:PackageReleaseNotesFile so NuGet displays the notes on the package
# page) 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 = $lines[$start..($end - 1)] -join "`n"
# Strip HTML comments - useful for contributors editing
# RELEASE_NOTES.md but noisy on the NuGet page / GitHub Release.
$body = [regex]::Replace($body, '<!--[\s\S]*?-->', '').Trim()
$body | Out-File -FilePath release-body.md -Encoding utf8
Write-Host "Extracted '$label' ($($body.Length) chars) to release-body.md."
}

# A preview built against a different NVorbis says so on the package page.
if (-not $isFinal -and '${{ inputs.nvorbis_version }}'.Trim()) {
$note = "`n`nBuilt against NVorbis ${{ steps.version.outputs.nvorbis }}."
Add-Content -Path release-body.md -Value $note
}

- name: Restore
run: dotnet restore NAudio.Vorbis.slnx ${{ steps.version.outputs.pack_args }}

- name: Build
run: dotnet build NAudio.Vorbis.slnx --configuration Release --no-restore ${{ steps.version.outputs.pack_args }}

- name: Test
run: dotnet test NAudio.Vorbis.slnx --configuration Release --no-build

# Pack the library explicitly so we never ship the TestApp sample or the
# test project (both IsPackable=false anyway).
- name: Pack
shell: pwsh
run: |
$notesPath = Join-Path $env:GITHUB_WORKSPACE "release-body.md"
New-Item -ItemType Directory -Force -Path artifacts | Out-Null
dotnet pack NAudio.Vorbis/NAudio.Vorbis.csproj `
--configuration Release `
--no-build `
--output artifacts `
-p:PackageReleaseNotesFile="$notesPath" `
${{ steps.version.outputs.pack_args }}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

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

# NuGet trusted publishing via OIDC. Configure the trusted-publisher
# policy on NuGet.org and set the NUGET_USER repository variable to the
# NuGet.org account/org that owns the package. No long-lived API key.
- name: NuGet login (trusted publishing)
id: nuget-login
uses: NuGet/login@v1
with:
user: ${{ vars.NUGET_USER }}

# dotnet nuget push does not expand globs and PowerShell does not expand
# wildcards in arguments to external commands, so loop explicitly. The
# matching .snupkg symbol package next to the .nupkg is pushed
# automatically by `dotnet nuget push` in the same call.
- 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 only on final tag-driven runs. Pre-releases just ship to
# NuGet - no GitHub Release noise for every preview.
- name: Create GitHub Release (final only)
if: steps.version.outputs.is_final == 'true'
env:
GH_TOKEN: ${{ github.token }}
shell: pwsh
run: |
gh release create "v${{ steps.version.outputs.version }}" `
--title "NAudio.Vorbis ${{ steps.version.outputs.version }}" `
--notes-file release-body.md `
--verify-tag
67 changes: 67 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<Project>
<PropertyGroup>
<!-- Version for the NAudio.Vorbis package. CI overrides <VersionSuffix> on
pre-release builds (e.g. preview.NN). The test and sample apps set
<IsPackable>false</IsPackable> and are never published. -->
<VersionPrefix>3.0.0</VersionPrefix>

<!-- The NVorbis version the package is built against, overridable from the
command line so a preview can be cut against a newer NVorbis without
editing the repo:

dotnet build -p:NVorbisVersion=1.0.0-rc.2

The 1.0.0 line fixes several decoder bugs that still affect us on
0.10.5 - see "Known NVorbis limitations" in the README. Releases stay
on the stable 0.10.5 until 1.0.0 ships, because a stable package
should not carry a prerelease dependency (NuGet NU5104). -->
<NVorbisVersion Condition="'$(NVorbisVersion)' == ''">0.10.5</NVorbisVersion>

<!-- Common NuGet package metadata. The packable csproj adds its own
Description and PackageTags. -->
<Authors>Andrew Ward, Mark Heath</Authors>
<Copyright>© Andrew Ward 2026</Copyright>
<PackageProjectUrl>https://github.com/naudio/Vorbis</PackageProjectUrl>
<RepositoryUrl>https://github.com/naudio/Vorbis</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!-- Shared NAudio-family package icon, anchored to the repo root via
$(MSBuildThisFileDirectory) so it resolves from any csproj depth.
The matching <None Include> is in Directory.Build.targets. -->
<PackageIcon>naudio-icon.png</PackageIcon>

<!-- Strong naming, matching NAudio and NLayer. The .snk lives at the repo root,
anchored via $(MSBuildThisFileDirectory) so csprojs at any depth resolve it.
The key is checked in: for OSS strong naming its private half is not a secret,
it only establishes assembly identity, and a key nobody can build with is worse
than no key at all. The test and sample projects inherit signing, which is
harmless.

Note this is new in 3.0: NAudio.Vorbis 1.5.0 and earlier were unsigned, so the
assembly identity changes. That is a break, but 3.0 already requires a new
target framework and a recompile against NAudio 3, so it costs nothing extra. -->
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)NAudioVorbisStrongNameKey.snk</AssemblyOriginatorKeyFile>
<!-- CS8002: NVorbis is not strong-named (no version of it is, including the 1.0
prereleases), so signing this assembly warns about the reference. .NET Framework
refused to load such a reference, but .NET Core and later dropped strong-name
verification entirely, so on net9.0 it is noise. NAudio.Core is signed. -->
<NoWarn>$(NoWarn);CS8002</NoWarn>

<LangVersion>latest</LangVersion>
<!-- 0 compiler warnings today, so this is free; keeps the build clean. -->
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<!-- SourceLink + symbol packages + reproducible CI builds. .NET 8+ ships
SourceLink in the SDK; PublishRepositoryUrl=true activates it for
GitHub-hosted repos without any PackageReference. Symbol packages
(.snupkg) sit next to the .nupkg and are pushed alongside it
automatically by `dotnet nuget push`. -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>
</Project>
Loading
Loading