Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 1935f4a

Browse files
Merge pull request #28 from thefringeninja/rtfm
Generate Documentation in Build
2 parents 75c0e71 + ef2a1ed commit 1935f4a

27 files changed

+159
-92
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ ARG TRAVIS_COMMIT
55
ARG TRAVIS_PULL_REQUEST
66
ARG TRAVIS_BRANCH
77
ARG MYGET_API_KEY
8+
9+
RUN apk add nodejs yarn --no-cache
10+
811
WORKDIR /src
912

1013
COPY ./src/*.sln ./
@@ -17,6 +20,10 @@ RUN dotnet restore --runtime=alpine.3.7-x64
1720

1821
COPY ./src .
1922

23+
WORKDIR /docs
24+
25+
COPY ./docs/package.json ./docs/yarn.lock ./
26+
2027
WORKDIR /build
2128

2229
COPY ./build/build.csproj .

build/Program.cs

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using System.Threading.Tasks;
36
using static Bullseye.Targets;
47
using static SimpleExec.Command;
58

@@ -8,6 +11,7 @@ static class Program
811
private const string ArtifactsDir = "artifacts";
912

1013
private const string Clean = nameof(Clean);
14+
private const string GenerateDocumentation = nameof(GenerateDocumentation);
1115
private const string Build = nameof(Build);
1216
private const string RunTests = nameof(RunTests);
1317
private const string Pack = nameof(Pack);
@@ -30,38 +34,73 @@ public static void Main(string[] args)
3034
});
3135

3236
Target(
33-
Build,
37+
GenerateDocumentation,
38+
() =>
39+
{
40+
var srcDirectory = new DirectoryInfo("./src");
41+
42+
var schemaFiles = srcDirectory.GetFiles("*.schema.json", SearchOption.AllDirectories);
43+
44+
var schemaDirectories = schemaFiles
45+
.Select(schemaFile => schemaFile.DirectoryName)
46+
.Distinct()
47+
.Select(schemaDirectory =>
48+
schemaDirectory.Replace(Path.DirectorySeparatorChar,
49+
'/')); // normalize paths; yarn/node can handle forward slashes
50+
51+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
52+
{
53+
Run("cmd", "/c yarn", "docs");
54+
}
55+
else
56+
{
57+
Run("yarn", string.Empty, "docs");
58+
}
59+
60+
foreach (var schemaDirectory in schemaDirectories)
61+
{
62+
Run(
63+
"node",
64+
$"node_modules/@adobe/jsonschema2md/cli.js -n --input {schemaDirectory} --out {schemaDirectory} --schema-out=-",
65+
"docs");
66+
}
67+
});
68+
69+
Target(
70+
Build,
71+
DependsOn(GenerateDocumentation),
3472
() => Run(
35-
"dotnet",
73+
"dotnet",
3674
$"build src/SqlStreamStore.HAL.sln -c Release /p:BuildMetadata={buildMetadata}"));
3775

3876
Target(
3977
RunTests,
4078
DependsOn(Build),
4179
() => Run(
4280
"dotnet",
43-
$"test src/SqlStreamStore.HAL.Tests -c Release -r ../../{ArtifactsDir} --no-build -l trx;LogFileName=SqlStreamStore.HAL.Tests.xml"));
81+
$"test src/SqlStreamStore.HAL.Tests -c Release -r ../../{ArtifactsDir} --verbosity normal --no-build -l trx;LogFileName=SqlStreamStore.HAL.Tests.xml"));
4482

4583
Target(
4684
Pack,
47-
DependsOn(Build),
85+
DependsOn(Build),
4886
() => Run(
4987
"dotnet",
5088
$"pack src/SqlStreamStore.HAL -c Release -o ../../{ArtifactsDir} --no-build"));
5189

5290
Target(
53-
Publish,
54-
DependsOn(Pack),
55-
() => {
91+
Publish,
92+
DependsOn(Pack),
93+
() =>
94+
{
5695
var packagesToPush = Directory.GetFiles(ArtifactsDir, "*.nupkg", SearchOption.TopDirectoryOnly);
5796
Console.WriteLine($"Found packages to publish: {string.Join("; ", packagesToPush)}");
58-
97+
5998
if (string.IsNullOrWhiteSpace(apiKey))
6099
{
61100
Console.WriteLine("MyGet API key not available. Packages will not be pushed.");
62101
return;
63102
}
64-
103+
65104
foreach (var packageToPush in packagesToPush)
66105
{
67106
Run(
@@ -77,15 +116,15 @@ public static void Main(string[] args)
77116

78117
private static string GetBranch()
79118
=> (Environment.GetEnvironmentVariable("TRAVIS_PULL_REQUEST")?.ToLower() == "false"
80-
? null
81-
: $"pr-{Environment.GetEnvironmentVariable("TRAVIS_PULL_REQUEST")}")
82-
?? Environment.GetEnvironmentVariable("TRAVIS_BRANCH")
83-
?? "none";
119+
? null
120+
: $"pr-{Environment.GetEnvironmentVariable("TRAVIS_PULL_REQUEST")}")
121+
?? Environment.GetEnvironmentVariable("TRAVIS_BRANCH")
122+
?? "none";
84123

85-
private static string GetCommitHash()
124+
private static string GetCommitHash()
86125
=> Environment.GetEnvironmentVariable("TRAVIS_PULL_REQUEST_SHA")
87-
?? Environment.GetEnvironmentVariable("TRAVIS_COMMIT")
88-
?? "none";
126+
?? Environment.GetEnvironmentVariable("TRAVIS_COMMIT")
127+
?? "none";
89128

90129
private static string GetBuildNumber()
91130
=> (Environment.GetEnvironmentVariable("TRAVIS_BUILD_NUMBER") ?? "0").PadLeft(5, '0');

docs/docs.csproj

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/SqlStreamStore.HAL.DevServer/WebHostBuilderExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ internal static class WebHostBuilderExtensions
77
{
88
public static IWebHostBuilder UseStartup(this IWebHostBuilder builder, IStartup startup)
99
=> builder
10-
.ConfigureServices(services => services.AddSingleton(startup))
11-
.UseSetting(WebHostDefaults.ApplicationKey, startup.GetType().AssemblyQualifiedName);
10+
.ConfigureServices(services => services.AddSingleton(startup));
1211
}
1312
}

src/SqlStreamStore.HAL.Tests/AllStreamMessageTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace SqlStreamStore.HAL.Tests
33
using System;
44
using System.Net;
55
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Http;
67
using Shouldly;
78
using Xunit;
89

@@ -31,7 +32,7 @@ public async Task read_single_message_all_stream()
3132

3233
resource.ShouldLink(
3334
Links
34-
.RootedAt("../")
35+
.FromRequestMessage(response.RequestMessage)
3536
.Find()
3637
.Index()
3738
.AddSelf(Constants.Relations.Message, "stream/0")
@@ -49,7 +50,7 @@ public async Task read_single_message_does_not_exist_all_stream()
4950
var resource = await response.AsHal();
5051

5152
resource.ShouldLink(Links
52-
.RootedAt("../")
53+
.FromPath(new PathString("/stream/0"))
5354
.AddSelf(Constants.Relations.Message, "stream/0")
5455
.Add(Constants.Relations.Feed, HeadOfAll));
5556
}

src/SqlStreamStore.HAL.Tests/StreamMessageTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task read_single_message_stream()
3131
var resource = await response.AsHal();
3232
3333
resource.ShouldLink(Links
34-
.RootedAt("../../")
34+
.FromRequestMessage(response.RequestMessage)
3535
.Index()
3636
.Find()
3737
.Add(Constants.Relations.Self, "streams/a-stream/0")
@@ -54,7 +54,7 @@ public async Task read_single_message_does_not_exist_stream()
5454
var resource = await response.AsHal();
5555

5656
resource.ShouldLink(Links
57-
.RootedAt("../../")
57+
.FromRequestMessage(response.RequestMessage)
5858
.Index()
5959
.Find()
6060
.Add(Constants.Relations.Self, "streams/a-stream/0")

src/SqlStreamStore.HAL.Tests/StreamMetadataTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ await _fixture.HttpClient.SendAsync(
4242

4343
resource.ShouldLink(
4444
Links
45-
.RootedAt("../../../")
45+
.FromRequestMessage(response.RequestMessage)
4646
.Index()
4747
.Find()
4848
.Add(Constants.Relations.Metadata, $"streams/{StreamId}/metadata").Self()
@@ -93,7 +93,7 @@ await _fixture.HttpClient.SendAsync(
9393

9494
resource.ShouldLink(
9595
Links
96-
.RootedAt("../../../")
96+
.FromRequestMessage(response.RequestMessage)
9797
.Index()
9898
.Find()
9999
.Add(Constants.Relations.Metadata, $"streams/{StreamId}/metadata").Self()
@@ -139,7 +139,7 @@ public async Task set_metadata()
139139

140140
resource.ShouldLink(
141141
Links
142-
.RootedAt("../../../")
142+
.FromRequestMessage(response.RequestMessage)
143143
.Index()
144144
.Find()
145145
.Add(Constants.Relations.Metadata, $"streams/{StreamId}/metadata").Self()

src/SqlStreamStore.HAL.Tests/StreamNavigationTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task read_head_link_no_messages(string path, string root, HttpStatu
4646
var resource = await response.AsHal();
4747

4848
var links = Links
49-
.RootedAt(root)
49+
.FromRequestMessage(response.RequestMessage)
5050
.Index()
5151
.Find()
5252
.Add(Constants.Relations.Self, $"{path}?{LastLinkQuery}")
@@ -85,7 +85,7 @@ public async Task read_head_link_when_multiple_pages(string path, string root)
8585
var resource = await response.AsHal();
8686

8787
var links = Links
88-
.RootedAt(root)
88+
.FromRequestMessage(response.RequestMessage)
8989
.Index()
9090
.Find()
9191
.Add(Constants.Relations.Self, $"{path}?{LastLinkQuery}")
@@ -118,7 +118,8 @@ public async Task read_first_link(string path, string root)
118118

119119
var resource = await response.AsHal();
120120

121-
var links = Links.RootedAt(root)
121+
var links = Links
122+
.FromRequestMessage(response.RequestMessage)
122123
.Index()
123124
.Find()
124125
.Add(Constants.Relations.Self, $"{path}?{FirstLinkQuery}")
@@ -146,7 +147,8 @@ public async Task read_first_link_when_multiple_pages(string path, string root)
146147

147148
var resource = await response.AsHal();
148149

149-
var links = Links.RootedAt(root)
150+
var links = Links
151+
.FromRequestMessage(response.RequestMessage)
150152
.Index()
151153
.Find()
152154
.Add(Constants.Relations.Self, $"{path}?{FirstLinkQuery}")

src/SqlStreamStore.HAL/AllStream/AllStreamResource.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task<Response> Get(
5454
})
5555
.AddLinks(
5656
Links
57-
.RootedAt(string.Empty)
57+
.FromOperation(operation)
5858
.Index()
5959
.Find()
6060
.AllStreamNavigation(page, operation))
@@ -74,7 +74,8 @@ public async Task<Response> Get(
7474
metadata = message.JsonMetadata
7575
})
7676
.AddLinks(
77-
Links.RootedAt(string.Empty)
77+
Links
78+
.FromOperation(operation)
7879
.Add(
7980
Constants.Relations.Message,
8081
$"streams/{message.StreamId}/{message.StreamVersion}")

src/SqlStreamStore.HAL/AllStream/ReadAllStreamOperation.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ internal class ReadAllStreamOperation : IStreamStoreOperation<ReadAllPage>
1212

1313
public ReadAllStreamOperation(HttpRequest request)
1414
{
15+
Path = request.Path;
16+
1517
EmbedPayload = request.Query.TryGetValueCaseInsensitive('e', out var embedPayload)
1618
&& embedPayload == "1";
1719

@@ -62,6 +64,7 @@ public ReadAllStreamOperation(HttpRequest request)
6264
public int ReadDirection { get; }
6365
public string Self { get; }
6466
public bool IsUriCanonical { get; }
67+
public PathString Path { get; }
6568

6669
public Task<ReadAllPage> Invoke(IStreamStore streamStore, CancellationToken ct)
6770
=> ReadDirection == Constants.ReadDirection.Forwards

src/SqlStreamStore.HAL/AllStreamMessage/AllStreamMessageResource.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public async Task<Response> Get(
2525
{
2626
var message = await operation.Invoke(_streamStore, cancellationToken);
2727

28-
var links = Links.RootedAt("../")
28+
var links = Links
29+
.FromOperation(operation)
2930
.Index()
3031
.Find()
3132
.Add(Constants.Relations.Message, $"stream/{message.Position}").Self()

src/SqlStreamStore.HAL/AllStreamMessage/ReadAllStreamMessageOperation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ internal class ReadAllStreamMessageOperation : IStreamStoreOperation<StreamMessa
1010
{
1111
public ReadAllStreamMessageOperation(HttpRequest request)
1212
{
13+
Path = request.Path;
1314
Position = long.Parse(request.Path.Value.Remove(0, 2 + Constants.Streams.All.Length));
1415
}
1516

1617
public long Position { get; }
18+
public PathString Path { get; }
1719

1820
public async Task<StreamMessage> Invoke(IStreamStore streamStore, CancellationToken ct)
1921
{

src/SqlStreamStore.HAL/IStreamStoreOperation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
{
33
using System.Threading;
44
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Http;
56

67
internal interface IStreamStoreOperation<T>
78
{
9+
PathString Path { get; }
810
Task<T> Invoke(IStreamStore streamStore, CancellationToken cancellationToken);
911
}
1012
}

src/SqlStreamStore.HAL/Index/IndexResource.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace SqlStreamStore.HAL.Index
33
using System;
44
using System.Reflection;
55
using Halcyon.HAL;
6+
using Microsoft.AspNetCore.Http;
67
using Newtonsoft.Json;
78
using Newtonsoft.Json.Linq;
89

@@ -39,7 +40,7 @@ private static string GetVersion(Type type)
3940
public Response Get() => new HalJsonResponse(new HALResponse(_data)
4041
.AddLinks(
4142
Links
42-
.RootedAt(string.Empty)
43+
.FromPath(PathString.Empty)
4344
.Index().Self()
4445
.Find()
4546
.Add(Constants.Relations.Feed, Constants.Streams.All)));

0 commit comments

Comments
 (0)