-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PrintEnvironmentVariablesModule.cs (#500)
* PrintEnvironmentVariablesModule.cs PrintGitInformationModule.cs * ReleaseNotes.md * Fix * Fix * IgnoreCycles * MaxDepth = 2, * [JsonIgnore] DirectoryInfo and FileInfo * IgnoreReadOnlyProperties = true, * IgnoreReadOnlyFields = true, * Undo readonly properties * WriteIndented = true, * Fix json cyclical reference on folder.root * [JsonConverter(typeof(FolderPathJsonConverter))] * Git Info * Fix * Formatting Markdown * WriteIndented = true, * GetRealTypeName --------- Co-authored-by: Tom Longhurst <[email protected]>
- Loading branch information
Showing
10 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/ModularPipelines.Build/Modules/PrintEnvironmentVariablesModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Microsoft.Extensions.Logging; | ||
using ModularPipelines.Context; | ||
using ModularPipelines.Modules; | ||
|
||
namespace ModularPipelines.Build.Modules; | ||
|
||
public class PrintEnvironmentVariablesModule : Module | ||
{ | ||
protected override async Task<IDictionary<string, object>?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken) | ||
{ | ||
await Task.CompletedTask; | ||
|
||
context.Logger.LogInformation("Environment Variables: {EnvVars}", JsonSerializer.Serialize(context.Environment.EnvironmentVariables.GetEnvironmentVariables(), new JsonSerializerOptions | ||
{ | ||
ReferenceHandler = ReferenceHandler.IgnoreCycles, | ||
IgnoreReadOnlyFields = true, | ||
WriteIndented = true, | ||
})); | ||
|
||
return null; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/ModularPipelines.Build/Modules/PrintGitInformationModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Microsoft.Extensions.Logging; | ||
using ModularPipelines.Context; | ||
using ModularPipelines.Git.Extensions; | ||
using ModularPipelines.Modules; | ||
|
||
namespace ModularPipelines.Build.Modules; | ||
|
||
public class PrintGitInformationModule : Module | ||
{ | ||
protected override async Task<IDictionary<string, object>?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken) | ||
{ | ||
await Task.CompletedTask; | ||
|
||
context.Logger.LogInformation("Git Info: {GitInfo}", JsonSerializer.Serialize(context.Git().Information, new JsonSerializerOptions | ||
{ | ||
ReferenceHandler = ReferenceHandler.IgnoreCycles, | ||
IgnoreReadOnlyFields = true, | ||
WriteIndented = true, | ||
})); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* DependsOnAllModulesInheritingFromAttribute to allow a module to wait on all modules inheriting from a base without needing to list each module explicitly | ||
* `[DependsOnAllModulesInheritingFromAttribute]` to allow a module to wait on all modules inheriting from a base without needing to list each module explicitly | ||
* Better JSON serialization of `Folder` objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,41 @@ | ||
namespace ModularPipelines.Extensions; | ||
using System.Text; | ||
|
||
namespace ModularPipelines.Extensions; | ||
|
||
internal static class TypeExtensions | ||
{ | ||
public static bool IsOrInheritsFrom(this Type type, Type otherType) | ||
{ | ||
return type == otherType || type.IsSubclassOf(otherType); | ||
} | ||
|
||
public static string GetRealTypeName(this Type type) | ||
{ | ||
if (!type.IsGenericType) | ||
{ | ||
return type.Name; | ||
} | ||
|
||
var stringBuilder = new StringBuilder(); | ||
|
||
stringBuilder.Append(type.Name.AsSpan(0, type.Name.IndexOf('`'))); | ||
stringBuilder.Append('<'); | ||
|
||
var appendComma = false; | ||
|
||
foreach (var genericTypeArgument in type.GetGenericArguments()) | ||
{ | ||
if (appendComma) | ||
{ | ||
stringBuilder.Append(','); | ||
} | ||
|
||
stringBuilder.Append(GetRealTypeName(genericTypeArgument)); | ||
appendComma = true; | ||
} | ||
|
||
stringBuilder.Append('>'); | ||
|
||
return stringBuilder.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using ModularPipelines.FileSystem; | ||
|
||
namespace ModularPipelines.JsonUtils; | ||
|
||
public class FolderPathJsonConverter : JsonConverter<Folder> | ||
{ | ||
public override Folder? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.Null) | ||
{ | ||
return null; | ||
} | ||
|
||
return new Folder(reader.GetString()!); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, Folder value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.Path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters