Skip to content

Commit

Permalink
Add .NET 8 Targets (#991)
Browse files Browse the repository at this point in the history
+semver: minor
  • Loading branch information
rhysparry authored Sep 3, 2024
1 parent f162e94 commit ab76266
Show file tree
Hide file tree
Showing 34 changed files with 490 additions and 121 deletions.
69 changes: 36 additions & 33 deletions build/Build.Pack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ partial class Build
.DependsOn(BuildOsx)
.Executes(() =>
{
RuntimeIds.Where(x => x.StartsWith("osx-")).ForEach(PackTarballs);
foreach (var runtimeId in RuntimeIds.Where(x => x.StartsWith("osx-")))
{
PackTarballs(NetCore, runtimeId);
}
});

[PublicAPI]
Expand All @@ -55,7 +58,10 @@ partial class Build
.DependsOn(BuildLinux)
.Executes(() =>
{
RuntimeIds.Where(x => x.StartsWith("linux-")).ForEach(PackTarballs);
foreach (var runtimeId in RuntimeIds.Where(x => x.StartsWith("linux-")))
{
PackTarballs(NetCore, runtimeId);
}
});

[PublicAPI]
Expand Down Expand Up @@ -106,7 +112,7 @@ void CreateLinuxPackages(string runtimeId)
"SIGN_PASSPHRASE")
.SetVolume(
$"{debBuildDir / "scripts"}:/scripts",
$"{BuildDirectory / "zip" / "net6.0" / runtimeId / "tentacle"}:/input",
$"{BuildDirectory / "zip" / NetCore / runtimeId / "tentacle"}:/input",
$"{debBuildDir / "output"}:/output"
)
.SetImage(dockerToolsContainerImage)
Expand Down Expand Up @@ -264,7 +270,7 @@ void PackWindowsInstallers(MSBuildTargetPlatform platform, AbsolutePath wixNuget
(BuildDirectory / "Octopus.Manager.Tentacle" / framework / "win").GlobFiles("*")
.ForEach(x => FileSystemTasks.CopyFileToDirectory(x, installerDirectory, FileExistsPolicy.Overwrite));
}
else if (framework == NetCoreWindows)
else if (framework is NetCoreWindows)
{
(BuildDirectory / "Tentacle" / framework / $"win-{platform}").GlobFiles("*")
.ForEach(x => FileSystemTasks.CopyFileToDirectory(x, installerDirectory, FileExistsPolicy.Overwrite));
Expand Down Expand Up @@ -333,19 +339,12 @@ void BuildMsiInstallerForPlatform(MSBuildTargetPlatform platform, AbsolutePath w
var builtMsi = RootDirectory / "installer" / "Octopus.Tentacle.Installer" / "bin" / platform / "Octopus.Tentacle.msi";
Signing.Sign(builtMsi);
string platformString;
if (framework == NetFramework)
{
platformString = platform == MSBuildTargetPlatform.x64 ? "-x64" : "";
}
else if (framework == NetCoreWindows)
var platformString = framework switch
{
platformString = $"-{NetCoreWindows}-win" + (platform == MSBuildTargetPlatform.x64 ? "-x64" : "-x86");
}
else
{
platformString = $"-{NetCore}-win" + (platform == MSBuildTargetPlatform.x64 ? "-x64" : "-x86");
}
NetFramework => platform == MSBuildTargetPlatform.x64 ? "-x64" : "",
NetCoreWindows => $"-{framework}-win" + (platform == MSBuildTargetPlatform.x64 ? "-x64" : "-x86"),
_ => $"-{framework}-win" + (platform == MSBuildTargetPlatform.x64 ? "-x64" : "-x86")
};
FileSystemTasks.MoveFile(
builtMsi,
Expand Down Expand Up @@ -467,13 +466,14 @@ string ConstructRedHatPackageFilename(string packageName, string architecture)
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}.msi", workingDirectory / "Octopus.Tentacle.msi");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-x64.msi", workingDirectory / "Octopus.Tentacle-x64.msi");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-net6.0-win-x86.msi", workingDirectory / "Octopus.Tentacle-net6.0-win-x86.msi");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-net6.0-win-x64.msi", workingDirectory / "Octopus.Tentacle-net6.0-win-x64.msi");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-net6.0-windows-win-x86.msi", workingDirectory / "Octopus.Tentacle-net6.0-windows-win-x86.msi");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-net6.0-windows-win-x64.msi", workingDirectory / "Octopus.Tentacle-net6.0-windows-win-x64.msi");
FileSystemTasks.CopyFile(BuildDirectory / "Octopus.Tentacle.Upgrader" / NetCore / "win-x86" / "Octopus.Tentacle.Upgrader.exe", workingDirectory / "Octopus.Tentacle.Upgrader-net6.0-win-x86.exe");
FileSystemTasks.CopyFile(BuildDirectory / "Octopus.Tentacle.Upgrader" / NetCore / "win-x64" / "Octopus.Tentacle.Upgrader.exe", workingDirectory / "Octopus.Tentacle.Upgrader-net6.0-win-x64.exe");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-net8.0-win-x86.msi", workingDirectory / "Octopus.Tentacle-net8.0-win-x86.msi");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-net8.0-win-x64.msi", workingDirectory / "Octopus.Tentacle-net8.0-win-x64.msi");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-net8.0-windows-win-x86.msi", workingDirectory / "Octopus.Tentacle-net8.0-windows-win-x86.msi");
FileSystemTasks.CopyFile(ArtifactsDirectory / "msi" / $"Octopus.Tentacle.{FullSemVer}-net8.0-windows-win-x64.msi", workingDirectory / "Octopus.Tentacle-net8.0-windows-win-x64.msi");
FileSystemTasks.CopyFile(BuildDirectory / "Octopus.Tentacle.Upgrader" / NetCore / "win-x86" / "Octopus.Tentacle.Upgrader.exe", workingDirectory / "Octopus.Tentacle.Upgrader-net8.0-win-x86.exe");
FileSystemTasks.CopyFile(BuildDirectory / "Octopus.Tentacle.Upgrader" / NetCore / "win-x64" / "Octopus.Tentacle.Upgrader.exe", workingDirectory / "Octopus.Tentacle.Upgrader-net8.0-win-x64.exe");
var octopusTentacleUpgraderDirectory = BuildDirectory / "Octopus.Tentacle.Upgrader" / NetFramework / "win";
octopusTentacleUpgraderDirectory.GlobFiles("*").ForEach(x => FileSystemTasks.CopyFileToDirectory(x, workingDirectory));
Expand Down Expand Up @@ -504,13 +504,16 @@ string ConstructRedHatPackageFilename(string packageName, string architecture)
Assert.True((workingDirectory / "Octopus.Tentacle.msi").FileExists(), "Missing Octopus.Tentacle.msi");
Assert.True((workingDirectory / "Octopus.Tentacle-x64.msi").FileExists(), "Missing Octopus.Tentacle-x64.msi");
Assert.True((workingDirectory / "Octopus.Tentacle-net6.0-win-x86.msi").FileExists(), "Missing Octopus.Tentacle-net6.0-win-x86.msi");
Assert.True((workingDirectory / "Octopus.Tentacle-net6.0-win-x64.msi").FileExists(), "Missing Octopus.Tentacle-net6.0-win-x64.msi");
Assert.True((workingDirectory / "Octopus.Tentacle-net6.0-windows-win-x86.msi").FileExists(), "Missing Octopus.Tentacle-net6.0-windows-win-x86.msi");
Assert.True((workingDirectory / "Octopus.Tentacle-net6.0-windows-win-x64.msi").FileExists(), "Missing Octopus.Tentacle-net6.0-windows-win-x64.msi");
Assert.True((workingDirectory / "Octopus.Tentacle.Upgrader.exe").FileExists(), "Missing Octopus.Tentacle.Upgrader.exe");
Assert.True((workingDirectory / "Octopus.Tentacle.Upgrader-net6.0-win-x86.exe").FileExists(), "Missing Octopus.Tentacle.Upgrader-net6.0-win-x86.exe");
Assert.True((workingDirectory / "Octopus.Tentacle.Upgrader-net6.0-win-x64.exe").FileExists(), "Missing Octopus.Tentacle.Upgrader-net6.0-win-x64.exe");
foreach (var framework in new[] {NetCore})
{
Assert.True((workingDirectory / $"Octopus.Tentacle-{framework}-win-x86.msi").FileExists(), $"Missing Octopus.Tentacle-{framework}-win-x86.msi");
Assert.True((workingDirectory / $"Octopus.Tentacle-{framework}-win-x64.msi").FileExists(), $"Missing Octopus.Tentacle-{framework}-win-x64.msi");
Assert.True((workingDirectory / $"Octopus.Tentacle-{framework}-windows-win-x86.msi").FileExists(), $"Missing Octopus.Tentacle-{framework}-windows-win-x86.msi");
Assert.True((workingDirectory / $"Octopus.Tentacle-{framework}-windows-win-x64.msi").FileExists(), $"Missing Octopus.Tentacle-{framework}-windows-win-x64.msi");
Assert.True((workingDirectory / $"Octopus.Tentacle.Upgrader-{framework}-win-x86.exe").FileExists(), $"Missing Octopus.Tentacle.Upgrader-{framework}-win-x86.exe");
Assert.True((workingDirectory / $"Octopus.Tentacle.Upgrader-{framework}-win-x64.exe").FileExists(), $"Missing Octopus.Tentacle.Upgrader-{framework}-win-x64.exe");
}
Assert.True((workingDirectory / debAmd64PackageFilename).FileExists(), $"Missing {debAmd64PackageFilename}");
Assert.True((workingDirectory / debArm64PackageFilename).FileExists(), $"Missing {debArm64PackageFilename}");
Assert.True((workingDirectory / debArm32PackageFilename).FileExists(), $"Missing {debArm32PackageFilename}");
Expand Down Expand Up @@ -540,15 +543,15 @@ string ConstructRedHatPackageFilename(string packageName, string architecture)
.DependsOn(PackContracts)
.DependsOn(PackClient);

