Skip to content

[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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WriteUsageBurndownData" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ReplaceTextInFile" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="DownloadFileSB" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ParseDotNetVersions" />

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

Expand Down Expand Up @@ -137,6 +138,46 @@
<WriteLinesToFile File="$(CompletedSemaphorePath)ReportPoisonUsage.complete" Overwrite="true" />
</Target>

<Target Name="VerifyAndWriteVersionsToFile"
AfterTargets="Build">

<ItemGroup>
<FinalSdkTarball Include="$(OutputPath)\dotnet-sdk-$(MajorVersion)*$(TarBallExtension)" />
</ItemGroup>

<PropertyGroup>
<!-- Shared path with smoke-test.sh -->
<ExtractedPath>$(BaseOutputPath)\builtCli\</ExtractedPath>
</PropertyGroup>

<MakeDir Directories="$(ExtractedPath)" />

<Exec Command="tar xf @(FinalSdkTarball) -C $(ExtractedPath)" />
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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.


<ParseDotNetVersions SdkRootDirectory="$(ExtractedPath)">
<Output TaskParameter="SdkVersion" PropertyName="BuiltSdkVersion" />
<Output TaskParameter="AspNetCoreVersion" PropertyName="BuiltAspNetCoreVersion" />
<Output TaskParameter="RuntimeVersion" PropertyName="BuiltRuntimeVersion" />
</ParseDotNetVersions>

<Message Text="Build Info:" Importance="High"/>
<Message Text=" SDK Version: $(BuiltSdkVersion)" Importance="High"/>
<Message Text=" ASP.NET Core Version: $(BuiltAspNetCoreVersion)" Importance="High"/>
<Message Text=" Runtime Version: $(BuiltRuntimeVersion)" Importance="High"/>

<WriteLinesToFile Lines="$(BuiltSdkVersion)" File="$(BaseOutputPath)\build-info\SdkVersion.txt" Overwrite="True" />
<WriteLinesToFile Lines="$(BuiltAspNetCoreVersion)" File="$(BaseOutputPath)\build-info\AspNetCoreVersion.txt" Overwrite="True" />
<WriteLinesToFile Lines="$(BuiltRuntimeVersion)" File="$(BaseOutputPath)\build-info\RuntimeVersion.txt" Overwrite="True" />

<Error Text="Mismatch in SDK version between what was built ($(BuiltSdkVersion)) and what's in Version.props ($(SdkProductVersion))"
Condition="'$(BuiltSdkVersion)' != '$(SdkProductVersion)'" />
<Error Text="Mismatch in ASP.NET Core version between what was built ($(BuiltAspNetCoreVersion)) and what's in Version.props ($(AspNetCoreProductVersion))"
Condition="'$(BuiltAspNetCoreVersion)' != '$(AspNetCoreProductVersion)'" />
<Error Text="Mismatch in Runtime version between what was built ($(BuiltRuntimeVersion)) and what's in Version.props ($(RuntimeProductVersion))"
Condition="'$(BuiltRuntimeVersion)' != '$(RuntimeProductVersion)'" />

</Target>

<Target Name="GeneratePrebuiltBurndownData"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(CompletedSemaphorePath)GeneratePrebuiltBurndownData.complete" >
Expand Down
14 changes: 9 additions & 5 deletions smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ excludeLocalTests=false
excludeOnlineTests=false
devCertsVersion="$DEV_CERTS_VERSION_DEFAULT"
testingDir="$SCRIPT_ROOT/testing-smoke"
cliDir="$testingDir/builtCli"
# Shared path with build.proj
cliDir="$SCRIPT_ROOT/artifacts/builtCli"
logFile="$testingDir/smoke-test.log"
restoredPackagesDir="$testingDir/packages"
testingHome="$testingDir/home"
Expand Down Expand Up @@ -611,11 +612,14 @@ echo "<Project />" | tee Directory.Build.props > Directory.Build.targets

# Unzip dotnet if the dotnetDir is not specified
if [ "$dotnetDir" == "" ]; then
OUTPUT_DIR="$SCRIPT_ROOT/artifacts/$buildArch/$configuration/"
DOTNET_TARBALL="$(ls "${OUTPUT_DIR}${TARBALL_PREFIX}${VERSION_PREFIX}"*)"
# It's possible that build.proj extracted the just-built dotnet tarball for other processing already
if [ ! -d "$cliDir" ]; then
OUTPUT_DIR="$SCRIPT_ROOT/artifacts/$buildArch/$configuration/"
DOTNET_TARBALL="$(ls "${OUTPUT_DIR}${TARBALL_PREFIX}${VERSION_PREFIX}"*)"

mkdir -p "$cliDir"
tar xzf "$DOTNET_TARBALL" -C "$cliDir"
mkdir -p "$cliDir"
tar xzf "$DOTNET_TARBALL" -C "$cliDir"
fi
dotnetDir="$cliDir"
else
if ! [[ "$dotnetDir" = /* ]]; then
Expand Down
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;
}

}
}