Skip to content

chore: Add support for GitHub Packages #134

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 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: CI

on:
push:
branches: [ main ]
paths-ignore:
- '**.md'
pull_request:
branches: [ main ]
paths-ignore:
- '**.md'

jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
dotnet-version: |
6.0.x
7.0.x
source-url: https://nuget.pkg.github.com/open-feature/index.json

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --logger GitHubActions

packaging:
needs: build

permissions:
contents: read
packages: write

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
dotnet-version: |
6.0.x
7.0.x
source-url: https://nuget.pkg.github.com/open-feature/index.json

- name: Restore
run: dotnet restore

- name: Pack NuGet packages (CI versions)
if: startsWith(github.ref, 'refs/heads/')
run: dotnet pack --no-restore --version-suffix "ci.$(date -u +%Y%m%dT%H%M%S)+sha.${GITHUB_SHA:0:9}"

- name: Pack NuGet packages (PR versions)
if: startsWith(github.ref, 'refs/pull/')
run: dotnet pack --no-restore --version-suffix "pr.$(date -u +%Y%m%dT%H%M%S)+sha.${GITHUB_SHA:0:9}"

- name: Publish NuGet packages (base)
if: github.event.pull_request.head.repo.fork == false
run: dotnet nuget push "src/**/*.nupkg" --api-key "${{ secrets.GITHUB_TOKEN }}" --source https://nuget.pkg.github.com/open-feature/index.json

- name: Publish NuGet packages (fork)
if: github.event.pull_request.head.repo.fork == true
uses: actions/[email protected]
with:
name: nupkgs
path: src/**/*.nupkg
34 changes: 0 additions & 34 deletions .github/workflows/linux-ci.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ jobs:
fetch-depth: 0
submodules: recursive

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
dotnet-version: |
6.0.x
7.0.x
source-url: https://nuget.pkg.github.com/open-feature/index.json
Comment on lines +26 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this change impact the Publish to Nuget step?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it should not, because in that step we explicitly pass the requisite API token.

This pattern here is just telling actions/setup-dotnet to (more or less) run dotnet nuget update source ... for this source-url using the ambient NUGET_AUTH_TOKEN while setting up the SDK.

As an alternative to pre-configuring this source-url here, we could instead pass additional sources and tokens to dotnet restore, but that gets really messy really fast, so the usual pattern is to just pre-configure your authenticated NuGet sources as part of setting up the .NET SDK.

I get this question a lot in repos where I'm setting up GitHub Actions for the first time, so often find myself wishing they had instead implemented source-url as source-urls: [ ... ] which would let us be more expressive about NUGET_AUTH_TOKEN being for, and only for, one source-url, but as things stand repos that want to pre-wire two auth'd feeds just end up running this step twice, once for each source-url and NUGET_AUTH_TOKEN.

Here's a snippet from the CI logs that kind of allude to this^ story (albeit, not very clearly, but if you squint you can kind of picture what its doing):

image


- name: Install dependencies
if: ${{ steps.release.outputs.releases_created }}
run: dotnet restore
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/windows-ci.yml

This file was deleted.

39 changes: 36 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ Sample `.csproj` file:
<PropertyGroup>
<PackageId>OpenFeature.Contrib.MyComponent</PackageId>
<VersionNumber>0.0.1</VersionNumber> <!--x-release-please-version -->
<Version>$(VersionNumber)</Version>
<VersionPrefix>$(VersionNumber)</VersionPrefix>
<AssemblyVersion>$(VersionNumber)</AssemblyVersion>
<FileVersion>$(VersionNumber)</FileVersion>
<Description>A very valuable OpenFeature contribution!</Description>
<PackageProjectUrl>https://openfeature.dev</PackageProjectUrl>
<RepositoryUrl>https://github.com/open-feature/dotnet-sdk-contrib</RepositoryUrl>
<Authors>Me!</Authors>
</PropertyGroup>

Expand All @@ -60,3 +58,38 @@ This repo uses _Release Please_ to release packages. Release Please sets up a ru

Keep dependencies to a minimum.
Dependencies used only for building and testing should have a `<PrivateAssets>all</PrivateAssets>` element to prevent them from being exposed to consumers.

## Consuming pre-release packages

