Skip to content

Commit 11c29ce

Browse files
authored
Added GitInformation project files. (#37)
Moved the project files to Elskom.GitInformation over to this repository. Signed-off-by: AraHaan <[email protected]>
1 parent a8ec9af commit 11c29ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1088
-379
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,4 @@ $RECYCLE.BIN/
451451
!.vscode/settings.json
452452
!.vscode/tasks.json
453453
!.vscode/launch.json
454-
!.vscode/extensions.json
454+
!.vscode/extensions.json

Directory.Build.props

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<LangVersion>latest</LangVersion>
5+
<Company>Els_kom org.</Company>
6+
<Authors>Els_kom org.</Authors>
7+
<RepositoryType>git</RepositoryType>
8+
<RepositoryUrl>https://github.com/Elskom/GitBuildInfo.SourceGenerator/</RepositoryUrl>
9+
<PackageProjectUrl>https://github.com/Elskom/GitBuildInfo.SourceGenerator/</PackageProjectUrl>
10+
<PackageOutputPath>$(MSBuildThisFileDirectory)artifacts\</PackageOutputPath>
11+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12+
<!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
13+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
14+
<DebugType>embedded</DebugType>
15+
<DebugSymbols>true</DebugSymbols>
16+
<!-- suppress message when using the .NET Preview SDKs. -->
17+
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
18+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
19+
</PropertyGroup>
20+
21+
</Project>

GitBuildInfo.SourceGenerator.sln

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.6.30114.105
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitBuildInfo.SourceGenerator", "src/GitBuildInfo.SourceGenerator.csproj", "{D769E982-58EE-436B-B2A8-C35D4D55BA8D}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitBuildInfo.SourceGenerator", "src/GitBuildInfo.SourceGenerator/GitBuildInfo.SourceGenerator.csproj", "{D769E982-58EE-436B-B2A8-C35D4D55BA8D}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{99761A41-8AED-49B5-AF0F-CF6CCAE482E8}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B84AD34C-E5C4-418F-A58A-195C9F89A961}"
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitBuildInfo.SourceGenerator.Tests", "tests/GitBuildInfo.SourceGenerator.Tests.csproj", "{5A9FCC65-752B-499B-A86B-ABCC6F4666D9}"
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elskom.GitInformation", "src\Elskom.GitInformation\Elskom.GitInformation.csproj", "{FD675B8D-C607-4007-A7E1-09531F535EE6}"
15+
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1618
Debug|Any CPU = Debug|Any CPU
@@ -48,9 +50,22 @@ Global
4850
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9}.Release|x64.Build.0 = Release|Any CPU
4951
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9}.Release|x86.ActiveCfg = Release|Any CPU
5052
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9}.Release|x86.Build.0 = Release|Any CPU
53+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Debug|x64.ActiveCfg = Debug|Any CPU
56+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Debug|x64.Build.0 = Debug|Any CPU
57+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Debug|x86.ActiveCfg = Debug|Any CPU
58+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Debug|x86.Build.0 = Debug|Any CPU
59+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|x64.ActiveCfg = Release|Any CPU
62+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|x64.Build.0 = Release|Any CPU
63+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|x86.ActiveCfg = Release|Any CPU
64+
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|x86.Build.0 = Release|Any CPU
5165
EndGlobalSection
5266
GlobalSection(NestedProjects) = preSolution
5367
{D769E982-58EE-436B-B2A8-C35D4D55BA8D} = {99761A41-8AED-49B5-AF0F-CF6CCAE482E8}
5468
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9} = {B84AD34C-E5C4-418F-A58A-195C9F89A961}
69+
{FD675B8D-C607-4007-A7E1-09531F535EE6} = {99761A41-8AED-49B5-AF0F-CF6CCAE482E8}
5570
EndGlobalSection
5671
EndGlobal

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-2021 Els_kom
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2-
2+
3+
<PropertyGroup>
4+
<GitBuildInfoIsGeneric Condition="'$(GitBuildInfoIsGeneric)' == ''">false</GitBuildInfoIsGeneric>
5+
</PropertyGroup>
6+
37
<ItemGroup>
4-
<AdditionalFiles Include="GitBuildInfo.json" Condition="Exists('GitBuildInfo.json')" />
5-
<AdditionalFiles Include="GitInfo.json" Condition="Exists('GitInfo.json')" />
8+
<CompilerVisibleProperty Include="GitBuildInfoAssemblyType" />
9+
<CompilerVisibleProperty Include="GitBuildInfoIsGeneric" />
10+
<CompilerVisibleProperty Include="GitHead" />
11+
<CompilerVisibleProperty Include="CommitHash" />
12+
<CompilerVisibleProperty Include="GitBranch" />
613
</ItemGroup>
14+
715
</Project>

