Skip to content

A C#/.NET port of the gh-badges library powering shields.io

License

Notifications You must be signed in to change notification settings

ap0llo/gh-badges-sharp

Repository files navigation

gh-badges-sharp

A C#/.NET port of the gh-badges library that powers shields.io

Overview

Build Status Conventional Commits Renovate

NuGet MyGet

GhBadgesSharp is a C#/.NET port of the gh-badges library that powers shields.io.

See Acknowledgments for license info.

Installation

GhBadgesSharp is distributed as NuGet package.

  • Prerelease and stable builds are available on MyGet
  • Stable builds are also available on NuGet.org

Usage

After installation, a badge can be rendered by calling Badge.MakeBadge. It will return the badge as an SVG image (as XElement).

The following code shows how to render this badge:

Example Badge

using System.IO;
using System.Xml.Linq;
using Grynwald.GhBadgesSharp;

public class Program
{
    public static void Main(string[] args)
    {
        XElement badge = Badge.MakeBadge(
            style: BadgeStyle.Flat,
            leftText: "Hello",
            rightText: "World",
            color: NamedColor.Green
        );

        File.WriteAllText("badge.svg", badge.ToString());
    }
}

Building from source

Note: This repository uses git submodules, clone using git clone --recursive

Building GhBadgesSharp from source requires the .NET 6 SDK (version 6.0.101 as specified in global.json) and uses Cake for the build.

To execute the default task, run

.\build.ps1

This will build the project, run all tests and pack the NuGet package.

Acknowledgments

This library is a C# port of the gh-badges library.

Libraries used (aside from .NET Core and .NET Standard):

Versioning and Branching

The version of this project is automatically derived from git and the information in version.json using Nerdbank.GitVersioning:

  • The master branch always contains the latest version. Packages produced from master are always marked as pre-release versions (using the -pre suffix).
  • Stable versions are built from release branches. Build from release branches will have no -pre suffix
  • Builds from any other branch will have both the -pre prerelease tag and the git commit hash included in the version string

To create a new release branch use the nbgv tool:

dotnet tool restore
dotnet tool run nbgv -- prepare-release