-
Notifications
You must be signed in to change notification settings - Fork 136
[release/5.0] Print and store versions at end of every build #2157
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
Merged
MichaelSimons
merged 4 commits into
dotnet:release/5.0
from
omajid:5.0-show-build-version-info
Sep 9, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
45cd8d5
Print and store versions at end of every build
omajid 139eaaf
Use Environment.NewLine when parsing .NET version
omajid 672f46a
Improve performance of ParseDotNetVersions task
omajid aa23c54
Reuse SDK directory for version parsing and smoke-tests
omajid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
85 changes: 85 additions & 0 deletions
85
tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/ParseDotNetVersions.cs
This file contains hidden or 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,85 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace Microsoft.DotNet.Build.Tasks | ||
{ | ||
/* | ||
* This task parses the versions in a .NET SDK | ||
*/ | ||
public class ParseDotNetVersions : Task | ||
{ | ||
[Required] | ||
public string SdkRootDirectory { get; set; } | ||
|
||
[Output] | ||
public string SdkVersion { get; set; } | ||
[Output] | ||
public string AspNetCoreVersion { get; set; } | ||
[Output] | ||
public string RuntimeVersion { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
var pathToDotNet = Path.Join(SdkRootDirectory, "dotnet"); | ||
|
||
SdkVersion = ExecuteDotNetCommand(SdkRootDirectory, | ||
pathToDotNet, | ||
new List<string> { "--list-sdks" }) | ||
.First() | ||
.Split(" ") | ||
.First(); | ||
|
||
var runtimesOutput = ExecuteDotNetCommand(SdkRootDirectory, | ||
pathToDotNet, | ||
new List<string> { "--list-runtimes" }); | ||
|
||
AspNetCoreVersion = runtimesOutput | ||
.First(line => line.Contains("Microsoft.AspNetCore.App")) | ||
.Split(" ") | ||
.ElementAt(1); | ||
|
||
RuntimeVersion = runtimesOutput | ||
.First(line => line.Contains("Microsoft.NETCore.App")) | ||
.Split(" ") | ||
.ElementAt(1); | ||
|
||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Executes a dotnet command and returns the result. | ||
/// </summary> | ||
/// <param name="workingDirectory">The working directory for the dotnet command.</param> | ||
/// <param name="command">The complete path to the dotnet command to execute.</param> | ||
/// <param name="argumentList">The arguments to the dotnet command to execute.</param> | ||
/// <returns>An array of the output lines of the dotnet command.</returns> | ||
private string[] ExecuteDotNetCommand(string workingDirectory, string command, List<string> argumentList) | ||
{ | ||
string[] returnData; | ||
Process _process = new Process(); | ||
_process.StartInfo.FileName = command; | ||
foreach (string argument in argumentList) | ||
{ | ||
_process.StartInfo.ArgumentList.Add(argument); | ||
} | ||
_process.StartInfo.WorkingDirectory = workingDirectory; | ||
_process.StartInfo.RedirectStandardOutput = true; | ||
_process.StartInfo.UseShellExecute = false; | ||
_process.Start(); | ||
returnData = _process.StandardOutput.ReadToEnd().Split(Environment.NewLine); | ||
_process.WaitForExit(); | ||
return returnData; | ||
} | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In 6.0 we've been trying to reduce the disk footprint of the tarball builds. It feels like the smoke-tests should reuse this location in CI. An alternative option is to grab the .versions files out of the tarball. Could these be utilized as is with a possible rename to satisfy the requirements? If not does it make sense to just grab the versions number out of them?
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.
That's a great idea! It should be possible to re-use the directory for smoke-tests. I am testing it now out now.
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.
Thanks again for the idea. I have implemented it. Only caveat that I can think of is that now the tests will always assume that the already-extracted-sdk is pristine; if any test modifies it, the modification will persist to future test runs.
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.
Agreed, but on the other hand, I don't think this is something our tests should be doing either.