Skip to content

Commit

Permalink
Nuget Package CI/CD Overhaul (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbah authored Jul 7, 2023
1 parent cba5f13 commit 9023b5a
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 204 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: ci
on:
push:
branches: [master, release-*]
pull_request:
env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
jobs:
ci:
strategy:
fail-fast: false
matrix:
job:
- name: ubuntu
os: ubuntu-22.04
- name: windows
os: windows-2022
name: ${{ matrix.job.name }}
runs-on: ${{ matrix.job.os }}
steps:
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.411
7.0.305
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal DMISharp.Tests/DMISharp.Tests.csproj --logger GitHubActions
- if: matrix.job.name == 'ubuntu'
uses: actions/upload-artifact@v3
with:
name: NuGet packages
path: ./**/*.nupkg
30 changes: 0 additions & 30 deletions .github/workflows/dotnet.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: release
on:
push:
tags: ["*.*.*"]
env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
jobs:
release:
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.305
- uses: actions/checkout@v3
- run: dotnet build --configuration Release --nologo
- name: push
env:
SOURCE: ${{ secrets.NUGET_PUSH_SOURCE }}
API_KEY: ${{ secrets.NUGET_PUSH_API_KEY }}
if: env.SOURCE != '' || env.API_KEY != ''
run: dotnet nuget push ./**/*.nupkg --source ${{ env.SOURCE }} --api-key ${{ env.API_KEY }}
4 changes: 4 additions & 0 deletions DMISharp.Tests/DMICreationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public void CanCreateDMIFromImages()
foreach (var source in sourceData)
{
var img = Image.Load<Rgba32>($@"Data/Input/SourceImages/{source}.png");
#pragma warning disable CA2000
var newState = new DMIState(source, DirectionDepth.One, 1, 32, 32);
#pragma warning restore CA2000
newState.SetFrame(img, 0);
newDMI.AddState(newState);
}
Expand All @@ -46,7 +48,9 @@ public void CanChangeDMIDepths()

// Create state
var img = Image.Load<Rgba32>($@"Data/Input/SourceImages/steve32.png");
#pragma warning disable CA2000
var newState = new DMIState("steve32", DirectionDepth.One, 1, 32, 32);
#pragma warning restore CA2000
newState.SetFrame(img, 0);
newDMI.AddState(newState);

Expand Down
7 changes: 3 additions & 4 deletions DMISharp.Tests/DMIModifyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

namespace DMISharp.Tests;

// ReSharper disable once ClassNeverInstantiated.Global
public class DMIModifyTests
public static class DMIModifyTests
{
[Fact]
public static void ShouldRemoveStateMetadata()
Expand Down Expand Up @@ -37,7 +36,7 @@ public static void ShouldDetectValidUnmodifiedDMIState()
}

[Fact]
public static void ShouldDetectInvalidDMIState__MissingFrame()
public static void ShouldDetectInvalidDMIStateMissingFrame()
{
// Arrange
using var file = new DMIFile(@"Data/Input/turf_analysis.dmi");
Expand All @@ -52,7 +51,7 @@ public static void ShouldDetectInvalidDMIState__MissingFrame()
}

[Fact]
public static void ShouldDetectInvalidDMIState__MissingDirection()
public static void ShouldDetectInvalidDMIStateMissingDirection()
{
// Arrange
using var file = new DMIFile(@"Data/Input/turf_analysis.dmi");
Expand Down
12 changes: 8 additions & 4 deletions DMISharp.Tests/DMISharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3"/>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1"/>
<PackageReference Include="xunit" Version="2.5.0"/>
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DMISharp\DMISharp.csproj"/>
<ProjectReference Include="..\DMISharp\DMISharp.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
143 changes: 70 additions & 73 deletions DMISharp.Tests/DMIWriteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,136 +84,133 @@ public void ResavingFileMatchesOriginalMetadata(string inputPath, string outputP
if (File.Exists(outputPath))
File.Delete(outputPath);

using (var fs = File.OpenWrite(outputPath!))
using (var fs = File.OpenWrite(outputPath))
using (var originalFile = new DMIFile(inputPath))
originalFile.Save(fs);

// Check metadata is equal
using (var oldFile = File.OpenRead(inputPath))
using (var newFile = File.OpenRead(outputPath))
Assert.Equal(DMIMetadata.GetDMIMetadata(oldFile).ToString(), DMIMetadata.GetDMIMetadata(newFile).ToString());
using var oldFile = File.OpenRead(inputPath);
using var newFile = File.OpenRead(outputPath);
Assert.Equal(DMIMetadata.GetDMIMetadata(oldFile).ToString(), DMIMetadata.GetDMIMetadata(newFile).ToString());
}

[Theory]
[InlineData(@"Data/Input/broadMobs.dmi", @"Data/Output/broadMobs.dmi")]
public void ResavingFileMatchesOriginalImage_RectSprites(string inputPath, string outputPath)
public void ResavingFileMatchesOriginalImageRectSprites(string inputPath, string outputPath)
{
if (File.Exists(outputPath))
File.Delete(outputPath);

using (var fs = File.OpenWrite(outputPath!))
using (var fs = File.OpenWrite(outputPath))
using (var originalFile = new DMIFile(inputPath))
originalFile.Save(fs);

// Check image is equal
var pixelDiffs = 0;
using (var oldFile = Image.Load<Rgba32>(inputPath))
using (var newFile = Image.Load<Rgba32>(outputPath))
{
// Check overall dimensions
Assert.Equal(oldFile.Width, newFile.Width);
Assert.Equal(oldFile.Height, newFile.Height);
using var oldFile = Image.Load<Rgba32>(inputPath);
using var newFile = Image.Load<Rgba32>(outputPath);

// Check overall dimensions
Assert.Equal(oldFile.Width, newFile.Width);
Assert.Equal(oldFile.Height, newFile.Height);

// Check pixel content
var height = oldFile.Height;
var width = oldFile.Width;
oldFile.ProcessPixelRows(newFile, (oldAccessor, newAccessor) =>
// Check pixel content
var height = oldFile.Height;
var width = oldFile.Width;
oldFile.ProcessPixelRows(newFile, (oldAccessor, newAccessor) =>
{
for (var ypx = 0; ypx < height; ypx++)
{
for (var ypx = 0; ypx < height; ypx++)
var oldSpan = oldAccessor.GetRowSpan(ypx);
var newSpan = newAccessor.GetRowSpan(ypx);
for (var xpx = 0; xpx < width; xpx++)
{
var oldSpan = oldAccessor.GetRowSpan(ypx);
var newSpan = newAccessor.GetRowSpan(ypx);
for (var xpx = 0; xpx < width; xpx++)
{
if (!(oldSpan[xpx].A == 0 && newSpan[xpx].A == 0) && oldSpan[xpx] != newSpan[xpx])
pixelDiffs++;
}
if (!(oldSpan[xpx].A == 0 && newSpan[xpx].A == 0) && oldSpan[xpx] != newSpan[xpx])
pixelDiffs++;
}
});
}
}
});

Assert.Equal(0, pixelDiffs);
}

[Theory]
[InlineData(@"Data/Input/animal.dmi", @"Data/Output/animal.dmi")]
public void ResavingFileMatchesOriginalImage_SquareSprites(string inputPath, string outputPath)
public void ResavingFileMatchesOriginalImageSquareSprites(string inputPath, string outputPath)
{
if (File.Exists(outputPath))
File.Delete(outputPath);

using (var fs = File.OpenWrite(outputPath!))
using (var fs = File.OpenWrite(outputPath))
using (var originalFile = new DMIFile(inputPath))
originalFile.Save(fs);

// Check image is equal
var pixelDiffs = 0;
using (var oldFile = Image.Load<Rgba32>(inputPath))
using (var newFile = Image.Load<Rgba32>(outputPath))
{
// Check overall dimensions
Assert.Equal(oldFile.Width, newFile.Width);
Assert.Equal(oldFile.Height, newFile.Height);
using var oldFile = Image.Load<Rgba32>(inputPath);
using var newFile = Image.Load<Rgba32>(outputPath);

// Check overall dimensions
Assert.Equal(oldFile.Width, newFile.Width);
Assert.Equal(oldFile.Height, newFile.Height);

// Check pixel content
var height = oldFile.Height;
var width = oldFile.Width;
oldFile.ProcessPixelRows(newFile, (oldAccessor, newAccessor) =>
// Check pixel content
var height = oldFile.Height;
var width = oldFile.Width;
oldFile.ProcessPixelRows(newFile, (oldAccessor, newAccessor) =>
{
for (var ypx = 0; ypx < height; ypx++)
{
for (var ypx = 0; ypx < height; ypx++)
var oldSpan = oldAccessor.GetRowSpan(ypx);
var newSpan = newAccessor.GetRowSpan(ypx);
for (var xpx = 0; xpx < width; xpx++)
{
var oldSpan = oldAccessor.GetRowSpan(ypx);
var newSpan = newAccessor.GetRowSpan(ypx);
for (var xpx = 0; xpx < width; xpx++)
{
if (!(oldSpan[xpx].A == 0 && newSpan[xpx].A == 0) && oldSpan[xpx] != newSpan[xpx])
pixelDiffs++;
}
if (!(oldSpan[xpx].A == 0 && newSpan[xpx].A == 0) && oldSpan[xpx] != newSpan[xpx])
pixelDiffs++;
}
});
}
}
});

Assert.Equal(0, pixelDiffs);
}

