Include .version file in SB artifacts tarball (#15353)
This commit is contained in:
parent
266202b0c9
commit
a6f0171cbc
5 changed files with 108 additions and 4 deletions
|
@ -164,12 +164,13 @@ jobs:
|
|||
set -x
|
||||
df -h
|
||||
|
||||
customRunArgs=
|
||||
# Allows Arcade to have access to the commit for the build
|
||||
customRunArgs="-e BUILD_SOURCEVERSION"
|
||||
customBuildArgs=
|
||||
if [[ '${{ parameters.runOnline }}' == 'True' ]]; then
|
||||
customBuildArgs='--online'
|
||||
else
|
||||
customRunArgs='--network none'
|
||||
customRunArgs="$customRunArgs --network none"
|
||||
fi
|
||||
|
||||
# See https://github.com/dotnet/source-build/issues/3202
|
||||
|
@ -188,7 +189,7 @@ jobs:
|
|||
set -x
|
||||
|
||||
dockerVolumeArgs="-v $(sourcesPath):/vmr"
|
||||
dockerEnvArgs="-e SMOKE_TESTS_EXCLUDE_OMNISHARP=${{ parameters.excludeOmniSharpTests }} -e SMOKE_TESTS_WARN_SDK_CONTENT_DIFFS=true"
|
||||
dockerEnvArgs="-e SMOKE_TESTS_EXCLUDE_OMNISHARP=${{ parameters.excludeOmniSharpTests }} -e SMOKE_TESTS_WARN_SDK_CONTENT_DIFFS=true -e SMOKE_TESTS_RUNNING_IN_CI=true"
|
||||
poisonArg=''
|
||||
|
||||
if [[ '${{ parameters.excludeSdkContentTests }}' != 'True' ]]; then
|
||||
|
|
|
@ -97,11 +97,13 @@
|
|||
<Target Name="RunSmokeTest">
|
||||
<ItemGroup>
|
||||
<SdkTarballItem Include="$(SourceBuiltTarBallPath)**/dotnet-sdk*$(TarBallExtension)" />
|
||||
<SourceBuiltArtifactsItem Include="$(SourceBuiltTarBallPath)**/Private.SourceBuilt.Artifacts.*$(TarBallExtension)" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<CustomTestEnvVars Condition="'$(EnablePoison)' == 'true'">SMOKE_TESTS_POISON_REPORT_PATH=$(PoisonUsageReportFile);</CustomTestEnvVars>
|
||||
<SdkTarballPath>%(SdkTarballItem.Identity)</SdkTarballPath>
|
||||
<SourceBuiltArtifactsPath>%(SourceBuiltArtifactsItem.Identity)</SourceBuiltArtifactsPath>
|
||||
<SmokeTestConsoleVerbosity Condition="'$(SmokeTestConsoleVerbosity)' == ''">normal</SmokeTestConsoleVerbosity>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -109,6 +111,7 @@
|
|||
<Exec Command="$(DotnetToolCommand) test $(SmokeTestsDir) --logger:trx --logger:'console;verbosity=$(SmokeTestConsoleVerbosity)' -c $(Configuration)"
|
||||
EnvironmentVariables="
|
||||
SMOKE_TESTS_SDK_TARBALL_PATH=$(SdkTarballPath);
|
||||
SMOKE_TESTS_SOURCEBUILT_ARTIFACTS_PATH=$(SourceBuiltArtifactsPath);
|
||||
SMOKE_TESTS_TARGET_RID=$(TargetRid);
|
||||
SMOKE_TESTS_PORTABLE_RID=$(PortableRid);
|
||||
SMOKE_TESTS_CUSTOM_PACKAGES_PATH=$(CustomSourceBuiltPackagesPath);
|
||||
|
|
|
@ -48,9 +48,33 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<SourceBuiltTarballName>$(OutputPath)$(SourceBuiltArtifactsTarballName).$(installerOutputPackageVersion).$(TargetRid).tar.gz</SourceBuiltTarballName>
|
||||
<SourceBuiltVersionFileName>.version</SourceBuiltVersionFileName>
|
||||
</PropertyGroup>
|
||||
|
||||
<Exec Command="tar --numeric-owner --exclude='Microsoft.SourceBuild.Intermediate.*.nupkg' -czf $(SourceBuiltTarballName) *.nupkg *.props SourceBuildReferencePackages/"
|
||||
<!--
|
||||
Manually load the installer version from the PVP. This is manually done instead of using an explicit
|
||||
<Import> because the PVP does not exist at the time this project file is loaded.
|
||||
-->
|
||||
<XmlPeek XmlInputPath="$(CurrentSourceBuiltPackageVersionPropsPath)"
|
||||
Query="msb:Project/msb:PropertyGroup/msb:MicrosoftSourceBuildIntermediateInstallerVersion/text()"
|
||||
Namespaces="<Namespace Prefix='msb' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/>">
|
||||
<Output TaskParameter="Result" ItemName="MicrosoftSourceBuildIntermediateInstallerVersionItem" />
|
||||
</XmlPeek>
|
||||
<PropertyGroup>
|
||||
<MicrosoftSourceBuildIntermediateInstallerVersion>@(MicrosoftSourceBuildIntermediateInstallerVersionItem)</MicrosoftSourceBuildIntermediateInstallerVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Content of the .version file to include in the tarball -->
|
||||
<ItemGroup>
|
||||
<VersionFileContent Include="$(RepositoryCommit);$(MicrosoftSourceBuildIntermediateInstallerVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<WriteLinesToFile
|
||||
File="$(SourceBuiltPackagesPath)$(SourceBuiltVersionFileName)"
|
||||
Lines="@(VersionFileContent)"
|
||||
Overwrite="true" />
|
||||
|
||||
<Exec Command="tar --numeric-owner --exclude='Microsoft.SourceBuild.Intermediate.*.nupkg' -czf $(SourceBuiltTarballName) $(SourceBuiltVersionFileName) *.nupkg *.props SourceBuildReferencePackages/"
|
||||
WorkingDirectory="$(SourceBuiltPackagesPath)" />
|
||||
|
||||
<Message Importance="High" Text="Packaged source-built artifacts to $(SourceBuiltTarballName)" />
|
||||
|
|
|
@ -17,9 +17,11 @@ internal static class Config
|
|||
public const string PrereqsPathEnv = "SMOKE_TESTS_PREREQS_PATH";
|
||||
public const string CustomPackagesPathEnv = "SMOKE_TESTS_CUSTOM_PACKAGES_PATH";
|
||||
public const string SdkTarballPathEnv = "SMOKE_TESTS_SDK_TARBALL_PATH";
|
||||
public const string SourceBuiltArtifactsPathEnv = "SMOKE_TESTS_SOURCEBUILT_ARTIFACTS_PATH";
|
||||
public const string TargetRidEnv = "SMOKE_TESTS_TARGET_RID";
|
||||
public const string WarnPoisonDiffsEnv = "SMOKE_TESTS_WARN_POISON_DIFFS";
|
||||
public const string WarnSdkContentDiffsEnv = "SMOKE_TESTS_WARN_SDK_CONTENT_DIFFS";
|
||||
public const string RunningInCIEnv = "SMOKE_TESTS_RUNNING_IN_CI";
|
||||
|
||||
public static string DotNetDirectory { get; } =
|
||||
Environment.GetEnvironmentVariable(DotNetDirectoryEnv) ?? Path.Combine(Directory.GetCurrentDirectory(), ".dotnet");
|
||||
|
@ -30,6 +32,8 @@ internal static class Config
|
|||
public static string? PrereqsPath { get; } = Environment.GetEnvironmentVariable(PrereqsPathEnv);
|
||||
public static string? CustomPackagesPath { get; } = Environment.GetEnvironmentVariable(CustomPackagesPathEnv);
|
||||
public static string? SdkTarballPath { get; } = Environment.GetEnvironmentVariable(SdkTarballPathEnv);
|
||||
public static string? SourceBuiltArtifactsPath { get; } = Environment.GetEnvironmentVariable(SourceBuiltArtifactsPathEnv) ??
|
||||
throw new InvalidOperationException($"'{Config.SourceBuiltArtifactsPathEnv}' must be specified");
|
||||
public static string TargetRid { get; } = Environment.GetEnvironmentVariable(TargetRidEnv) ??
|
||||
throw new InvalidOperationException($"'{Config.TargetRidEnv}' must be specified");
|
||||
public static string TargetArchitecture { get; } = TargetRid.Split('-')[1];
|
||||
|
@ -37,4 +41,8 @@ internal static class Config
|
|||
bool.TryParse(Environment.GetEnvironmentVariable(WarnPoisonDiffsEnv), out bool excludeOnlineTests) && excludeOnlineTests;
|
||||
public static bool WarnOnSdkContentDiffs { get; } =
|
||||
bool.TryParse(Environment.GetEnvironmentVariable(WarnSdkContentDiffsEnv), out bool excludeOnlineTests) && excludeOnlineTests;
|
||||
|
||||
// Indicates whether the tests are being run in the context of a CI pipeline
|
||||
public static bool RunningInCI { get; } =
|
||||
bool.TryParse(Environment.GetEnvironmentVariable(RunningInCIEnv), out bool runningInCI) && runningInCI;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
|
||||
|
||||
public class SourceBuiltArtifactsTests : SmokeTests
|
||||
{
|
||||
public SourceBuiltArtifactsTests(ITestOutputHelper outputHelper) : base(outputHelper) { }
|
||||
|
||||
[Fact]
|
||||
public void VerifyVersionFile()
|
||||
{
|
||||
string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "sourcebuilt-artifacts");
|
||||
Directory.CreateDirectory(outputDir);
|
||||
try
|
||||
{
|
||||
// Extract the .version file
|
||||
ExtractFileFromTarball(Config.SourceBuiltArtifactsPath, ".version", outputDir);
|
||||
|
||||
string[] versionLines = File.ReadAllLines(Path.Combine(outputDir, ".version"));
|
||||
Assert.Equal(2, versionLines.Length);
|
||||
|
||||
// Verify the commit SHA
|
||||
|
||||
string commitSha = versionLines[0];
|
||||
OutputHelper.WriteLine($"Commit SHA: {commitSha}");
|
||||
Assert.Equal(40, commitSha.Length);
|
||||
Assert.True(commitSha.All(c => char.IsLetterOrDigit(c)));
|
||||
|
||||
// When running in CI, we should ensure that the commit SHA is not all zeros, which is the default
|
||||
// value when no commit SHA is available. In a dev environment this will likely be all zeros but it's
|
||||
// possible that it could be a valid commit SHA depending on the environment's configuration, so we
|
||||
// only verify this in CI.
|
||||
if (Config.RunningInCI)
|
||||
{
|
||||
Assert.False(commitSha.All(c => c == '0'));
|
||||
}
|
||||
|
||||
// Verify the SDK version
|
||||
|
||||
string sdkVersion = versionLines[1];
|
||||
|
||||
// Find the expected SDK version by getting it from the SDK tarball
|
||||
ExtractFileFromTarball(Config.SdkTarballPath, "./sdk/*/.version", outputDir);
|
||||
DirectoryInfo sdkDir = new DirectoryInfo(Path.Combine(outputDir, "sdk"));
|
||||
string sdkVersionPath = sdkDir.GetFiles(".version", SearchOption.AllDirectories).Single().FullName;
|
||||
string[] sdkVersionLines = File.ReadAllLines(Path.Combine(outputDir, sdkVersionPath));
|
||||
string expectedSdkVersion = sdkVersionLines[1];
|
||||
|
||||
Assert.Equal(expectedSdkVersion, sdkVersion);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.Delete(outputDir, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExtractFileFromTarball(string tarballPath, string filePath, string outputDir)
|
||||
{
|
||||
ExecuteHelper.ExecuteProcessValidateExitCode("tar", $"xzf {tarballPath} -C {outputDir} {filePath}", OutputHelper);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue