-
Notifications
You must be signed in to change notification settings - Fork 827
Add AmbientMetadata.Build component #6623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add AmbientMetadata.Build component #6623
Conversation
I love porting until I realize my commit history is lost. 🤣 |
/// Gets or sets the build time in sortable date/time pattern. | ||
/// This is the time the BuildMetadataGenerator was run. | ||
/// </summary> | ||
public string? BuildDateTime { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should BuildDateTime
, BuildNumber
and BuildId
be removed or be optional, hear me out...
A good practice in dotnet is reproducible builds, having source info like repository url, source commit etc... is fine because that would be consistent and considered an input to the build (albeit implicitly), but certainly timestamps would break this practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thank you for the comment. Need to think about it
// Azure DevOps environment variables: https://learn.microsoft.com/azure/devops/pipelines/build/variables#build-variables-devops-services | ||
internal static string? AzureBuildId = Environment.GetEnvironmentVariable("Build_BuildId"); | ||
internal static string? AzureBuildNumber = Environment.GetEnvironmentVariable("Build_BuildNumber"); | ||
internal static string? AzureSourceBranchName = Environment.GetEnvironmentVariable("Build_SourceBranchName"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this alternatively be fetched by the InitializeSourceControlInformation
and related targets in MSBuild that are used for SourceLink, that way this would work for local builds as well as CI.
…hub.com/evgenyfedorov2/dotnet-extensions into users/evgenyfedorov2/add_build_metadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of the empty src/Libraries/Microsoft.Extensions.AmbientMetadata.Build/Microsoft.Extensions.AmbientMetadata.Build.json
file?
[SuppressMessage("Format", "IDE0055", Justification = "For better visualization of how the generated code will look like.")] | ||
private void OutNullGuards(bool checkBuilder = true) | ||
{ | ||
OutPP("#if NETFRAMEWORK"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should perhaps be #if !NET
so that it doesn't try to use the throw helpers in a project that targets .NET Standard.
{ | ||
const int TestAttributeConstructorArgumentsLength = 5; | ||
|
||
if (attributes.IsDefaultOrEmpty || attributes[0].ConstructorArguments.Length != TestAttributeConstructorArgumentsLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check that the name of the attribute type matches "Microsoft.Gen.BuildMetadata.GenerateBuildMetadataAttribute".
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||
<InjectExperimentalAttributeOnLegacy>true</InjectExperimentalAttributeOnLegacy> | ||
<InjectSharedDiagnosticIds>true</InjectSharedDiagnosticIds> | ||
<!-- CA1852 is for the internal shared type DiagDescriptiorsBase. It can't be sealed because there are child classes in other components--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling DiagDescriptorsBase
.
Adding a brand new component - Build metadata, which automatically grabs build information from the CI/CD pipelines, deserializes it into a strong type
BuildMetadata
and registers it in Dependency Injection container asIOptions<BuildMetadata>
.The component uses source generation to collect build information and immediately express it via C# code.
Initially, only GitHub Actions and Azure DevOps are supported
Microsoft Reviewers: Open in CodeFlow