Skip to content

Commit

Permalink
Merge pull request #28 from arkahna/feature/fb-102-nuget
Browse files Browse the repository at this point in the history
Feature/fb 102 nuget
  • Loading branch information
idadaniels authored Oct 2, 2023
2 parents 10a6858 + 3029456 commit 5c51d2f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 124 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-seahorses-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'dotnet-sdk': patch
---

Publish FeatureBoard dotnet-sdk
19 changes: 18 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Setup NuGet
uses: nuget/setup-nuget@v1
with:
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
nuget-version: '5.x'

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
Expand All @@ -55,6 +61,14 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Update DotNet SDK version and copyright year
run: |
version=$(node -pe "require('./libs/dotnet-sdk/package.json').version")
currentYear=$(node -pe "new Date().getFullYear()")
csproj_path=libs/dotnet-sdk/FeatureBoard.DotnetSdk.csproj
sed -i "s/<Version>.*<\/Version>/<Version>$version<\/Version>/" $csproj_path
sed -i "s/<Copyright>.*<\/Copyright>/<Copyright>Copyright (c) Arkahna $currentYear<\/Copyright>/" $csproj_path
- name: Push changes
run: |
pnpm i -r --no-frozen-lockfile
Expand All @@ -76,7 +90,10 @@ jobs:
- name: Package libs
run: pnpm package

- name: Release packages
- name: Release NPM packages
run: pnpm publish -r --access public
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Release NuGet package
run: nuget push dist/libs/dotnet-sdk/FeatureBoard.DotnetSdk.$version.nupkg -Source 'https://api.nuget.org/v3/index.json'
21 changes: 19 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ jobs:

- name: Tests
run: pnpm run test


- name: Version command
id: version
run: |
npx changeset version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Update DotNet SDK version and copyright year
run: |
version=$(node -pe "require('./libs/dotnet-sdk/package.json').version")
echo "Version: $version"
currentYear=$(node -pe "new Date().getFullYear()")
csproj_path=libs/dotnet-sdk/FeatureBoard.DotnetSdk.csproj
sed -i "s/<Version>.*<\/Version>/<Version>$version<\/Version>/" $csproj_path
sed -i "s/<Copyright>.*<\/Copyright>/<Copyright>Copyright (c) Arkahna $currentYear<\/Copyright>/" $csproj_path
cat $csproj_path
- name: Package libs
run: pnpm package
run: pnpm package
18 changes: 18 additions & 0 deletions libs/dotnet-sdk/FeatureBoard.DotnetSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1</Version>
<PackageDescription>FeatureBoard .NET SDK for .NET core and framework applications.</PackageDescription>
<PackageTags>feature toggle flags</PackageTags>
<Authors>Arkahna</Authors>
<Copyright>Copyright (c) Arkahna 2023</Copyright>
<PackageIcon>featureboard-logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>https://github.com/arkahna/featureboard-sdks/blob/main/libs/dotnet-sdk/CHANGELOG.md</PackageReleaseNotes>
<PackageProjectUrl>https://docs.featurebard.app</PackageProjectUrl>
<RepositoryUrl>https://github.com/arkahna/featureboard-sdks/</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
Expand All @@ -28,6 +41,11 @@
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="7.*" />
</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
<None Include="assets\featureboard-logo.png" Pack="true" PackagePath="\"/>
</ItemGroup>

<PropertyGroup>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
Expand Down
129 changes: 12 additions & 117 deletions libs/dotnet-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,24 @@
## DotNet SDK

## Installation
## What is FeatureBoard?

```powershell
dotnet add package FeatureBoard.DotnetSdk
```


## Setup

1) Create a Features model
Note that FeatureKeyName can be used here to apply the correct feature key to a property, otherwise feature board will do it's best to convert the property to a kebab case key.
```csharp
using FeatureBoard.DotnetSdk.Models;

public class WeatherFeatures : IFeatures
{
[FeatureKeyName("weather-imperial")]
public bool WeatherImperial { get; set; }
}
```

