Unleash / yggdrasil

MIT License
16 stars 4 forks source link

chore: publish dotnet #128

Closed nunogois closed 3 months ago

nunogois commented 3 months ago

https://linear.app/unleash/issue/2-1629/yggdrasilnet-package-and-publish

Adds a workflow to publish the dotnet engine.

Note: Not uploading to NuGet yet, since we need to set up a token for that. Now publishing to NuGet: https://www.nuget.org/packages/Unleash.Yggdrasil

Current package size is at:

-rw-r--r-- 1 runner docker 3.4M Jun 21 14:33 Yggdrasil.Engine/bin/Release/Yggdrasil.Engine.1.0.0-beta.0.nupkg
-rw-r--r-- 1 runner docker 3.4M Jun 21 14:33 Yggdrasil.Engine/bin/Release/Yggdrasil.Engine.1.0.0-beta.0.symbols.nupkg

Which includes:

image

Weirdly, aarch64-unknown-linux-gnu was the most problematic to get right.

Manual test

Edit: Now that we have the package available in NuGet you can simply:

dotnet add package Unleash.Yggdrasil --version 1.0.0-beta.2

But if you're curious, here's how I manually tested this on my M1 Mac before the NuGet deployment:

  1. Downloaded NuGet package artifact from the action: https://github.com/Unleash/yggdrasil/actions/runs/9615428370/job/26522725796?pr=128#step:9:21

  2. Extracted the ZIP artifact and in that folder ran:

dotnet nuget push "*.nupkg" -s ~/dev/nuget # choose whatever folder you want to use as a local NuGet source
  1. Added NuGet locals and cleared their cache:
dotnet nuget add source ~/dev/nuget # same folder as before
  1. Created a new dotnet project to test our engine:
dotnet new console -n dotnet-test
  1. Installed our package in the test project:
dotnet nuget locals all --clear # just to ensure we don't use stale data
dotnet add package Yggdrasil.Engine --prerelease
  1. Ran test project:
using System.Text.Json;
using Yggdrasil;

class Program
{
  static void Main(string[] args)
  {
    JsonSerializerOptions options = new JsonSerializerOptions
    {
      PropertyNamingPolicy = JsonNamingPolicy.CamelCase
    };

    var testDataObject = new
    {
      Version = 2,
      Features = new[] {
                new {
                    Name = "test.flag",
                    Type = "release",
                    Enabled = true,
                    ImpressionData = true,
                    Strategies = new [] {
                        new {
                            Name = "default",
                            Parameters = new Dictionary<string, string>()
                        }
                    }
                }
            }
    };

    var testData = JsonSerializer.Serialize(testDataObject, options);
    var engine = new YggdrasilEngine();
    engine.TakeState(testData);
    var featureName = "test.flag";
    var result = engine.IsEnabled(featureName, new Context());

    Console.WriteLine(result);
  }
}
❯ dotnet run
True