void PackTarballs(string runtimeId)
void PackTarballs(string framework, string runtimeId)
{
(ArtifactsDirectory / "zip").CreateDirectory();

var workingDir = BuildDirectory / "zip" / NetCore / runtimeId;
var workingDir = BuildDirectory / "zip" / framework / runtimeId;
(workingDir / "tentacle").CreateDirectory();

var linuxPackagesContent = RootDirectory / "linux-packages" / "content";
var tentacleDirectory = BuildDirectory / "Tentacle" / NetCore / runtimeId;
var tentacleDirectory = BuildDirectory / "Tentacle" / framework / runtimeId;

linuxPackagesContent.GlobFiles("*")
.ForEach(x => FileSystemTasks.CopyFileToDirectory(x, workingDir / "tentacle"));
Expand All @@ -559,7 +562,7 @@ void PackTarballs(string runtimeId)
workingDir,
"tentacle",
ArtifactsDirectory / "zip",
$"tentacle-{FullSemVer}-{NetCore}-{runtimeId}.tar.gz");
$"tentacle-{FullSemVer}-{framework}-{runtimeId}.tar.gz");
}

void BuildAndPushOrLoadKubernetesTentacleContainerImage(bool push, bool load, string? host = null, bool includeDebugger = false)
Expand Down Expand Up @@ -627,4 +630,4 @@ string GetMicrok8sIpAddress()
{ "linux-arm64", ("arm64", "arm64") },
{ "linux-arm", ("armhf", "armv7") }
};
}
}
6 changes: 1 addition & 5 deletions build/Build.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ void RunLinuxPackageTestsFor(TestConfigurationOnLinuxDistribution testConfigurat
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "ubuntu:focal", "deb"), // 20.04
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "ubuntu:bionic", "deb"), // 18.04
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "ubuntu:xenial", "deb"), // 16.04
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "ubuntu:trusty", "deb"), // 14.04
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "centos:7", "rpm"),
// new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "fedora:latest", "rpm"), // Fedora 36 doesn't support netcore, related https://github.com/dotnet/core/issues/7467 (there is no issue for Fedora 36)
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "fedora:35", "rpm"),
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "roboxes/rhel7", "rpm"),
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "fedora:39", "rpm"),
new TestConfigurationOnLinuxDistribution(NetCore, "linux-x64", "roboxes/rhel8", "rpm"),
};
Expand Down
19 changes: 13 additions & 6 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public Build()
readonly AbsolutePath TestDirectory = RootDirectory / "_test";

