Skip to content

Commit

Permalink
Merge pull request #1 from RocketSurgeonsGuild/feature/readme
Browse files Browse the repository at this point in the history
Added support for generating parts of the readme to keep them in sync
  • Loading branch information
david-driscoll committed Jul 17, 2019
2 parents b18098c + 9231339 commit 43bd5bf
Show file tree
Hide file tree
Showing 24 changed files with 777 additions and 22 deletions.
6 changes: 5 additions & 1 deletion .build/.build.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../src/Nuke/build/Rocket.Surgery.Nuke.props" />

<PropertyGroup>
Expand All @@ -23,5 +23,9 @@
<None Remove="*.csproj.DotSettings;*.ref.*.txt" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

<Import Project="../src/Nuke/build/Rocket.Surgery.Nuke.targets" />
</Project>
4 changes: 2 additions & 2 deletions Nuke.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = ".build", ".build\.build.csp
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{E3DCB78E-EE06-4EA3-88AC-762D8910387C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Nuke", "src\Nuke\Rocket.Surgery.Nuke.csproj", "{C33C63CF-8760-4305-B9AC-14456930C867}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rocket.Surgery.Nuke", "src\Nuke\Rocket.Surgery.Nuke.csproj", "{C33C63CF-8760-4305-B9AC-14456930C867}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Nuke.Tests", "test\Nuke.Tests\Rocket.Surgery.Nuke.Tests.csproj", "{29950FB4-8A41-4C83-9FE0-FEA9C8D0BF67}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rocket.Surgery.Nuke.Tests", "test\Nuke.Tests\Rocket.Surgery.Nuke.Tests.csproj", "{29950FB4-8A41-4C83-9FE0-FEA9C8D0BF67}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 2 additions & 0 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<PackageReference Update="Rocket.Surgery.Nuke" Version="0.2.6" />
<PackageReference Update="GitVersion.CommandLine.DotNetCore" Version="5.0.0-beta5.11" />
<PackageReference Update="ReportGenerator" Version="4.2.9" />
<PackageReference Update="YamlDotNet" Version="6.1.1" />
<PackageReference Update="Buildalyzer" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Rocket.Surgery.Extensions.Testing" Version="1.1.11" />
Expand Down
70 changes: 62 additions & 8 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,65 @@
# Rocket Surgeons Guild Nuke
# Rocket Surgery - Nuke

| Build | Test | Release |
|---|---|---|
| |
| [![Nuke Pipelines Build Status](https://img.shields.io/vso/build/RocketSurgeonsGuild/Libraries/RSG.Nuke.svg?logo=visualstudiocode&style=flat-square)](https://rocketsurgeonsguild.visualstudio.com/Libraries/_build?definitionId=3) | |
| | | ![MyGet Pre Release](https://img.shields.io/myget/rocket-surgeons-guild/vpre/Nuke.svg?logo=nuget&style=flat-square&label=myget) |
Every good Rocket Surgeon needs multiple choices of build systems to pick from them for their best work. This is an integration for the `Nuke` build system with some defaults for all Rocket Surgeon Repositories (or if you follow the same structure, you can use it too!)

[![Nuke Pipelines Build History](https://buildstats.info/azurepipelines/chart/RocketSurgeonsGuild/Libraries/3)](https://rocketsurgeonsguild.visualstudio.com/Libraries/_build?definitionId=3)
<!-- badges -->
[![github-release-badge]][github-release]
[![github-license-badge]][github-license]
[![codecov-badge]][codecov]
[![codacy-badge]][codacy]
<!-- badges -->

## More info to come...
<!-- history badges -->
| Azure Pipelines | AppVeyor |
| --------------- | -------- |
| [![azurepipelines-badge]][azurepipelines] | [![appveyor-badge]][appveyor] |
| [![azurepipelines-history-badge]][azurepipelines-history] | [![appveyor-history-badge]][appveyor-history] |
<!-- history badges -->

<!-- nuget packages -->
| Package | NuGet | MyGet |
| ------- | ----- | ----- |
| Rocket.Surgery.Nuke | [![nuget-version-6plqb7nwtdoa-badge]![nuget-downloads-6plqb7nwtdoa-badge]][nuget-6plqb7nwtdoa] | [![myget-version-6plqb7nwtdoa-badge]![myget-downloads-6plqb7nwtdoa-badge]][myget-6plqb7nwtdoa] |
<!-- nuget packages -->

<!-- generated references -->
[github-release]: https://github.com/RocketSurgeonsGuild/Nuke/releases/latest
[github-release-badge]: https://img.shields.io/github/release/RocketSurgeonsGuild/Nuke.svg?logo=github&style=flat "Latest Release"
[github-license]: https://github.com/RocketSurgeonsGuild/Nuke/blob/master/LICENSE
[github-license-badge]: https://img.shields.io/github/license/RocketSurgeonsGuild/Nuke.svg?style=flat "License"
[codecov]: https://codecov.io/gh/RocketSurgeonsGuild/Nuke
[codecov-badge]: https://img.shields.io/codecov/c/github/RocketSurgeonsGuild/Nuke.svg?color=E03997&label=codecov&logo=codecov&logoColor=E03997&style=flat "Code Coverage"
[codacy]: https://www.codacy.com/app/RocketSurgeonsGuild/Nuke
[codacy-badge]: https://api.codacy.com/project/badge/Grade/d31c561959b34f35ae2d99979bfb239a "Codacy"
[azurepipelines]: https://rocketsurgeonsguild.visualstudio.com/Libraries/_build/latest?definitionId=31&branchName=master
[azurepipelines-badge]: https://img.shields.io/azure-devops/build/rocketsurgeonsguild/Libraries/31.svg?color=98C6FF&label=azure%20pipelines&logo=azuredevops&logoColor=98C6FF&style=flat "Azure Pipelines Status"
[azurepipelines-history]: https://rocketsurgeonsguild.visualstudio.com/Libraries/_build?definitionId=31&branchName=master
[azurepipelines-history-badge]: https://buildstats.info/azurepipelines/chart/rocketsurgeonsguild/Libraries/31?includeBuildsFromPullRequest=false "Azure Pipelines History"
[appveyor]: https://ci.appveyor.com/project/RocketSurgeonsGuild/Nuke
[appveyor-badge]: https://img.shields.io/appveyor/ci/RocketSurgeonsGuild/Nuke.svg?color=00b3e0&label=appveyor&logo=appveyor&logoColor=00b3e0&style=flat "AppVeyor Status"
[appveyor-history]: https://ci.appveyor.com/project/RocketSurgeonsGuild/Nuke/history
[appveyor-history-badge]: https://buildstats.info/appveyor/chart/RocketSurgeonsGuild/Nuke?includeBuildsFromPullRequest=false "AppVeyor History"
[nuget-6plqb7nwtdoa]: https://www.nuget.org/packages/Rocket.Surgery.Nuke/
[nuget-version-6plqb7nwtdoa-badge]: https://img.shields.io/nuget/v/Rocket.Surgery.Nuke.svg?color=004880&logo=nuget&style=flat-square "NuGet Version"
[nuget-downloads-6plqb7nwtdoa-badge]: https://img.shields.io/nuget/dt/Rocket.Surgery.Nuke.svg?color=004880&logo=nuget&style=flat-square "NuGet Downloads"
[myget-6plqb7nwtdoa]: https://www.myget.org/feed/rocket-surgeons-guild/package/nuget/Rocket.Surgery.Nuke
[myget-version-6plqb7nwtdoa-badge]: https://img.shields.io/myget/rocket-surgeons-guild/vpre/Rocket.Surgery.Nuke.svg?label=myget&color=004880&logo=nuget&style=flat-square "MyGet Pre-Release Version"
[myget-downloads-6plqb7nwtdoa-badge]: https://img.shields.io/myget/rocket-surgeons-guild/dt/Rocket.Surgery.Nuke.svg?color=004880&logo=nuget&style=flat-square "MyGet Downloads"
<!-- generated references -->

<!-- nuke-data
github:
owner: RocketSurgeonsGuild
repository: Nuke
azurepipelines:
account: rocketsurgeonsguild
teamproject: Libraries
builddefinition: 31
appveyor:
account: RocketSurgeonsGuild
build: Nuke
myget:
account: rocket-surgeons-guild
codacy:
project: d31c561959b34f35ae2d99979bfb239a
-->
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variables:
- name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
value: "true"
- name: CodeCovToken
value: '7dfeb756-b27e-47ec-8906-a349cf7e0688'
value: 'c93f6719-da50-4d00-ba2b-b73fd95239e0'

jobs:
- template: pipeline/nuke.yml@rsg
Expand Down
31 changes: 31 additions & 0 deletions src/Nuke/Readme/AppVeyorHistory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Dynamic;

namespace Rocket.Surgery.Nuke.Readme
{
class AppVeyorHistory : IHistorySection
{
public string Name { get; } = "AppVeyor";

public string ConfigKey { get; } = "appveyor";

public (string badge, string history) Process(IDictionary<object, object> config, IMarkdownReferences references,
RocketBoosterBuild build)
{
var url = references.AddReference("appveyor", $"https://ci.appveyor.com/project/{config["account"]}/{config["build"]}");
var badge = references.AddReference(
"appveyor-badge",
$"https://img.shields.io/appveyor/ci/{config["account"]}/{config["build"]}.svg?color=00b3e0&label=appveyor&logo=appveyor&logoColor=00b3e0&style=flat",
"AppVeyor Status"
);
var historyUrl = references.AddReference("appveyor-history", $"https://ci.appveyor.com/project/{config["account"]}/{config["build"]}/history");
var historyBadge = references.AddReference(
"appveyor-history-badge",
$"https://buildstats.info/appveyor/chart/{config["account"]}/{config["build"]}?includeBuildsFromPullRequest=false",
"AppVeyor History"
);

return ($"[!{badge}]{url}", $"[!{historyBadge}]{historyUrl}");
}
}
}
31 changes: 31 additions & 0 deletions src/Nuke/Readme/AzurePipelinesHistory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Dynamic;

namespace Rocket.Surgery.Nuke.Readme
{
class AzurePipelinesHistory : IHistorySection
{
public string Name { get; } = "Azure Pipelines";

public string ConfigKey { get; } = "azurepipelines";

public (string badge, string history) Process(IDictionary<object, object> config, IMarkdownReferences references,
RocketBoosterBuild build)
{
var url = references.AddReference("azurepipelines", $"https://{config["account"]}.visualstudio.com/{config["teamproject"]}/_build/latest?definitionId={config["builddefinition"]}&branchName=master");
var badge = references.AddReference(
"azurepipelines-badge",
$"https://img.shields.io/azure-devops/build/{config["account"]}/{config["teamproject"]}/{config["builddefinition"]}.svg?color=98C6FF&label=azure%20pipelines&logo=azuredevops&logoColor=98C6FF&style=flat",
"Azure Pipelines Status"
);
var historyUrl = references.AddReference("azurepipelines-history", $"https://{config["account"]}.visualstudio.com/{config["teamproject"]}/_build?definitionId={config["builddefinition"]}&branchName=master");
var historyBadge = references.AddReference(
"azurepipelines-history-badge",
$"https://buildstats.info/azurepipelines/chart/{config["account"]}/{config["teamproject"]}/{config["builddefinition"]}?includeBuildsFromPullRequest=false",
"Azure Pipelines History"
);

return ($"[!{badge}]{url}", $"[!{historyBadge}]{historyUrl}");
}
}
}
55 changes: 55 additions & 0 deletions src/Nuke/Readme/Badges.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Text;
using Nuke.Common.Utilities.Collections;

namespace Rocket.Surgery.Nuke.Readme
{
/// <summary>
/// A container for badges that you want to show on the readme
/// </summary>
public class Badges : IReadmeSection
{
private readonly List<IBadgeSection> _sections = new List<IBadgeSection>();

/// <summary>
/// Adds a new Badge section
/// </summary>
/// <param name="section"></param>
/// <returns></returns>
public Badges Add(IBadgeSection section)
{
_sections.Add(section);
return this;
}

/// <inheritdoc />
public string Name => "badges";

/// <inheritdoc />
public string ConfigKey => string.Empty;

/// <inheritdoc />
public string Process(IDictionary<string, object> config, IMarkdownReferences references, RocketBoosterBuild build)
{
var sb = new StringBuilder();
foreach (var section in _sections)
{
var subConfig = string.IsNullOrEmpty(section.ConfigKey) ? config.ToDictionary(x => (object)x.Key, x => x.Value) : config.TryGetValue(section.ConfigKey, out var o) ? o as IDictionary<object, object> : null;
// Assume if not configured, it will never be able to be rendered
if (subConfig is null)
{
continue;
}
var result = section.Process(subConfig, references, build);
if (string.IsNullOrWhiteSpace(result))
{
continue;
}
sb.AppendLine(result);
}

return sb.ToString();
}
}
}
26 changes: 26 additions & 0 deletions src/Nuke/Readme/CodacySection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Dynamic;

namespace Rocket.Surgery.Nuke.Readme
{
class CodacySection : IBadgeSection
{
public string Name => "Codacy";

public string ConfigKey => string.Empty;

public string Process(IDictionary<object, object> config, IMarkdownReferences references, RocketBoosterBuild build)
{
if (!(config.TryGetValue("github", out var githubObj) && config.TryGetValue("codacy", out var codacyObj)))
{
return string.Empty;
}

var github = (IDictionary<object, object>)githubObj;
var codacy = (IDictionary<object, object>)codacyObj;
var url = references.AddReference("codacy", $"https://www.codacy.com/app/{github["owner"]}/{github["repository"]}");
var badge = references.AddReference("codacy-badge", $"https://api.codacy.com/project/badge/Grade/{codacy["project"]}", "Codacy");
return $"[!{badge}]{url}";
}
}
}
19 changes: 19 additions & 0 deletions src/Nuke/Readme/CodecovSection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Dynamic;

namespace Rocket.Surgery.Nuke.Readme
{
class CodecovSection : IBadgeSection
{
public string Name => "Codecov";

public string ConfigKey => "github";

public string Process(IDictionary<object, object> config, IMarkdownReferences references, RocketBoosterBuild build)
{
var url = references.AddReference("codecov", $"https://codecov.io/gh/{config["owner"]}/{config["repository"]}");
var badge = references.AddReference("codecov-badge", $"https://img.shields.io/codecov/c/github/{config["owner"]}/{config["repository"]}.svg?color=E03997&label=codecov&logo=codecov&logoColor=E03997&style=flat", "Code Coverage");
return $"[!{badge}]{url}";
}
}
}
19 changes: 19 additions & 0 deletions src/Nuke/Readme/GithubLicenseSection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Dynamic;

namespace Rocket.Surgery.Nuke.Readme
{
class GithubLicenseSection : IBadgeSection
{
public string Name => "Github Release";

public string ConfigKey => "github";

public string Process(IDictionary<object, object> config, IMarkdownReferences references, RocketBoosterBuild build)
{
var url = references.AddReference("github-license", $"https://github.com/{config["owner"]}/{config["repository"]}/blob/master/LICENSE");
var badge = references.AddReference("github-license-badge", $"https://img.shields.io/github/license/{config["owner"]}/{config["repository"]}.svg?style=flat", "License");
return $"[!{badge}]{url}";
}
}
}
19 changes: 19 additions & 0 deletions src/Nuke/Readme/GithubReleaseSection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Dynamic;

namespace Rocket.Surgery.Nuke.Readme
{
class GithubReleaseSection : IBadgeSection
{
public string Name => "Github Release";

public string ConfigKey => "github";

public string Process(IDictionary<object, object> config, IMarkdownReferences references, RocketBoosterBuild build)
{
var url = references.AddReference("github-release", $"https://github.com/{config["owner"]}/{config["repository"]}/releases/latest");
var badge = references.AddReference("github-release-badge", $"https://img.shields.io/github/release/{config["owner"]}/{config["repository"]}.svg?logo=github&style=flat", "Latest Release");
return $"[!{badge}]{url}";
}
}
}
57 changes: 57 additions & 0 deletions src/Nuke/Readme/Histories.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using JetBrains.Annotations;

namespace Rocket.Surgery.Nuke.Readme
{
/// <summary>
/// A container for build histories that you want to show on the readme
/// </summary>
[PublicAPI]
public class Histories : IReadmeSection
{
private readonly List<IHistorySection> _sections = new List<IHistorySection>();

/// <summary>
/// Adds a new history section
/// </summary>
/// <param name="section"></param>
/// <returns></returns>
public Histories Add(IHistorySection section)
{
_sections.Add(section);
return this;
}

/// <inheritdoc />
public string Name => "history badges";

/// <inheritdoc />
public string ConfigKey => string.Empty;

/// <inheritdoc />
public string Process(IDictionary<string, object> config, IMarkdownReferences references, RocketBoosterBuild build)
{
var results = new List<(string name, string badge, string history)>();
foreach (var section in _sections)
{
var subConfig = string.IsNullOrEmpty(section.ConfigKey) ? config.ToDictionary(x => (object)x.Key, x => x.Value) : config.TryGetValue(section.ConfigKey, out var o) ? o as IDictionary<object, object> : null;
// Assume if not configured, it will never be able to be rendered
if (subConfig is null)
{
continue;
}
var (badge, history) = section.Process(subConfig, references, build);
results.Add((section.Name, badge, history));
}
var sb = new StringBuilder();
sb.AppendLine($"| {string.Join(" | ", results.Select(z => z.name))} |");
sb.AppendLine($"| {string.Join(" | ", results.Select(z => string.Join("", Enumerable.Range(0, z.name.Length).Select(x => "-"))))} |");
sb.AppendLine($"| {string.Join(" | ", results.Select(z => z.badge))} |");
sb.AppendLine($"| {string.Join(" | ", results.Select(z => z.history))} |");
return sb.ToString();
}
}
}

0 comments on commit 43bd5bf

Please sign in to comment.