1. Acquire a [GitHub personal access token (PAT)](https://docs.github.com/github/authenticating-to-github/creating-a-personal-access-token) scoped for `read:packages` and verify the permissions:
```console
$ gh auth login --scopes read:packages

? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: ****-****
Press Enter to open github.com in your browser...

✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as ********
```

```console
$ gh auth status

github.com
✓ Logged in to github.com as ******** (~/.config/gh/hosts.yml)
✓ Git operations for github.com configured to use https protocol.
✓ Token: gho_************************************
✓ Token scopes: gist, read:org, read:packages, repo, workflow
```
2. Run the following command to configure your local environment to consume packages from GitHub Packages:
```console
$ dotnet nuget update source github-open-feature --username $(gh api user --jq .email) --password $(gh auth token) --store-password-in-clear-text

Package source "github-open-feature" was successfully updated.
```
15 changes: 5 additions & 10 deletions build/Common.prod.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
<Import Project=".\Common.props" />

<PropertyGroup>
<ContinuousIntegrationBuild Condition="'$(CI)' == 'true'">true</ContinuousIntegrationBuild>
<Deterministic Condition="'$(CI)' == 'true'">true</Deterministic>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackRelease>true</PackRelease>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462;net5.0;net6.0;net7.0</TargetFrameworks>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/open-feature/dotnet-sdk</RepositoryUrl>
<Description>OpenFeature is an open standard for feature flag management, created to support a robust feature flag ecosystem using cloud native technologies. OpenFeature will provide a unified API and SDK, and a developer-first, cloud-native implementation, with extensibility for open source and commercial offerings.</Description>
<RepositoryUrl>https://github.com/open-feature/dotnet-sdk-contrib</RepositoryUrl>
<Description>OpenFeature is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.</Description>
<PackageTags>Feature;OpenFeature;Flags;</PackageTags>
<PackageIcon>openfeature-icon.png</PackageIcon>
<PackageProjectUrl>https://openfeature.dev</PackageProjectUrl>
Expand All @@ -28,12 +31,4 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup Condition="'$(Deterministic)'=='true'">
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
</ItemGroup>

<PropertyGroup Condition="'$(Deterministic)'=='true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
</Project>
6 changes: 5 additions & 1 deletion build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
<!-- 0.5+ -->
<OpenFeatureVer>[1.2,)</OpenFeatureVer>
</PropertyGroup>
</Project>

<ItemGroup Condition="'$(OS)' == 'Unix'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions build/Common.tests.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVer)" />
<PackageReference Include="GitHubActionsTestLogger" Version="$(GitHubActionsTestLoggerVer)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPkgVer)" />
<PackageReference Include="NSubstitute" Version="$(NSubstituteVer)" />
<PackageReference Include="xunit" Version="$(XUnitPkgVer)" />
Expand All @@ -45,6 +46,7 @@
<AutoFixtureVer>[4.17.0]</AutoFixtureVer>
<CoverletCollectorVer>[3.1.2]</CoverletCollectorVer>
<FluentAssertionsVer>[6.7.0]</FluentAssertionsVer>
<GitHubActionsTestLoggerVer>[2.3.3]</GitHubActionsTestLoggerVer>
<MicrosoftNETTestSdkPkgVer>[17.3.2]</MicrosoftNETTestSdkPkgVer>
<NSubstituteVer>[5.0.0]</NSubstituteVer>
<XUnitRunnerVisualStudioPkgVer>[2.4.3,3.0)</XUnitRunnerVisualStudioPkgVer>
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"rollForward": "latestFeature",
"version": "8.0.100"
}
}
22 changes: 22 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>

<packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="github-open-feature" value="https://nuget.pkg.github.com/open-feature/index.json" />
</packageSources>

<packageSourceMapping>
<packageSource key="nuget">
<package pattern="OpenFeature" />
<package pattern="OpenFeature.*" />
<package pattern="*" />
</packageSource>
<packageSource key="github-open-feature">
<package pattern="OpenFeature" />
<package pattern="OpenFeature.*" />
</packageSource>
</packageSourceMapping>

</configuration>
Comment on lines +1 to +22
Copy link
Member Author

@austindrenski austindrenski Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Note: these instructions are also available in CONTRIBUTING.md

Following open-feature/dotnet-sdk#173, it is now possible for this repo to consume pre-release packages from open-feature/dotnet-sdk 🎉

This file provides dotnet restore with a mapping of where to look for packages. For example, if a project in this repo references a pre-release version of OpenFeature, dotnet restore will first look in the nuget source, and when the pre-release version is not found, it will proceed to checking in the github-open-feature source.

Currently, this repo does not yet reference any pre-release package versions, so there is no action required today for contributors.

