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
26 changes: 17 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,31 @@ jobs:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: |
9.x
10.x
- name: Derive CI package version
shell: pwsh
run: |
$version = dotnet msbuild src/OpenDisNet/OpenDisNet.csproj -getProperty:Version -nologo
"PACKAGE_VERSION=${version}-ci.${{ github.run_id }}" >> $env:GITHUB_ENV
- run: dotnet restore --locked-mode
- run: dotnet run --project tools/OpenDisNet.Generator/OpenDisNet.Generator.csproj --configuration Release --no-restore -- --verify
- run: dotnet build --configuration Release --no-restore
- run: dotnet build --configuration Release --no-restore --no-incremental -p:Version=${{ env.PACKAGE_VERSION }}
- run: dotnet test --configuration Release --no-build
- run: dotnet pack src/OpenDisNet/OpenDisNet.csproj --configuration Release --no-build --output artifacts/packages -p:PackageVersion=0.0.0-ci.${{ github.run_id }}
- run: dotnet pack src/OpenDisNet/OpenDisNet.csproj --configuration Release --no-build --no-restore --output artifacts/packages -p:Version=${{ env.PACKAGE_VERSION }} -p:PackageVersion=${{ env.PACKAGE_VERSION }}
- name: Inspect package
shell: pwsh
run: ./eng/Validate-Package.ps1 -PackagePath ./artifacts/packages/OpenDisNet.${{ env.PACKAGE_VERSION }}.nupkg -ExpectedVersion ${{ env.PACKAGE_VERSION }}
- name: Restore packed-package consumer
run: dotnet restore tests/OpenDisNet.PackageSmoke/OpenDisNet.PackageSmoke.csproj --source "${{ github.workspace }}/artifacts/packages" --force --no-cache -p:OpenDisNetPackageVersion=0.0.0-ci.${{ github.run_id }}
run: dotnet restore tests/OpenDisNet.PackageSmoke/OpenDisNet.PackageSmoke.csproj --source "${{ github.workspace }}/artifacts/packages" --force --no-cache -p:OpenDisNetPackageVersion=${{ env.PACKAGE_VERSION }}
- name: Run packed-package consumer on .NET 9
run: dotnet run --project tests/OpenDisNet.PackageSmoke/OpenDisNet.PackageSmoke.csproj --configuration Release --framework net9.0 --no-restore -p:OpenDisNetPackageVersion=0.0.0-ci.${{ github.run_id }}
run: dotnet run --project tests/OpenDisNet.PackageSmoke/OpenDisNet.PackageSmoke.csproj --configuration Release --framework net9.0 --no-restore -p:OpenDisNetPackageVersion=${{ env.PACKAGE_VERSION }}
- name: Run packed-package consumer on .NET 10
run: dotnet run --project tests/OpenDisNet.PackageSmoke/OpenDisNet.PackageSmoke.csproj --configuration Release --framework net10.0 --no-restore -p:OpenDisNetPackageVersion=0.0.0-ci.${{ github.run_id }}
run: dotnet run --project tests/OpenDisNet.PackageSmoke/OpenDisNet.PackageSmoke.csproj --configuration Release --framework net10.0 --no-restore -p:OpenDisNetPackageVersion=${{ env.PACKAGE_VERSION }}
- uses: actions/upload-artifact@v7
if: matrix.os == 'ubuntu-latest'
with:
Expand All @@ -42,8 +50,8 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.x
- run: dotnet restore --locked-mode
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
- uses: github/codeql-action/init@v4
with:
languages: csharp
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
- name: Reject vulnerable dependency changes
uses: actions/dependency-review-action@v5
with:
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v5
- uses: actions/setup-dotnet@v6
with:
dotnet-version: |
9.x
Expand All @@ -29,8 +29,12 @@ jobs:
shell: bash
run: echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
- run: dotnet restore --locked-mode
- run: dotnet test --configuration Release --no-restore
- run: dotnet pack src/OpenDisNet/OpenDisNet.csproj --configuration Release --no-restore --output artifacts/packages -p:PackageVersion=${{ env.PACKAGE_VERSION }}
- run: dotnet build --configuration Release --no-restore --no-incremental -p:Version=${{ env.PACKAGE_VERSION }}
- run: dotnet test --configuration Release --no-build
- run: dotnet pack src/OpenDisNet/OpenDisNet.csproj --configuration Release --no-build --no-restore --output artifacts/packages -p:Version=${{ env.PACKAGE_VERSION }} -p:PackageVersion=${{ env.PACKAGE_VERSION }}
- name: Inspect package
shell: pwsh
run: ./eng/Validate-Package.ps1 -PackagePath ./artifacts/packages/OpenDisNet.${{ env.PACKAGE_VERSION }}.nupkg -ExpectedVersion ${{ env.PACKAGE_VERSION }}
- name: Restore packed-package consumer
run: dotnet restore tests/OpenDisNet.PackageSmoke/OpenDisNet.PackageSmoke.csproj --source "${{ github.workspace }}/artifacts/packages" --force --no-cache -p:OpenDisNetPackageVersion=${{ env.PACKAGE_VERSION }}
- name: Run packed-package consumer on .NET 9
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ incomplete.