[Theory]
[InlineData(@"Data/Input/light_64.dmi", @"Data/Output/light_64.dmi")]
public void ResavingFileMatchesOriginalImage_SingleSprite(string inputPath, string outputPath)
public void ResavingFileMatchesOriginalImageSingleSprite(string inputPath, string outputPath)
{
if (File.Exists(outputPath))
File.Delete(outputPath);

using (var fs = File.OpenWrite(outputPath!))
using (var fs = File.OpenWrite(outputPath))
using (var originalFile = new DMIFile(inputPath))
originalFile.Save(fs);

// Check image is equal
var pixelDiffs = 0;
using (var oldFile = Image.Load<Rgba32>(inputPath))
using (var newFile = Image.Load<Rgba32>(outputPath))
{
// Check overall dimensions
Assert.Equal(oldFile.Width, newFile.Width);
Assert.Equal(oldFile.Height, newFile.Height);
using var oldFile = Image.Load<Rgba32>(inputPath);
using var newFile = Image.Load<Rgba32>(outputPath);

// Check overall dimensions
Assert.Equal(oldFile.Width, newFile.Width);
Assert.Equal(oldFile.Height, newFile.Height);

// Check pixel content
var height = oldFile.Height;
var width = oldFile.Width;
oldFile.ProcessPixelRows(newFile, (oldAccessor, newAccessor) =>
// Check pixel content
var height = oldFile.Height;
var width = oldFile.Width;
oldFile.ProcessPixelRows(newFile, (oldAccessor, newAccessor) =>
{
for (var ypx = 0; ypx < height; ypx++)
{
for (var ypx = 0; ypx < height; ypx++)
var oldSpan = oldAccessor.GetRowSpan(ypx);
var newSpan = newAccessor.GetRowSpan(ypx);
for (var xpx = 0; xpx < width; xpx++)
{
var oldSpan = oldAccessor.GetRowSpan(ypx);
var newSpan = newAccessor.GetRowSpan(ypx);
for (var xpx = 0; xpx < width; xpx++)
{
if (!(oldSpan[xpx].A == 0 && newSpan[xpx].A == 0) && oldSpan[xpx] != newSpan[xpx])
pixelDiffs++;
}
if (!(oldSpan[xpx].A == 0 && newSpan[xpx].A == 0) && oldSpan[xpx] != newSpan[xpx])
pixelDiffs++;
}
});
}
}
});

Assert.Equal(0, pixelDiffs);
}
}
Loading

0 comments on commit 9023b5a

Please sign in to comment.