Skip to content

Commit e65d042

Browse files
Add alpine source build CI leg (#15765)
1 parent 32e5438 commit e65d042

File tree

7 files changed

+89
-11
lines changed

7 files changed

+89
-11
lines changed

eng/pipelines/templates/stages/vmr-build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ parameters:
1313

1414
# The following parameters aren't expected to be passed in rather they are used for encapsulation
1515
# -----------------------------------------------------------------------------------------------
16+
alpine317Container: mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.17
1617
centOSStream8Container: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-stream8
1718
centOSStream9Container: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-stream9
1819
debian11Arm64Container: mcr.microsoft.com/dotnet-buildtools/prereqs:debian-11-arm64v8
@@ -65,6 +66,9 @@ stages:
6566
value: ${{ replace(replace(variables['Build.SourceBranch'], 'refs/heads/', ''), 'refs/pull/', '') }}
6667

6768
jobs:
69+
70+
# PR and CI legs ------------------------------------
71+
6872
- template: ../jobs/vmr-build.yml
6973
parameters:
7074
buildName: CentOSStream8_Online_MsftSdk
@@ -84,6 +88,27 @@ stages:
8488
withPreviousSDK: false # 🚫
8589

8690
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
91+
92+
# CI - Stage 1 x64 legs ------------------------------------
93+
94+
- template: ../jobs/vmr-build.yml
95+
parameters:
96+
buildName: Alpine317_Offline_MsftSdk
97+
isBuiltFromVmr: ${{ parameters.isBuiltFromVmr }}
98+
vmrBranch: ${{ variables.VmrBranch }}
99+
architecture: x64
100+
pool:
101+
name: ${{ variables.defaultPoolName }}
102+
demands: ${{ variables.defaultPoolDemands }}
103+
container: ${{ parameters.alpine317Container }}
104+
buildFromArchive: false #
105+
enablePoison: false # 🚫
106+
excludeOmniSharpTests: true #
107+
overrideDistroDisablingSha1: false # 🚫
108+
runOnline: false # 🚫
109+
useMonoRuntime: false # 🚫
110+
withPreviousSDK: false # 🚫
111+
87112
- template: ../jobs/vmr-build.yml
88113
parameters:
89114
buildName: CentOSStream8_Online_PreviousSourceBuiltSdk
@@ -192,6 +217,8 @@ stages:
192217
useMonoRuntime: false # 🚫
193218
withPreviousSDK: false # 🚫
194219

220+
# CI - Stage 1 arm64 Legs ------------------------------------
221+
195222
- template: ../jobs/vmr-build.yml
196223
parameters:
197224
buildName: Debian11_Offline_MsftSdk
@@ -208,6 +235,8 @@ stages:
208235
useMonoRuntime: false # 🚫
209236
withPreviousSDK: false # 🚫
210237

238+
# CI - Stage 2 x64 Legs ------------------------------------
239+
211240
- template: ../jobs/vmr-build.yml
212241
parameters:
213242
buildName: CentOSStream8_Online_CurrentSourceBuiltSdk

src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/DotNetHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public DotNetHelper(ITestOutputHelper outputHelper)
3636
}
3737

3838
Directory.CreateDirectory(Config.DotNetDirectory);
39-
ExecuteHelper.ExecuteProcessValidateExitCode("tar", $"xzf {Config.SdkTarballPath} -C {Config.DotNetDirectory}", outputHelper);
39+
Utilities.ExtractTarball(Config.SdkTarballPath, Config.DotNetDirectory);
4040
}
4141
IsMonoRuntime = DetermineIsMonoRuntime(Config.DotNetDirectory);
4242

src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/Microsoft.DotNet.SourceBuild.SmokeTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="7.0.0" />
1213
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
1314
<PackageReference Include="xunit" Version="2.4.2" />
1415
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">

src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/OmniSharpTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private async Task InitializeOmniSharp()
6565
await client.DownloadFileAsync(omniSharpTarballUrl, omniSharpTarballFile, OutputHelper);
6666

6767
Directory.CreateDirectory(OmniSharpDirectory);
68-
ExecuteHelper.ExecuteProcessValidateExitCode("tar", $"xzf {omniSharpTarballFile} -C {OmniSharpDirectory}", OutputHelper);
68+
Utilities.ExtractTarball(omniSharpTarballFile, OmniSharpDirectory);
6969
}
7070
}
7171
}

src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SdkContentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private void WriteTarballFileList(string? tarballPath, string outputFileName, bo
4343
throw new InvalidOperationException($"Tarball path '{tarballPath}' does not exist.");
4444
}
4545