## 1.0.2 - Unreleased

- Ensured NuGet package, assembly, file, and informational versions agree for
release and CI builds, with package-level validation for both target frameworks.
- Migrated the test suite to MSTest, refreshed the test platform and GitHub
Actions dependencies, and removed the unused code-coverage collector.
- Expanded NuGet metadata and search terms for Distributed Interactive
Simulation, IEEE 1278.1, DIS v7, SISO, PDU parsing, and binary serialization.
- Added a package icon, explicit project/repository links, release-notes link,
Expand Down
113 changes: 113 additions & 0 deletions eng/Validate-Package.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string] $PackagePath,

[Parameter(Mandatory)]
[string] $ExpectedVersion,

[string] $ExpectedPackageId = 'OpenDisNet'
)

$ErrorActionPreference = 'Stop'
$resolvedPackage = (Resolve-Path -LiteralPath $PackagePath).Path

Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [System.IO.Compression.ZipFile]::OpenRead($resolvedPackage)

try {
$entryNames = @($archive.Entries | ForEach-Object FullName)
$requiredEntries = @(
'README.md',
'opendisnet-icon.png',
'lib/net9.0/OpenDisNet.dll',
'lib/net10.0/OpenDisNet.dll'
)

foreach ($entry in $requiredEntries) {
if ($entryNames -cnotcontains $entry) {
throw "Package is missing required entry '$entry'."
}
}

$nuspecEntry = $archive.Entries |
Where-Object FullName -Like '*.nuspec' |
Select-Object -First 1
if ($null -eq $nuspecEntry) {
throw 'Package does not contain a .nuspec file.'
}

$reader = [System.IO.StreamReader]::new($nuspecEntry.Open())
try {
[xml] $nuspec = $reader.ReadToEnd()
}
finally {
$reader.Dispose()
}

$metadata = $nuspec.package.metadata
if ($metadata.id -ne $ExpectedPackageId) {
throw "Expected package ID '$ExpectedPackageId', found '$($metadata.id)'."
}

if ($metadata.version -ne $ExpectedVersion) {
throw "Expected package version '$ExpectedVersion', found '$($metadata.version)'."
}

if ($ExpectedVersion -notmatch '^(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$') {
throw "Expected version '$ExpectedVersion' is not a supported semantic version."
}

$expectedAssemblyVersion = "$($Matches[1]).$($Matches[2]).$($Matches[3]).0"
$assemblyEntries = @(
'lib/net9.0/OpenDisNet.dll',
'lib/net10.0/OpenDisNet.dll'
)
$temporaryDirectory = Join-Path ([System.IO.Path]::GetTempPath()) (
'opendisnet-package-validation-' + [System.Guid]::NewGuid().ToString('N'))
[void] [System.IO.Directory]::CreateDirectory($temporaryDirectory)

try {
foreach ($entryName in $assemblyEntries) {
$assemblyEntry = $archive.GetEntry($entryName)
$temporaryAssembly = Join-Path $temporaryDirectory ($entryName.Replace('/', '_'))
$sourceStream = $assemblyEntry.Open()
$destinationStream = [System.IO.File]::Create($temporaryAssembly)

try {
$sourceStream.CopyTo($destinationStream)
}
finally {
$destinationStream.Dispose()
$sourceStream.Dispose()
}

$assemblyVersion = [System.Reflection.AssemblyName]::GetAssemblyName(
$temporaryAssembly).Version.ToString()
$fileVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo(
$temporaryAssembly)

if ($assemblyVersion -ne $expectedAssemblyVersion) {
throw "Expected '$entryName' assembly version '$expectedAssemblyVersion', found '$assemblyVersion'."
}

if ($fileVersion.FileVersion -ne $expectedAssemblyVersion) {
throw "Expected '$entryName' file version '$expectedAssemblyVersion', found '$($fileVersion.FileVersion)'."
}

if ($fileVersion.ProductVersion -ne $ExpectedVersion -and
-not $fileVersion.ProductVersion.StartsWith(
"$ExpectedVersion+", [System.StringComparison]::Ordinal)) {
throw "Expected '$entryName' product version '$ExpectedVersion', found '$($fileVersion.ProductVersion)'."
}
}
}
finally {
[System.IO.Directory]::Delete($temporaryDirectory, $true)
}

Write-Host "Validated $ExpectedPackageId $ExpectedVersion ($($entryNames.Count) entries)."
}
finally {
$archive.Dispose()
}
21 changes: 11 additions & 10 deletions tests/OpenDisNet.Tests/Binary/DisHeaderCodecTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@

namespace OpenDisNet.Tests.Binary;

