-
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
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