2) Implement the audiance provider.
This should provide the audiance of the current user or application context and could pull from the users token or app settings etc.
```csharp
using FeatureBoard.DotnetSdk;

public class ClaimsAudienceProvider : IAudienceProvider
{
public List<string> AudienceKeys { get; }

public ClaimsAudienceProvider(IHttpContextAccessor contextAccessor)
{
AudienceKeys = contextAccessor.HttpContext?.User.Claims
.Where(x => x.Type == "audience")
.Select(x => x.Value).ToList() ?? new List<string>();
}
}
```


3) Register the provider in `program.cs`
```csharp
// Register feature board
builder.Services.AddFeatureBoard<WeatherFeatures, ClaimsAudienceProvider>()
.WithPollingUpdateStrategy();
```
FeatureBoard is the future of Feature Toggling and is tailored for SaaS teams on the hunt for a simplified yet highly potent feature toggling solution. FeatureBoard enhances team productivity by allowing everyone to manage software features seamlessly, not just developers.

4) Add any required middleware
```csharp
// Add feature board middleware
app.UseFeatureBoard();
```

5) Add the enviroment key to your appsettings.json file
```json
{
....
"AllowedHosts": "*",
"FeatureBoardOptions": {
"EnvironmentApiKey": "YOUR KEY HERE"
}
}
```



## Usage
```csharp
using FeatureBoard.DotnetSdk;
using FeatureBoardSdks.Examples.DotnetApi.Models;
using Microsoft.AspNetCore.Mvc;

namespace FeatureBoardSdks.Examples.DotnetApi.Controllers;

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
## How do I get started?

private readonly IFeatureBoardClient<WeatherFeatures> _featureBoardClient;
To get started checkout our [getting started guide](https://docs.featureboard.app).

public WeatherForecastController(ILogger<WeatherForecastController> logger, IFeatureBoardClient<WeatherFeatures> featureBoardClient)
{
_featureBoardClient = featureBoardClient;
}
## Install FeatureBoard .Net SDK

[HttpGet(Name = "GetWeatherForecast")]
public async Task<ActionResult<WeatherForecast[]>> Get()
{
if (_featureBoardClient.GetFeatureValue(features => features.WeatherImperial, false))
{
// Return Fahrenheit
}
else
{
// Return Celsius
}
}
}
FeatureBoard .Net SDK is installed from NuGet.

```powershell
dotnet add package FeatureBoard.DotnetSdk
```

## Setup and example

## External State Store
You can create an external state to provide state in case that feature board is unavilable by implementing `IFeatureBoardExternalState`
How to setup and use FeatureBoard .Net SDK can be found in our [documentation](https://docs.featureboard.app/sdks/dotnet-sdk/).

```csharp
using FeatureBoard.DotnetSdk.Models;
using FeatureBoard.DotnetSdk.States;
## Release notes

public class MyExternalState: IFeatureBoardExternalState
{
public Task<Dictionary<string, FeatureConfiguration>> GetState(CancellationToken cancellationToken)
{....}

public Task UpdateState(Dictionary<string, FeatureConfiguration>? features, CancellationToken cancellationToken)
{....}
}
```

And registering it in `program.cs`

```csharp
builder.Services.AddFeatureBoard<WeatherFeatures, QueryStringAudienceProvider>()
.WithPollingUpdateStrategy()
.WithExternalState<MyExternalState>();
```
Our changelog [can be found on GitHub](https://github.com/arkahna/featureboard-sdks/blob/main/libs/dotnet-sdk/CHANGELOG.md).
Binary file added libs/dotnet-sdk/assets/featureboard-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions libs/dotnet-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dontnet-sdk",
"version": "1.0.0",
"name": "dotnet-sdk",
"version": "0.0.1",
"private": true
}
}
12 changes: 11 additions & 1 deletion libs/dotnet-sdk/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@
},
"lint": {
"executor": "@nx-dotnet/core:format"
},
"package": {
"executor": "@nx-dotnet/core:build",
"outputs": [
"{workspaceRoot}/dist/libs/dotnet-sdk"
],
"options": {
"configuration": "Release",
"noDependencies": true
}
}
},
"tags": []
}
}

0 comments on commit 5c51d2f

Please sign in to comment.