[TestClass]
public sealed class DisHeaderCodecTests
{
[Fact]
[TestMethod]
public void ReadsVersion7HeaderInNetworkByteOrder()
{
byte[] bytes = [7, 3, 1, 1, 0x01, 0x02, 0x03, 0x04, 0, 12, 0xA5, 0];
var reader = new DisBinaryReader(bytes);

DisHeader header = DisHeaderCodec.Read(ref reader);

Assert.Equal(DisProtocolVersion.Ieee1278_1_2012, header.ProtocolVersion);
Assert.Equal((byte)3, header.ExerciseId);
Assert.Equal(PduType.EntityState, header.PduType);
Assert.Equal(0x01020304u, header.Timestamp);
Assert.Equal((ushort)12, header.Length);
Assert.Equal((byte)0xA5, header.PduStatus);
Assert.Equal(12, reader.Offset);
Assert.AreEqual(DisProtocolVersion.Ieee1278_1_2012, header.ProtocolVersion);
Assert.AreEqual((byte)3, header.ExerciseId);
Assert.AreEqual(PduType.EntityState, header.PduType);
Assert.AreEqual(0x01020304u, header.Timestamp);
Assert.AreEqual((ushort)12, header.Length);
Assert.AreEqual((byte)0xA5, header.PduStatus);
Assert.AreEqual(12, reader.Offset);
}

[Fact]
[TestMethod]
public void WriterRoundTripsHeader()
{
var expected = new DisHeader(DisProtocolVersion.Ieee1278_1_2012, 9, PduType.Fire, ProtocolFamily.Warfare, 42, 12, 0, 0);
Expand All @@ -31,6 +32,6 @@ public void WriterRoundTripsHeader()
DisHeaderCodec.Write(ref writer, expected);
var reader = new DisBinaryReader(bytes);

Assert.Equal(expected, DisHeaderCodec.Read(ref reader));
Assert.AreEqual(expected, DisHeaderCodec.Read(ref reader));
}
}
27 changes: 14 additions & 13 deletions tests/OpenDisNet.Tests/Conformance/ConformanceAuditTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,53 @@

namespace OpenDisNet.Tests.Conformance;

[TestClass]
public sealed class ConformanceAuditTests
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
PropertyNameCaseInsensitive = true,
};

[Fact]
[TestMethod]
public void AuditedInputsHaveNotChanged()
{
string root = FindRepositoryRoot();
AuditManifest manifest = ReadManifest(root);

Assert.Equal("1.0.1", manifest.AuditVersion);
Assert.Equal(72, manifest.PduTypeCount);
Assert.Equal(233, manifest.ConcreteWireClassCount);
Assert.Equal(17, manifest.Artifacts.Length);
Assert.AreEqual("1.0.1", manifest.AuditVersion);
Assert.AreEqual(72, manifest.PduTypeCount);
Assert.AreEqual(233, manifest.ConcreteWireClassCount);
Assert.AreEqual(17, manifest.Artifacts.Length);

foreach (AuditArtifact artifact in manifest.Artifacts)
{
string path = Path.Combine(root, artifact.Path.Replace('/', Path.DirectorySeparatorChar));
Assert.True(File.Exists(path), $"Audited input is missing: {artifact.Path}");
Assert.IsTrue(File.Exists(path), $"Audited input is missing: {artifact.Path}");
byte[] normalized = Encoding.UTF8.GetBytes(File.ReadAllText(path).ReplaceLineEndings("\n"));
string actual = Convert.ToHexStringLower(SHA256.HashData(normalized));
Assert.Equal(artifact.Sha256, actual);
Assert.AreEqual(artifact.Sha256, actual);
}
}

[Fact]
[TestMethod]
public void AuditAccountsForEveryStandardPduAndFamily()
{
string root = FindRepositoryRoot();
AuditManifest manifest = ReadManifest(root);
int[] auditedTypes = manifest.Families.SelectMany(x => x.Types).Order().ToArray();

Assert.Equal(Enumerable.Range(1, 72), auditedTypes);
Assert.Equal(72, manifest.Families.Sum(x => x.Count));
Assert.Equal(12, manifest.Families.Length);
Assert.AreSequenceEqual(Enumerable.Range(1, 72), auditedTypes);
Assert.AreEqual(72, manifest.Families.Sum(x => x.Count));
Assert.AreEqual(12, manifest.Families.Length);

foreach (AuditFamily family in manifest.Families)
{
Assert.Equal(family.Count, family.Types.Length);
Assert.AreEqual(family.Count, family.Types.Length);
foreach (int type in family.Types)
{
Pdu pdu = PduFactory.Create((PduType)type);
Assert.Equal((ProtocolFamily)family.Value, pdu.ProtocolFamily);
Assert.AreEqual((ProtocolFamily)family.Value, pdu.ProtocolFamily);
}
}
}
Expand Down
Loading
Loading