const string NetFramework = "net48";
const string NetCore = "net6.0";
const string NetCoreWindows = "net6.0-windows";
const string NetCore = "net8.0";
const string NetCoreWindows = "net8.0-windows";

IEnumerable<string> RuntimeIds => SpecificRuntimeId != null
? new[] { SpecificRuntimeId }
Expand Down Expand Up @@ -206,7 +206,10 @@ public Build()
using var productWxsFile = UpdateMsiProductVersion();
RuntimeIds.Where(x => x.StartsWith("linux-"))
.ForEach(runtimeId => RunBuildFor(NetCore, runtimeId));
.ForEach(runtimeId =>
{
RunBuildFor(NetCore, runtimeId);
});
versionInfoFile.Dispose();
productWxsFile.Dispose();
Expand All @@ -222,7 +225,10 @@ public Build()
using var productWxsFile = UpdateMsiProductVersion();
RuntimeIds.Where(x => x.StartsWith("osx-"))
.ForEach(runtimeId => RunBuildFor(NetCore, runtimeId));
.ForEach(runtimeId =>
{
RunBuildFor(NetCore, runtimeId);
});
versionInfoFile.Dispose();
productWxsFile.Dispose();
Expand Down Expand Up @@ -288,6 +294,7 @@ ModifiableFileWithRestoreContentsOnDispose ModifyTemplatedVersionAndProductFiles
ModifiableFileWithRestoreContentsOnDispose UpdateMsiProductVersion()
{
var productWxsFilePath = RootDirectory / "installer" / "Octopus.Tentacle.Installer" / "Product.wxs";
var productWxsFile = new ModifiableFileWithRestoreContentsOnDispose(productWxsFilePath);

var xmlDoc = new XmlDocument();
xmlDoc.Load(productWxsFilePath);
Expand All @@ -305,7 +312,7 @@ ModifiableFileWithRestoreContentsOnDispose UpdateMsiProductVersion()

xmlDoc.Save(productWxsFilePath);

return new ModifiableFileWithRestoreContentsOnDispose(productWxsFilePath);
return productWxsFile;
}

