Skip to content

Commit 1c0c42e

Browse files
authored
Add support for appending health check metadata to gauge results (#2)
* build: Add tooling for code quality * build: Update build tool * test: Update test class Bumped target framework to .NET 8, updated dependencies and added analyzers * test(sample): Update the SampleApi project to latest dependencies and .NET 8 * chore: Apply dotnet format to solution * build: Refactor build tool application host Also, add new build target to launch code coverage reports in browser. * build: Refactor git hooks Also minor edits to github pipelines and build tool comments * feat(metrics): Add support for appending health check metadata to guage results Add XmlDoc to public classes and some additional build properties to help with CI. Reduce the version on the dependency to allow greater compatibility with older .NET 6 projects. +semver: minor * chore(sample): Update sample project to be more descriptive
1 parent 09eac87 commit 1c0c42e

36 files changed

+1115
-240
lines changed

.config/dotnet-tools.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
"version": 1,
33
"isRoot": true,
44
"tools": {
5+
"gitversion.tool": {
6+
"version": "5.12.0",
7+
"commands": [
8+
"dotnet-gitversion"
9+
]
10+
},
511
"dotnet-reportgenerator-globaltool": {
6-
"version": "5.1.25",
12+
"version": "5.2.4",
713
"commands": [
814
"reportgenerator"
915
]
1016
},
11-
"gitversion.tool": {
12-
"version": "5.12.0",
17+
"husky": {
18+
"version": "0.6.4",
1319
"commands": [
14-
"dotnet-gitversion"
20+
"husky"
1521
]
1622
}
1723
}

.editorconfig

Lines changed: 415 additions & 0 deletions
Large diffs are not rendered by default.

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sh text eol=lf

.github/workflows/nightly-build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
fetch-depth: 0
4848
ref: dev
4949

50-
- uses: actions/setup-dotnet@v3
50+
- uses: actions/setup-dotnet@v4
5151
with:
52-
dotnet-version: '7.x'
52+
dotnet-version: '8.x'
5353

5454
- name: Build solution
5555
run: dotnet run --project build/build.csproj --configuration Release -- targets pack

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ bld/
3636
.vs/
3737
# Uncomment if you have tasks that create the project's static files in wwwroot
3838
#wwwroot/
39-
.artifacts/
4039

4140
# Visual Studio 2017 auto generated files
4241
Generated\ Files/
@@ -397,3 +396,6 @@ FodyWeavers.xsd
397396

398397
# JetBrains Rider
399398
*.sln.iml
399+
400+
# Include Husky.Net scripts
401+
!.husky/csx

.husky/commit-msg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
# $1 = temp file containing commit message
5+
dotnet husky run --group "commit-msg" --args "$1"

.husky/csx/append-issue-id.csx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#r "System.Linq"
2+
#r "System.Text.RegularExpressions"
3+
#load "common.csx"
4+
5+
using System;
6+
using System.ComponentModel;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Text.RegularExpressions;
10+
using static Constants;
11+
using static Utilities;
12+
13+
private static void Log(string message)
14+
{
15+
Console.WriteLine($"[append-issue-id] {message}");
16+
}
17+
18+
var branchName = Args[0];
19+
var branchMatch = Regex.Match(branchName, RegexPatterns.BranchName, RegexOptions.IgnoreCase);
20+
var issue = branchMatch.Groups["issue"];
21+
var commitMessage = File.ReadAllText(Args[1]);
22+
commitMessage = NormalizeNewlineFeeds(commitMessage);
23+
var commitMatch = Regex.Match(commitMessage, RegexPatterns.CommitMessage, RegexOptions.Multiline);
24+
var footers = commitMatch.Groups["footers"];
25+
26+
// skip if no issue ID detected
27+
if (!issue.Success || issue.Value.Equals("no-ref"))
28+
{
29+
Log($"{UnicodeEmojis.Information} No issue ID detected in branch name.");
30+
return 0;
31+
}
32+
33+
// does the commit message have a footer
34+
if (footers.Success)
35+
{
36+
// does the footer already contain a reference to the issue
37+
if (footers.Value.Contains(issue.Value))
38+
{
39+
Log($"{UnicodeEmojis.Information} Issue #{issue.Value} detected in commit message.");
40+
return 0;
41+
}
42+
43+
File.AppendAllText(Args[1], Environment.NewLine + $"Refs: #{issue.Value}");
44+
}
45+
else
46+
{
47+
File.AppendAllText(Args[1], Environment.NewLine + Environment.NewLine + $"Refs: #{issue.Value}");
48+
}
49+
50+
Log($"{UnicodeEmojis.Success} Appended reference for issue #{issue.Value} to commit message!");
51+
return 0;

.husky/csx/common.csx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#r "System.Text.RegularExpressions"
2+
3+
using System.Text.RegularExpressions;
4+
5+
public static class Constants
6+
{
7+
public static class RegexPatterns
8+
{
9+
// ref: https://regex101.com/r/ZgMPsl/2
10+
// language=regex
11+
public static readonly string CommitMessage = @"\A(?:(?<type>[^\(!:]+)(?:\((?<scope>[^\)]+)\))?(?<breaking>!)?: (?<description>.+))(?:(?!(?:\n{2}^(?:BREAKING[ -]CHANGE|[a-zA-Z0-9_\-]+)(?:: | #\b)[^\n:]+(\n*\b)?)+)\n{2}(?<body>(?:(?!\n{2}(?:^(?:BREAKING[ -]CHANGE|[a-zA-Z0-9_\-]+)(?:: | #\b)[^\n:]+(\n*\b)?)+).|\n+?)+?))?(?:\n{2}(?<footers>(?:^(?:BREAKING[ -]CHANGE|[a-zA-Z0-9_\-]+)(?:: | #\b)[^\n:]+(\n*\b)?)+))?(?:\n*)\Z";
12+
13+
// ref: https://regex101.com/r/Y34fz1/4
14+
// language=regex
15+
public static readonly string BranchName = @"^(?:(?<type>main|dev(?:elop)?)|(?<type>release)\/(?<version>[0-9]+(?:\.[0-9]+){2}(?:-[a-zA-Z0-9]+)?)|(?<type>wip)\/(?<desc>[a-zA-Z0-9]+(?:[-][a-zA-Z0-9]+)*)|(?<type>feature|(?:bug|hot)fix)\/(?<issue>[0-9]+|no-ref){1}\/(?<desc>[a-zA-Z0-9]+(?:[-][a-zA-Z0-9]+)*))$";
16+
}
17+
18+
public static class UnicodeEmojis
19+
{
20+
public static readonly string Success = "\u2714"; // check_mark = ✔
21+
public static readonly string Failure = "\u274c"; // cross_mark = ❌
22+
public static readonly string Information = "\u2139"; // information = ℹ
23+
public static readonly string Warning = "\u26a0"; // warning = ⚠
24+
}
25+
}
26+
27+
public static class Utilities
28+
{
29+
public static string NormalizeNewlineFeeds(string message)
30+
{
31+
return Regex.Replace(message, @"\r\n|\r|\n", "\n");
32+
}
33+
}

.husky/csx/lint-branch-name.csx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#r "System.Linq"
2+
#r "System.Text.RegularExpressions"
3+
#load "common.csx"
4+
5+
using System.ComponentModel;
6+
using System.Linq;
7+
using System.Text.RegularExpressions;
8+
using static Constants;
9+
10+
private static void Log(string message)
11+
{
12+
Console.WriteLine($"[lint-branch-name] {message}");
13+
}
14+
15+
var branchName = Args[0];
16+
var match = Regex.Match(branchName, RegexPatterns.BranchName, RegexOptions.IgnoreCase);
17+
18+
if (!match.Success)
19+
{
20+
Log($"{UnicodeEmojis.Failure} branch name is invalid!");
21+
Log("Please review the docs for more information about the branch naming conventions.");
22+
return 1;
23+
}
24+
25+
switch (match.Groups["type"].Value)
26+
{
27+
case "feature":
28+
case "bugfix":
29+
case "hotfix":
30+
case "wip":
31+
if (match.Groups["desc"].Value.Length < 4)
32+
{
33+
Log($"{UnicodeEmojis.Failure} branch name is invalid!");
34+
Log("The 'description' segment of the branch name must be at least 4 characters long.");
35+
Log("Please review the docs for more information about the branch naming conventions.");
36+
return 1;
37+
}
38+
break;
39+
}
40+
41+
Log($"{UnicodeEmojis.Success} branch name is valid!");
42+
return 0;

.husky/csx/lint-commit-msg.csx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#r "System.Text.RegularExpressions"
2+
#load "common.csx"
3+
4+
using System.Text.RegularExpressions;
5+
using static Constants;
6+
using static Utilities;
7+
8+
private static void Log(string message)
9+
{
10+
Console.WriteLine($"[lint-commit-msg] {message}");
11+
}
12+
13+
var commitMessage = File.ReadAllText(Args[0]);
14+
commitMessage = NormalizeNewlineFeeds(commitMessage);
15+
16+
if (Regex.IsMatch(commitMessage, RegexPatterns.CommitMessage, RegexOptions.Multiline))
17+
{
18+
Log($"{UnicodeEmojis.Success} commit message format is valid!");
19+
return 0;
20+
}
21+
22+
Log($"{UnicodeEmojis.Failure} commit message format is invalid!");
23+
Log("e.g: 'feat(scope): subject' or 'fix: subject'");
24+
Log("more info: https://www.conventionalcommits.org/en/v1.0.0/");
25+
26+
return 1;

0 commit comments

Comments
 (0)