However, contributors can prepare their local environments using the following instructions:

  1. Acquire a GitHub personal access token (PAT) scoped for read:packages and verify the permissions:

    $ gh auth login --scopes read:packages
    
    ? What account do you want to log into? GitHub.com
    ? What is your preferred protocol for Git operations? HTTPS
    ? How would you like to authenticate GitHub CLI? Login with a web browser
    
    ! First copy your one-time code: ****-****
    Press Enter to open github.com in your browser...
    
    ✓ Authentication complete.
    - gh config set -h github.com git_protocol https
    ✓ Configured git protocol
    ✓ Logged in as ********
    $ gh auth status
    
    github.com
      ✓ Logged in to github.com as ******** (~/.config/gh/hosts.yml)
      ✓ Git operations for github.com configured to use https protocol.
      ✓ Token: gho_************************************
      ✓ Token scopes: gist, read:org, read:packages, repo, workflow
  2. Run the following command to configure your local environment to consume packages from GitHub Packages:

    $ dotnet nuget update source github-open-feature --username $(gh api user --jq .email) --password $(gh auth token) --store-password-in-clear-text
    
    Package source "github-open-feature" was successfully updated.

Related

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<PropertyGroup>
<PackageId>OpenFeature.Contrib.Hooks.Otel</PackageId>
<VersionNumber>0.1.3</VersionNumber> <!--x-release-please-version -->
<Version>$(VersionNumber)</Version>
<VersionPrefix>$(VersionNumber)</VersionPrefix>
<AssemblyVersion>$(VersionNumber)</AssemblyVersion>
<FileVersion>$(VersionNumber)</FileVersion>
<Description>Open Telemetry Hook for .NET</Description>
<PackageProjectUrl>https://openfeature.dev</PackageProjectUrl>
<RepositoryUrl>https://github.com/open-feature/dotnet-sdk-contrib</RepositoryUrl>
<Authors>Florian Bacher</Authors>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>OpenFeature.Contrib.Providers.ConfigCat</PackageId>
<VersionNumber>0.0.2</VersionNumber> <!--x-release-please-version -->
<Version>$(VersionNumber)</Version>
<VersionPrefix>$(VersionNumber)</VersionPrefix>
<AssemblyVersion>$(VersionNumber)</AssemblyVersion>
<FileVersion>$(VersionNumber)</FileVersion>
<Description>ConfigCat provider for .NET</Description>
<PackageProjectUrl>https://openfeature.dev</PackageProjectUrl>
<RepositoryUrl>https://github.com/open-feature/dotnet-sdk-contrib</RepositoryUrl>
<Authors>Luiz Bon</Authors>
</PropertyGroup>
<ItemGroup>
Expand All @@ -20,4 +18,4 @@
<ItemGroup>
<PackageReference Include="ConfigCat.Client" Version="[9,)"/>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
<PropertyGroup>
<PackageId>OpenFeature.Contrib.Provider.FeatureManagement</PackageId>
<VersionNumber>0.0.1</VersionNumber>
<Version>$(VersionNumber)-preview</Version>
<VersionPrefix>$(VersionNumber)</VersionPrefix>
<VersionSuffix>preview</VersionSuffix>
Comment on lines +6 to +7
Copy link
Member Author

@austindrenski austindrenski Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B. <VersionSuffix> will still be overridden in CI builds to be, e.g., 0.0.1-ci.$(date -u +%Y%m%dT%H%M%S)+sha.${GITHUB_SHA:0:9} when --version-suffix ... is passed, but 0.0.1-preview when no --version-suffix ... is passed, as in the release.yml workflow.

<AssemblyVersion>$(VersionNumber)</AssemblyVersion>
<FileVersion>$(VersionNumber)</FileVersion>
<Description>An OpenFeature Provider built on top of the standard Microsoft FeatureManagement Library</Description>
<PackageProjectUrl>https://openfeature.dev</PackageProjectUrl>
<RepositoryUrl>https://github.com/open-feature/dotnet-sdk-contrib</RepositoryUrl>
<Authors>Eric Pattison</Authors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.FeatureManagement" Version="4.0.0-preview" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<PropertyGroup>
<PackageId>OpenFeature.Contrib.Providers.Flagd</PackageId>
<VersionNumber>0.1.7</VersionNumber> <!--x-release-please-version -->
<Version>$(VersionNumber)</Version>
<VersionPrefix>$(VersionNumber)</VersionPrefix>
<AssemblyVersion>$(VersionNumber)</AssemblyVersion>
<FileVersion>$(VersionNumber)</FileVersion>
<Description>flagd provider for .NET</Description>
<PackageProjectUrl>https://openfeature.dev</PackageProjectUrl>
<RepositoryUrl>https://github.com/open-feature/dotnet-sdk-contrib</RepositoryUrl>
<Authors>Todd Baert</Authors>
</PropertyGroup>

Expand Down
Loading