build/GitBuildInfo.SourceGenerator.targets

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
TaskFactory="RoslynCodeTaskFactory"
66
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
77
<ParameterGroup>
8-
<OutputPath Required="true" />
8+
<ProjectDir ParameterType="System.String" Required="true" />
9+
<GitHead ParameterType="System.String" Output="true" />
10+
<CommitHash ParameterType="System.String" Output="true" />
11+
<GitBranch ParameterType="System.String" Output="true" />
912
</ParameterGroup>
1013
<Task>
1114
<Code Source="$(MSBuildThisFileDirectory)GitInfoTask.cs" />
1215
</Task>
1316
</UsingTask>
1417

15-
<Target Name="BeforeBuild">
16-
<GitInfoTask OutputPath="$(MSBuildProjectDirectory)\GitInfo.json" />
18+
<Target Name="GitBuildInfo" AfterTargets="PrepareForBuild">
19+
<GitInfoTask ProjectDir="$(MSBuildProjectDirectory)">
20+
<Output TaskParameter="GitHead" PropertyName="GitHead" />
21+
<Output TaskParameter="CommitHash" PropertyName="CommitHash" />
22+
<Output TaskParameter="GitBranch" PropertyName="GitBranch" />
23+
</GitInfoTask>
1724
</Target>
1825

1926
</Project>

build/GitInfoTask.cs

