From 6c5137a31fb0ac1f340e5a66cf4dbb63783b7e38 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 20 Nov 2024 19:22:01 +0100 Subject: [PATCH 1/3] Add tests to default build command and add github logger --- build/Program.cs | 1 + .../Elastic.Markdown.Tests.csproj | 40 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/build/Program.cs b/build/Program.cs index 519b414..812697d 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -15,6 +15,7 @@ { await "dotnet tool restore"; await "dotnet build -c Release --verbosity minimal"; + await "dotnet test --configuration Release --logger GitHubActions -- RunConfiguration.CollectSourceInformation=true"; }); app.Add("publish", async (Cancel _) => diff --git a/tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj b/tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj index c948af1..eb53a99 100644 --- a/tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj +++ b/tests/Elastic.Markdown.Tests/Elastic.Markdown.Tests.csproj @@ -1,27 +1,29 @@ - - net8.0 - enable - enable + + net8.0 + enable + enable - false - true - + false + true + - - - - - - - - - + + + + + + + + + + + - - - + + + From 82b78991d1b95f81947575ce85db6db79d2be5af Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 20 Nov 2024 19:32:02 +0100 Subject: [PATCH 2/3] Be able to handle detached HEAD for GitConfiguration --- src/Elastic.Markdown/IO/GitConfiguration.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Elastic.Markdown/IO/GitConfiguration.cs b/src/Elastic.Markdown/IO/GitConfiguration.cs index 6634ab7..0f10a68 100644 --- a/src/Elastic.Markdown/IO/GitConfiguration.cs +++ b/src/Elastic.Markdown/IO/GitConfiguration.cs @@ -29,9 +29,17 @@ public static GitConfiguration Create(IFileSystem fileSystem) if (!gitConfig.Exists) throw new Exception($"{Paths.Root.FullName} is not a git repository."); - var head = Read(".git/HEAD").Replace("ref: ", string.Empty); - var gitRef = Read(".git/" + head); + var head = Read(".git/HEAD"); + var gitRef = head; var branch = head.Replace("refs/heads/", string.Empty); + //not detached HEAD + if (head.StartsWith("ref:")) + { + head = head.Replace("ref: ", string.Empty); + gitRef = Read(".git/" + head); + } + else + branch = "detached/head"; var ini = new FileIniDataParser(); using var stream = gitConfig.OpenRead(); From ac95db1eb71223961ca4c3a82625eb296cf5f351 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 20 Nov 2024 19:40:53 +0100 Subject: [PATCH 3/3] Handle local checkouts (on CI's mainly) --- src/Elastic.Markdown/IO/GitConfiguration.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/IO/GitConfiguration.cs b/src/Elastic.Markdown/IO/GitConfiguration.cs index 0f10a68..3ad5611 100644 --- a/src/Elastic.Markdown/IO/GitConfiguration.cs +++ b/src/Elastic.Markdown/IO/GitConfiguration.cs @@ -50,7 +50,8 @@ public static GitConfiguration Create(IFileSystem fileSystem) remote = BranchTrackingRemote("main", config); if (string.IsNullOrEmpty(remote)) remote = BranchTrackingRemote("master", config); - + if (string.IsNullOrEmpty(remote)) + remote = Environment.GetEnvironmentVariable("GITHUB_REPOSITORY") ?? "elastic/docs-builder-unknown"; return new GitConfiguration { Ref = gitRef, Branch = branch, Remote = remote };