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/src/Elastic.Markdown/IO/GitConfiguration.cs b/src/Elastic.Markdown/IO/GitConfiguration.cs index 6634ab7..3ad5611 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(); @@ -42,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 }; 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 + - - - - - - - - - + + + + + + + + + + + - - - + + +