46-
string fileListing = ExecuteHelper.ExecuteProcessValidateExitCode("tar", $"tf {tarballPath}", OutputHelper);
46+
string fileListing = Utilities.GetTarballContentNames(tarballPath).Aggregate((a, b) => $"{a}{Environment.NewLine}{b}");
4747
fileListing = BaselineHelper.RemoveRids(fileListing, isPortable);
4848
fileListing = BaselineHelper.RemoveVersions(fileListing);
4949
IEnumerable<string> files = fileListing.Split(Environment.NewLine).OrderBy(path => path);

src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SourceBuiltArtifactsTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
26
using System.Collections.Generic;
37
using System.IO;
48
using System.Linq;
@@ -22,7 +26,7 @@ public void VerifyVersionFile()
2226
try
2327
{
2428
// Extract the .version file
25-
ExtractFileFromTarball(Config.SourceBuiltArtifactsPath, ".version", outputDir);
29+
Utilities.ExtractTarball(Config.SourceBuiltArtifactsPath, outputDir, ".version");
2630

2731
string[] versionLines = File.ReadAllLines(Path.Combine(outputDir, ".version"));
2832
Assert.Equal(2, versionLines.Length);
@@ -48,7 +52,7 @@ public void VerifyVersionFile()
4852
string sdkVersion = versionLines[1];
4953

5054
// Find the expected SDK version by getting it from the SDK tarball
51-
ExtractFileFromTarball(Config.SdkTarballPath ?? string.Empty, "./sdk/*/.version", outputDir);
55+
Utilities.ExtractTarball(Config.SdkTarballPath ?? string.Empty, outputDir, "./sdk/*/.version");
5256
DirectoryInfo sdkDir = new DirectoryInfo(Path.Combine(outputDir, "sdk"));
5357
string sdkVersionPath = sdkDir.GetFiles(".version", SearchOption.AllDirectories).Single().FullName;
5458
string[] sdkVersionLines = File.ReadAllLines(Path.Combine(outputDir, sdkVersionPath));
@@ -61,9 +65,4 @@ public void VerifyVersionFile()
6165
Directory.Delete(outputDir, recursive: true);
6266
}
6367
}
64-
65-
private void ExtractFileFromTarball(string tarballPath, string filePath, string outputDir)
66-
{
67-
ExecuteHelper.ExecuteProcessValidateExitCode("tar", $"--wildcards -xzf {tarballPath} -C {outputDir} {filePath}", OutputHelper);
68-
}
6968
}

src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/Utilities.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Microsoft.Extensions.FileSystemGlobbing;
56
using System;
7+
using System.Collections.Generic;
8+
using System.Formats.Tar;
9+
using System.IO;
10+
using System.IO.Compression;
611
using System.Threading;
712
using System.Threading.Tasks;
813
using Xunit.Abstractions;
@@ -11,6 +16,50 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests;
1116

1217
public static class Utilities
1318
{
19+
public static void ExtractTarball(string tarballPath, string outputDir)
20+
{
21+
using FileStream fileStream = File.OpenRead(tarballPath);
22+
using GZipStream decompressorStream = new(fileStream, CompressionMode.Decompress);
23+
TarFile.ExtractToDirectory(decompressorStream, outputDir, true);
24+
}
25+
26+
public static void ExtractTarball(string tarballPath, string outputDir, string targetFilePath)
27+
{
28+
Matcher matcher = new();
29+
matcher.AddInclude(targetFilePath);
30+
31+
using FileStream fileStream = File.OpenRead(tarballPath);
32+
using GZipStream decompressorStream = new(fileStream, CompressionMode.Decompress);
33+
using TarReader reader = new(decompressorStream);
34+
35+
TarEntry entry;
36+
while ((entry = reader.GetNextEntry()) is not null)
37+
{
38+
if (matcher.Match(entry.Name).HasMatches)
39+
{
40+
string outputPath = Path.Join(outputDir, entry.Name);
41+
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
42+
43+
using FileStream outputFileStream = File.Create(outputPath);
44+
entry.DataStream.CopyTo(outputFileStream);
45+
break;
46+
}
47+
}
48+
}
49+
50+
public static IEnumerable<string> GetTarballContentNames(string tarballPath)
51+
{
52+
using FileStream fileStream = File.OpenRead(tarballPath);
53+
using GZipStream decompressorStream = new(fileStream, CompressionMode.Decompress);
54+
using TarReader reader = new(decompressorStream);
55+
56+
TarEntry entry;
57+
while ((entry = reader.GetNextEntry()) is not null)
58+
{
59+
yield return entry.Name;
60+
}
61+
}
62+
1463
public static async Task RetryAsync(Func<Task> executor, ITestOutputHelper outputHelper)
1564
{
1665
await Utilities.RetryAsync(

0 commit comments

Comments
 (0)