Skip to content

Commit 9a8ee60

Browse files
authored
Add tests to default build command and add github logger (#83)
1 parent 2d6621c commit 9a8ee60

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

build/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{
1616
await "dotnet tool restore";
1717
await "dotnet build -c Release --verbosity minimal";
18+
await "dotnet test --configuration Release --logger GitHubActions -- RunConfiguration.CollectSourceInformation=true";
1819
});
1920

2021
app.Add("publish", async (Cancel _) =>

src/Elastic.Markdown/IO/GitConfiguration.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ public static GitConfiguration Create(IFileSystem fileSystem)
2929
if (!gitConfig.Exists)
3030
throw new Exception($"{Paths.Root.FullName} is not a git repository.");
3131

32-
var head = Read(".git/HEAD").Replace("ref: ", string.Empty);
33-
var gitRef = Read(".git/" + head);
32+
var head = Read(".git/HEAD");
33+
var gitRef = head;
3434
var branch = head.Replace("refs/heads/", string.Empty);
35+
//not detached HEAD
36+
if (head.StartsWith("ref:"))
37+
{
38+
head = head.Replace("ref: ", string.Empty);
39+
gitRef = Read(".git/" + head);
40+
}
41+
else
42+
branch = "detached/head";
3543

3644
var ini = new FileIniDataParser();
3745
using var stream = gitConfig.OpenRead();
@@ -42,7 +50,8 @@ public static GitConfiguration Create(IFileSystem fileSystem)
4250
remote = BranchTrackingRemote("main", config);
4351
if (string.IsNullOrEmpty(remote))
4452
remote = BranchTrackingRemote("master", config);
45-
53+
if (string.IsNullOrEmpty(remote))
54+
remote = Environment.GetEnvironmentVariable("GITHUB_REPOSITORY") ?? "elastic/docs-builder-unknown";
4655

4756
return new GitConfiguration { Ref = gitRef, Branch = branch, Remote = remote };
4857

tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
77

8-
<IsPackable>false</IsPackable>
9-
<IsTestProject>true</IsTestProject>
10-
</PropertyGroup>
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
1111

12-
<ItemGroup>
13-
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
14-
<PackageReference Include="FluentAssertions" Version="6.12.1" />
15-
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
17-
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="21.0.29" />
18-
<PackageReference Include="Verify.Xunit" Version="27.0.1" />
19-
<PackageReference Include="xunit" Version="2.9.2" />
20-
</ItemGroup>
12+
<ItemGroup>
13+
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
14+
<PackageReference Include="FluentAssertions" Version="6.12.1"/>
15+
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0"/>
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
17+
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="21.0.29"/>
18+
<PackageReference Include="Verify.Xunit" Version="27.0.1"/>
19+
<PackageReference Include="xunit" Version="2.9.2"/>
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
21+
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
22+
</ItemGroup>
2123

22-
<ItemGroup>
23-
<ProjectReference Include="..\..\src\Elastic.Markdown\Elastic.Markdown.csproj" />
24-
</ItemGroup>
24+
<ItemGroup>
25+
<ProjectReference Include="..\..\src\Elastic.Markdown\Elastic.Markdown.csproj"/>
26+
</ItemGroup>
2527

2628
<ItemGroup>
2729
<Using Include="Xunit"/>

0 commit comments

Comments
 (0)