Repository navigation
Add a package smoke test gate before publishing to nuget.org #2068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/OpenCvSharp.PackageSmokeTest/OpenCvSharp.PackageSmokeTest.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- | ||
| This project intentionally has no ProjectReference to src/OpenCvSharp: it exists to catch | ||
| packaging mistakes (wrong RID asset placement, missing files, a broken dependency graph) in the | ||
| actual .nupkg files about to be pushed to nuget.org, which a ProjectReference-based test can | ||
| never exercise. .github/workflows/publish_nuget.yml adds the freshly built, not-yet-published | ||
| packages as a local NuGet feed and passes -p:SmokeTestPackageVersion=<version> plus | ||
| -p:SmokeTestRuntimePackage=<runtime package id> before restoring, so this project always targets | ||
| whichever version and platform runtime package is actually about to be published, never a | ||
| hardcoded one. | ||
| --> | ||
| <PropertyGroup> | ||
| <SmokeTestPackageVersion Condition="'$(SmokeTestPackageVersion)' == ''">0.0.0-dev</SmokeTestPackageVersion> | ||
| <SmokeTestRuntimePackage Condition="'$(SmokeTestRuntimePackage)' == ''">OpenCvSharp5.official.runtime.linux-x64</SmokeTestRuntimePackage> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="OpenCvSharp5" Version="$(SmokeTestPackageVersion)" /> | ||
| <PackageReference Include="$(SmokeTestRuntimePackage)" Version="$(SmokeTestPackageVersion)" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Pre-publish smoke test: exercises the actual .nupkg files about to be pushed to nuget.org, | ||
| // referenced the same way a real consumer would (PackageReference against a NuGet feed, not | ||
| // ProjectReference against source), to catch packaging mistakes (wrong RID asset placement, | ||
| // missing native library, broken dependency graph) that a source-level test can never see. | ||
| // Asserts and sets the process exit code instead of using a test framework, since the point is | ||
| // just "does a freshly `dotnet add package`-d app work at all", not exhaustive API coverage. | ||
| using System.Globalization; | ||
| using OpenCvSharp; | ||
|
|
||
| try | ||
| { | ||
| var version = Cv2.GetVersionString(); | ||
|
|
||
| using var mat = new Mat(256, 256, MatType.CV_8UC1, Scalar.All(0)); | ||
| Cv2.Rectangle(mat, new Rect(40, 40, 120, 120), Scalar.All(255), thickness: -1); | ||
| Cv2.Circle(mat, new Point(180, 180), 30, Scalar.All(200), thickness: -1); | ||
|
|
||
| using var orb = ORB.Create(500); | ||
| using var descriptors = new Mat(); | ||
| orb.DetectAndCompute(mat, default, out var keypoints, descriptors); | ||
|
|
||
| foreach (var ext in new[] { ".jpg", ".png", ".tiff" }) | ||
| { | ||
| var encoded = Cv2.ImEncode(ext, mat, out var buf); | ||
| if (!encoded || buf.Length == 0) | ||
| throw new InvalidOperationException($"ImEncode({ext}) failed or produced an empty buffer"); | ||
|
|
||
| using var decoded = Cv2.ImDecode(buf, ImreadModes.Unchanged); | ||
| if (decoded.Empty() || decoded.Size() != mat.Size()) | ||
| throw new InvalidOperationException( | ||
| $"ImDecode({ext}) round trip failed: empty={decoded.Empty()}, size={decoded.Size()}"); | ||
| } | ||
|
|
||
| using var blob = Cv2.Dnn.BlobFromImage(mat, size: new Size(64, 64)); | ||
| if (blob.Empty()) | ||
| throw new InvalidOperationException("Cv2.Dnn.BlobFromImage produced an empty blob"); | ||
|
|
||
| var blobShape = string.Join('x', Enumerable.Range(0, blob.Dims).Select(blob.Size)); | ||
|
|
||
| Console.WriteLine(string.Format( | ||
| CultureInfo.InvariantCulture, | ||
| "ok: OpenCV {0}, ORB keypoints: {1}, dnn blob shape: {2}", | ||
| version, keypoints.Length, blobShape)); | ||
| return 0; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.Error.WriteLine("error: " + ex); | ||
| return 1; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.