void RunBuildFor(string framework, string runtimeId)
Expand Down Expand Up @@ -342,4 +349,4 @@ void TarGZipCompress(AbsolutePath inputDirectory, string fileSpec, AbsolutePath
}

public static int Main() => Execute<Build>(x => x.Default);
}
}
11 changes: 11 additions & 0 deletions build/ModifiableFileWithRestoreContentsOnDispose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ModifiableFileWithRestoreContentsOnDispose : IDisposable
public readonly AbsolutePath FilePath;
readonly string OriginalFileText;
string FileText;
bool disposed = false;

public ModifiableFileWithRestoreContentsOnDispose(AbsolutePath filePath)
{
Expand All @@ -20,6 +21,16 @@ public ModifiableFileWithRestoreContentsOnDispose(AbsolutePath filePath)
}

public void Dispose()
{
if (disposed)
{
return;
}
disposed = true;
RestoreContents();
}

public void RestoreContents()
{
Log.Information($"Restoring file {FilePath}");
File.WriteAllText(FilePath, OriginalFileText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $SCRIPT_DIR/setup-vm-agent.sh

source $SCRIPT_DIR/set-dotnet-envvars.sh

itdll=`pwd`/build/outputs/integrationtests/net6.0/linux-x64/Octopus.Tentacle.Tests.Integration.dll
itdll=`pwd`/build/outputs/integrationtests/${TARGET_FRAMEWORK:-net8.0}/linux-x64/Octopus.Tentacle.Tests.Integration.dll


# We don't care about the exit code of dotnet test and instead depend on tests passing.
Expand Down
3 changes: 1 addition & 2 deletions build/test-scripts/integration/common/setup-vm-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

source $SCRIPT_DIR/dotnet-install.sh
# We install the 8.0 sdk and also the 6.0 runtime as the tests require it
install_dotnet --runtime 6.0 --sdk 8.0
install_dotnet 8.0
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $SCRIPT_DIR/common/setup-vm-agent.sh

source $SCRIPT_DIR/common/set-dotnet-envvars.sh

itdll=`pwd`/build/outputs/integrationtests/net6.0/linux-x64/Octopus.Tentacle.Kubernetes.Tests.Integration.dll
itdll=`pwd`/build/outputs/integrationtests/${TARGET_FRAMEWORK:-net8.0}/linux-x64/Octopus.Tentacle.Kubernetes.Tests.Integration.dll


# We don't care about the exit code of dotnet test and instead depend on tests passing.
Expand All @@ -22,4 +22,4 @@ if [ "$TENTACLE_IT_WITH_SUDO" = "1" ]; then
sudo -E env PATH=$PATH dotnet vstest $itdll "/testcasefilter:TestCategory!=TentacleBackwardsCompatibility" /logger:logger://teamcity /TestAdapterPath:/opt/TeamCity/BuildAgent/plugins/dotnet/tools/vstest15 /logger:console;verbosity=detailed
else
dotnet vstest $itdll "/testcasefilter:TestCategory!=RequiresSudoOnLinux&TestCategory!=TentacleBackwardsCompatibility" /logger:logger://teamcity /TestAdapterPath:/opt/TeamCity/BuildAgent/plugins/dotnet/tools/vstest15 /logger:console;verbosity=detailed
fi
fi
4 changes: 4 additions & 0 deletions source/Octopus.Manager.Tentacle.Tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#if NET8_0_OR_GREATER
using System.Runtime.Versioning;
[assembly: SupportedOSPlatform("windows")]
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<LangVersion>9</LangVersion>
<Nullable>annotations</Nullable>
<TargetFrameworks>net48;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net48;net6.0-windows;net8.0-windows</TargetFrameworks>
<!-- Following the recommended action from https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/duplicate-files-in-output -->
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>

Expand All @@ -26,6 +27,11 @@
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
</PropertyGroup>
</When>
<When Condition="'$(TargetFramework)' == 'net8.0-windows'">
<PropertyGroup>
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
</PropertyGroup>
</When>
</Choose>

<ItemGroup>
Expand Down
Loading

0 comments on commit ab76266

Please sign in to comment.