diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index a34a9a3..a818803 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -58,7 +58,7 @@ jobs: run: dotnet pack src/ColorHashSharp/ColorHashSharp.csproj --configuration Release --no-build --output artifacts -p:Version=$env:RELEASE_VERSION -p:PackageVersion=$env:RELEASE_VERSION - name: Upload package - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v6 with: name: nuget-package path: artifacts/ColorHashSharp.${{ steps.version.outputs.version }}.nupkg @@ -88,7 +88,7 @@ jobs: dotnet-version: 11.0.x - name: Download package - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v7 with: name: nuget-package path: artifacts diff --git a/README.md b/README.md index 7bd634e..ebcf278 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ -# ColorHashSharp +# ColorHashSharp + Generate color based on the given string. C# port of [ColorHash Javascript Library](https://github.com/zenozeng/color-hash). [![NuGet version (ColorHashSharp)](https://img.shields.io/nuget/v/ColorHashSharp.svg?style=flat-square)](https://www.nuget.org/packages/ColorHashSharp/)   [![NuGet Downloads](https://img.shields.io/nuget/dt/ColorHashSharp.svg)](https://www.nuget.org/packages/ColorHashSharp/)   -[![CodeFactor](https://www.codefactor.io/repository/github/fernandezja/colorhashsharp/badge)](https://www.codefactor.io/repository/github/fernandezja/colorhashsharp) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/7b256a3706a2434e9984dfb9f0d3da93)](https://app.codacy.com/gh/fernandezja/ColorHashSharp/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) +[![CodeFactor](https://www.codefactor.io/repository/github/fernandezja/colorhashsharp/badge)](https://www.codefactor.io/repository/github/fernandezja/colorhashsharp) -[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml/badge.svg)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml)  [![Build status](https://fernandezja.visualstudio.com/ColorHashSharp/_apis/build/status/ColorHashSharp-CI)](https://fernandezja.visualstudio.com/ColorHashSharp/_build/latest?definitionId=4) +[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml/badge.svg)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml) #### Status @@ -18,9 +19,18 @@ Generate color based on the given string. C# port of [ColorHash Javascript Libra |CI |[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml/badge.svg?branch=main)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml) |[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml/badge.svg?branch=develop)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml) | -#### Basic +## Installation + +```sh +dotnet add package ColorHashSharp +``` + +## Basic usage ```csharp +using System.Diagnostics; +using Fernandezja.ColorHashSharp; + Debug.WriteLine($"ColorHash > Hello World"); var colorHash = new ColorHash(); @@ -85,7 +95,7 @@ passed to a custom hash. ### Publishing to NuGet.org -[Publish to NuGet](.github/workflows/publish-nuget.yml) builds and tests each release before packing it. The package version comes from the tag without its leading `v`. Use a stable tag such as `v2.0.0` or a prerelease tag such as `v2.0.0-rc.1`. Omit build metadata (`+...`) because NuGet.org normalizes it out of version identifiers. +[Publish to NuGet](https://github.com/fernandezja/ColorHashSharp/blob/main/.github/workflows/publish-nuget.yml) builds and tests each release before packing it. The package version comes from the tag without its leading `v`. Use a stable tag such as `v2.0.0` or a prerelease tag such as `v2.0.0-rc.1`. Omit build metadata (`+...`) because NuGet.org normalizes it out of version identifiers. 1. In GitHub, open **Settings → Environments → nuget**. Under **Environment variables**, set `NUGET_USER` to the NuGet.org profile name `fernandezja`. Under **Deployment branches and tags**, select **Selected branches and tags** and add a **Tag** rule for `v*.*.*`. 2. On [NuGet.org → Trusted Publishing](https://www.nuget.org/account/trustedpublishing), add a GitHub Actions policy named `ColorHashSharp GitHub Actions` for the package owner. Set **Repository Owner** to `fernandezja`, **Repository** to `ColorHashSharp`, **Workflow File** to `publish-nuget.yml`, and **Environment** to `nuget`. Select **Push only new package versions** and enter `ColorHashSharp` under **Glob Patterns and Packages**. The workflow exchanges its OIDC token for a short-lived API key when the package is ready to publish. @@ -97,3 +107,7 @@ passed to a custom hash. ``` Check **Actions → Publish to NuGet** for the result, then verify the version on the [ColorHashSharp package page](https://www.nuget.org/packages/ColorHashSharp/). + +## Feedback and contributions + +Report issues and suggest improvements on [GitHub](https://github.com/fernandezja/ColorHashSharp/issues). Contributions are welcome through [pull requests](https://github.com/fernandezja/ColorHashSharp/pulls). diff --git a/assets/icon/ColorHashSharp-40x40.png b/assets/icon/ColorHashSharp-40x40.png new file mode 100644 index 0000000..394e142 Binary files /dev/null and b/assets/icon/ColorHashSharp-40x40.png differ diff --git a/src/ColorHashSharp.Tests/ColorConversionEdgeCasesTest.cs b/src/ColorHashSharp.Tests/ColorConversionEdgeCasesTest.cs index e28b645..63f8c74 100644 --- a/src/ColorHashSharp.Tests/ColorConversionEdgeCasesTest.cs +++ b/src/ColorHashSharp.Tests/ColorConversionEdgeCasesTest.cs @@ -137,7 +137,8 @@ public void TransformSaturationAndBrightness_ExtremeValues() 5.0, 5.0); - Assert.NotNull(result); + var expected = SimpleColorTransforms.HsBtoRgb(210, 1, 1); + Assert.Equal(expected, result); } #endregion diff --git a/src/ColorHashSharp.Tests/ColorToRgbTest.cs b/src/ColorHashSharp.Tests/ColorToRgbTest.cs index e219025..993008d 100644 --- a/src/ColorHashSharp.Tests/ColorToRgbTest.cs +++ b/src/ColorHashSharp.Tests/ColorToRgbTest.cs @@ -88,7 +88,6 @@ public void ToRgb1_AllSectors_ShouldConvert(double hue) { var result = ColorToRgb.ToRgb1(hue, 1, 0.5); - Assert.NotNull(result); Assert.Equal(255, result.A); } diff --git a/src/ColorHashSharp.Tests/SimpleColorTransformsTest.cs b/src/ColorHashSharp.Tests/SimpleColorTransformsTest.cs index 22faba2..bde46e3 100644 --- a/src/ColorHashSharp.Tests/SimpleColorTransformsTest.cs +++ b/src/ColorHashSharp.Tests/SimpleColorTransformsTest.cs @@ -384,7 +384,7 @@ public void TransformSaturationAndBrightness_ZeroSaturationWithIncrease_ShouldIn 2.0, 1.0); - Assert.NotNull(result); + Assert.True(result.GetSaturation() > color.GetSaturation()); } [Fact(DisplayName = "TransformSaturationAndBrightness_ZeroBrightnessWithIncrease_ShouldIncrease")] @@ -397,7 +397,7 @@ public void TransformSaturationAndBrightness_ZeroBrightnessWithIncrease_ShouldIn 1.0, 2.0); - Assert.NotNull(result); + Assert.True(result.GetBrightness() > color.GetBrightness()); } [Fact(DisplayName = "TransformSaturationAndBrightness_WithCustomAlpha_ShouldSetAlpha")] diff --git a/src/ColorHashSharp/ColorHashSharp.csproj b/src/ColorHashSharp/ColorHashSharp.csproj index 65a21d9..98f18e2 100644 --- a/src/ColorHashSharp/ColorHashSharp.csproj +++ b/src/ColorHashSharp/ColorHashSharp.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;netstandard2.1;net48;net481;net10.0;net11.0 @@ -13,6 +13,7 @@ https://licenses.nuget.org/MIT ColorHashSharp-icon.png + README.md https://github.com/fernandezja/ColorHashSharp color hash string hsl hex hexadecimal Generate color based on the given string. C# port of ColorHash Javascript Library. See https://github.com/fernandezja/ColorHashSharp @@ -28,5 +29,6 @@ +