Skip to content

Commit

Permalink
When building locally, default branch to HEAD
Browse files Browse the repository at this point in the history
If we can't find an envvar with the right value, default to checkout HEAD.
  • Loading branch information
kzu committed Jan 28, 2023
1 parent 8b0a1be commit 4a11a03
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 48 deletions.
6 changes: 6 additions & 0 deletions src/ThisAssembly.Git/ThisAssembly.Git.targets
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
<RepositoryRoot>@(_ThisAssemblyGitSourceRoot)</RepositoryRoot>
</PropertyGroup>

<PropertyGroup Condition="'$(RepositoryBranch)' == '' and '$(RepositoryRoot)' != ''">
<!-- We may not be in CI at all. If we got a git repo root, we can directly read HEAD -->
<RepositoryHead>$(RepositoryRoot).git/HEAD</RepositoryHead>
<RepositoryBranch Condition="Exists($(RepositoryHead))">$([System.IO.File]::ReadAllText($(RepositoryHead)).TrimStart("ref: refs/heads/"))</RepositoryBranch>
</PropertyGroup>

</Target>

<Target Name="PrepareGitConstants"
Expand Down
103 changes: 55 additions & 48 deletions src/ThisAssembly.Tests/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,78 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Xunit;
using Xunit.Abstractions;

[assembly: SuppressMessage("SponsorLink", "SL04")]

namespace ThisAssemblyTests
namespace ThisAssemblyTests;

public record class Tests(ITestOutputHelper Output)
{
public class Tests
{
[Fact]
public void CanReadResourceFile()
=> Assert.NotNull(ResourceFile.Load("Resources.resx", "Strings"));
[Fact]
public void CanReadResourceFile()
=> Assert.NotNull(ResourceFile.Load("Resources.resx", "Strings"));

[Fact]
public void CanUseInfo()
=> Assert.Equal("ThisAssembly.Tests", ThisAssembly.Info.Title);
[Fact]
public void CanUseInfo()
=> Assert.Equal("ThisAssembly.Tests", ThisAssembly.Info.Title);

[Fact]
public void CanUseConstants()
=> Assert.Equal("Baz", ThisAssembly.Constants.Foo.Bar);
[Fact]
public void CanUseConstants()
=> Assert.Equal("Baz", ThisAssembly.Constants.Foo.Bar);

[Fact]
public void CanUseFileConstants()
=> Assert.Equal(ThisAssembly.Constants.Content.Docs.License, Path.Combine("Content", "Docs", "License.md"));
[Fact]
public void CanUseFileConstants()
=> Assert.Equal(ThisAssembly.Constants.Content.Docs.License, Path.Combine("Content", "Docs", "License.md"));

[Fact]
public void CanUseFileConstantLinkedFile()
=> Assert.Equal(ThisAssembly.Constants.Included.Readme, Path.Combine("Included", "Readme.txt"));
[Fact]
public void CanUseFileConstantLinkedFile()
=> Assert.Equal(ThisAssembly.Constants.Included.Readme, Path.Combine("Included", "Readme.txt"));

[Fact]
public void CanUseMetadata()
=> Assert.Equal("Bar", ThisAssembly.Metadata.Foo);
[Fact]
public void CanUseMetadata()
=> Assert.Equal("Bar", ThisAssembly.Metadata.Foo);

[Fact]
public void CanUseProjectProperty()
=> Assert.Equal("Bar", ThisAssembly.Project.Foo);
[Fact]
public void CanUseProjectProperty()
=> Assert.Equal("Bar", ThisAssembly.Project.Foo);

[Fact]
public void CanUseStringsNamedArguments()
=> Assert.NotNull(ThisAssembly.Strings.Named("hello", "world"));
[Fact]
public void CanUseStringsNamedArguments()
=> Assert.NotNull(ThisAssembly.Strings.Named("hello", "world"));

[Fact]
public void CanUseStringsIndexedArguments()
=> Assert.NotNull(ThisAssembly.Strings.Indexed("hello", "world"));
[Fact]
public void CanUseStringsIndexedArguments()
=> Assert.NotNull(ThisAssembly.Strings.Indexed("hello", "world"));

[Fact]
public void CanUseStringResource()
=> Assert.Equal("Value", ThisAssembly.Strings.Foo.Bar.Baz);
[Fact]
public void CanUseStringResource()
=> Assert.Equal("Value", ThisAssembly.Strings.Foo.Bar.Baz);

[Fact]
public void CanUseTextResource()
=> Assert.NotNull(ThisAssembly.Resources.Content.Styles.Custom.Text);
[Fact]
public void CanUseTextResource()
=> Assert.NotNull(ThisAssembly.Resources.Content.Styles.Custom.Text);

[Fact]
public void CanUseByteResource()
=> Assert.NotNull(ThisAssembly.Resources.Content.Styles.Main.GetBytes());
[Fact]
public void CanUseByteResource()
=> Assert.NotNull(ThisAssembly.Resources.Content.Styles.Main.GetBytes());

[Fact]
public void CanUseSameNameDifferentExtensions()
=> Assert.NotNull(ThisAssembly.Resources.Content.Swagger.swagger_ui.css.GetBytes());
[Fact]
public void CanUseSameNameDifferentExtensions()
=> Assert.NotNull(ThisAssembly.Resources.Content.Swagger.swagger_ui.css.GetBytes());

[Fact]
public void CanUseFileInvalidCharacters()
=> Assert.NotNull(ThisAssembly.Resources.webhook_data.Text);
[Fact]
public void CanUseFileInvalidCharacters()
=> Assert.NotNull(ThisAssembly.Resources.webhook_data.Text);

[Fact]
public void CanUseGitConstants()
=> Assert.NotEmpty(ThisAssembly.Git.Commit);
[Fact]
public void CanUseGitConstants()
=> Assert.NotEmpty(ThisAssembly.Git.Commit);

[Fact]
public void CanUseGitBranchConstants()
{
Assert.NotEmpty(ThisAssembly.Git.Branch);
Output.WriteLine(ThisAssembly.Git.Branch);
}
}

0 comments on commit 4a11a03

Please sign in to comment.