+30-25
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,63 @@
1616
public class GitInfoTask : Task
1717
{
1818
/// <summary>
19-
/// Gets or sets the generated output file path.
19+
/// Gets or sets the directory that contains the project.
2020
/// </summary>
2121
[Required]
22-
public string OutputPath { get; set; }
22+
public string ProjectDir { get; set; }
23+
24+
/// <summary>
25+
/// Gets or sets the git head information.
26+
/// </summary>
27+
[Output]
28+
public string GitHead { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the git commit hash.
32+
/// </summary>
33+
[Output]
34+
public string CommitHash { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the current git branch information.
38+
/// </summary>
39+
[Output]
40+
public string GitBranch { get; set; }
2341

2442
/// <inheritdoc/>
2543
public override bool Execute()
2644
{
27-
this.RunGit("describe --all --always --dirty", out var git_out1);
28-
this.RunGit("rev-parse --short HEAD", out var git_out2);
29-
this.RunGit("name-rev --name-only HEAD", out var git_out3);
30-
var outputData = $"{{{Environment.NewLine} \"GitHead\": \"{git_out1}\",{Environment.NewLine} \"CommitHash\": \"{git_out2}\",{Environment.NewLine} \"GitBranch\": \"{git_out3}\"{Environment.NewLine}}}";
31-
// patch 112019: only print the getting build info from git message from the initial call to this task.
32-
// all other calls will not print anything to avoid spamming up the build output.
33-
try
34-
{
35-
if (!File.Exists(this.OutputPath) || (File.Exists(this.OutputPath) && !string.Equals(outputData, File.ReadAllText(this.OutputPath), StringComparison.Ordinal)))
36-
{
37-
this.Log.LogMessage(MessageImportance.High, "Getting build info from git");
38-
File.WriteAllText(this.OutputPath, outputData);
39-
}
40-
}
41-
catch (IOException)
42-
{
43-
// catch I/O error from being unable to open the file for checking it's contents.
44-
}
45+
this.GitHead = this.RunGit("describe --all --always --dirty");
46+
this.CommitHash = this.RunGit("rev-parse --short HEAD");
47+
this.GitBranch = this.RunGit("name-rev --name-only HEAD");
48+
this.Log.LogMessage(MessageImportance.High, "Getting build info from git");
4549
return true;
4650
}
4751

48-
private void RunGit(string arguments, out string git_out)
52+
private string RunGit(string arguments)
4953
{
5054
using var pro1 = new Process();
5155
pro1.StartInfo.FileName = "git";
5256
pro1.StartInfo.Arguments = arguments;
5357
pro1.StartInfo.RedirectStandardOutput = true;
5458
pro1.StartInfo.UseShellExecute = false;
5559
pro1.StartInfo.CreateNoWindow = true;
56-
pro1.StartInfo.WorkingDirectory = Path.GetFullPath(this.OutputPath).Replace(Path.GetFileName(this.OutputPath), string.Empty);
60+
pro1.StartInfo.WorkingDirectory = Path.GetFullPath(this.ProjectDir).Replace(Path.GetFileName(this.ProjectDir), string.Empty);
5761
try
5862
{
5963
_ = pro1.Start();
60-
git_out = pro1.StandardOutput.ReadToEnd();
64+
var git_out = pro1.StandardOutput.ReadToEnd();
6165
pro1.WaitForExit();
6266
// handle all cases of possible endlines.
6367
git_out = git_out.Replace("\r\n", string.Empty);
6468
git_out = git_out.Replace("\n", string.Empty);
6569
git_out = git_out.Replace("\r", string.Empty);
70+
return git_out;
6671
}
6772
catch (Win32Exception)
6873
{
69-
git_out = "Not a git clone or git is not in Path.";
74+
return "Not a git clone or git is not in Path.";
7075
}
7176
}
7277
}
73-
}
78+
}
+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Remove the line below if you want to inherit .editorconfig settings from higher directories
2+
root = true
3+
4+
# C# files
5+
[*.cs]
6+
7+
#### Core EditorConfig Options ####
8+
9+
# Indentation and spacing
10+
indent_size = 4
11+
indent_style = space
12+
tab_width = 4
13+
14+
# New line preferences
15+
end_of_line = crlf
16+
insert_final_newline = false
17+
18+
#### .NET Coding Conventions ####
19+
20+
# this. and Me. preferences
21+
dotnet_style_qualification_for_event = true:warning
22+
dotnet_style_qualification_for_field = true:warning
23+
dotnet_style_qualification_for_method = true:warning
24+
dotnet_style_qualification_for_property = true:warning
25+
26+
# Language keywords vs BCL types preferences
27+
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
28+
dotnet_style_predefined_type_for_member_access = true:warning
29+
30+
# Parentheses preferences
31+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning
32+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
33+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
34+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning
35+
36+
# Modifier preferences
37+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
38+
39+
# Expression-level preferences
40+
csharp_style_deconstructed_variable_declaration = true:warning
41+
csharp_style_inlined_variable_declaration = true:warning
42+
csharp_style_throw_expression = true:warning
43+
dotnet_style_coalesce_expression = true:warning
44+
dotnet_style_collection_initializer = true:warning
45+
dotnet_style_explicit_tuple_names = true:warning
46+
dotnet_style_null_propagation = true:warning
47+
dotnet_style_object_initializer = true:warning
48+
dotnet_style_prefer_auto_properties = true:warning
49+
dotnet_style_prefer_compound_assignment = true:suggestion
50+
dotnet_style_prefer_conditional_expression_over_assignment = true:warning
51+
dotnet_style_prefer_conditional_expression_over_return = true:warning
52+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
53+
dotnet_style_prefer_inferred_tuple_names = true:warning
54+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
55+
56+
# Field preferences
57+
dotnet_style_readonly_field = true:warning
58+
59+
# Parameter preferences
60+
dotnet_code_quality_unused_parameters = all:suggestion
61+
62+
#### C# Coding Conventions ####
63+
64+
# var preferences
65+
csharp_style_var_elsewhere = true:warning
66+
csharp_style_var_for_built_in_types = true:warning
67+
csharp_style_var_when_type_is_apparent = true:warning
68+
69+
# Expression-bodied members
70+
csharp_style_expression_bodied_accessors = true:warning
71+
csharp_style_expression_bodied_constructors = true:warning
72+
csharp_style_expression_bodied_indexers = true:warning
73+
csharp_style_expression_bodied_lambdas = true:silent
74+
csharp_style_expression_bodied_local_functions = true:silent
75+
csharp_style_expression_bodied_methods = true:warning
76+
csharp_style_expression_bodied_operators = true:warning
77+
csharp_style_expression_bodied_properties = true:warning
78+
79+
# Pattern matching preferences
80+
csharp_style_pattern_matching_over_as_with_null_check = true:warning
81+
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
82+
83+
# Null-checking preferences
84+
csharp_style_conditional_delegate_call = true:warning
85+
86+
# Modifier preferences
87+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
88+
89+
# Code-block preferences
90+
csharp_prefer_braces = true:warning
91+
92+
# Expression-level preferences
93+
csharp_prefer_simple_default_expression = true:warning
94+
csharp_style_pattern_local_over_anonymous_function = true:warning
95+
csharp_style_prefer_index_operator = true:suggestion
96+
csharp_style_prefer_range_operator = true:suggestion
97+
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
98+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
99+
100+
#### C# Formatting Rules ####
101+
102+
# New line preferences
103+
csharp_new_line_before_catch = true
104+
csharp_new_line_before_else = true
105+
csharp_new_line_before_finally = true
106+
csharp_new_line_before_members_in_anonymous_types = true
107+
csharp_new_line_before_members_in_object_initializers = true
108+
csharp_new_line_before_open_brace = all
109+
csharp_new_line_between_query_expression_clauses = true
110+
111+
# Indentation preferences
112+
csharp_indent_block_contents = true
113+
csharp_indent_braces = false
114+
csharp_indent_case_contents = true
115+
csharp_indent_case_contents_when_block = false
116+
csharp_indent_labels = one_less_than_current
117+
csharp_indent_switch_labels = true
118+
119+
# Space preferences
120+
csharp_space_after_cast = false
121+
csharp_space_after_colon_in_inheritance_clause = true
122+
csharp_space_after_comma = true
123+
csharp_space_after_dot = false
124+
csharp_space_after_keywords_in_control_flow_statements = true
125+
csharp_space_after_semicolon_in_for_statement = true
126+
csharp_space_around_binary_operators = before_and_after
127+
csharp_space_around_declaration_statements = false
128+
csharp_space_before_colon_in_inheritance_clause = true
129+
csharp_space_before_comma = false
130+
csharp_space_before_dot = false
131+
csharp_space_before_open_square_brackets = false
132+
csharp_space_before_semicolon_in_for_statement = false
133+
csharp_space_between_empty_square_brackets = false
134+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
135+
csharp_space_between_method_call_name_and_opening_parenthesis = false
136+
csharp_space_between_method_call_parameter_list_parentheses = false
137+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
138+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
139+
csharp_space_between_method_declaration_parameter_list_parentheses = false
140+
csharp_space_between_parentheses = false
141+
csharp_space_between_square_brackets = false
142+
143+
# Wrapping preferences
144+
csharp_preserve_single_line_blocks = true
145+
csharp_preserve_single_line_statements = true
146+
147+
148+
# CA1307: Specify StringComparison
149+
dotnet_diagnostic.CA1307.severity = warning

0 commit comments

Comments
 (0)