From 4d5ee417ea3773b085efa265d02ba5668c11e32c Mon Sep 17 00:00:00 2001 From: Rhys Parry Date: Fri, 8 Nov 2024 14:01:54 +1000 Subject: [PATCH] Using new octopus cli to pack cross-platform bundle --- build/Build.Pack.cs | 72 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/build/Build.Pack.cs b/build/Build.Pack.cs index f380b34f4..2871d19e3 100644 --- a/build/Build.Pack.cs +++ b/build/Build.Pack.cs @@ -538,15 +538,15 @@ string ConstructRedHatPackageFilename(string packageName, string architecture) const string author = "Octopus Deploy"; const string title = "Octopus Tentacle cross platform bundle"; - OctopusTasks.OctopusPack(o => o - .SetId("Octopus.Tentacle.CrossPlatformBundle") - .SetVersion(FullSemVer) - .SetBasePath(workingDirectory) - .SetOutputFolder(ArtifactsDirectory / "nuget") - .SetAuthors(author) - .SetTitle(title) - .SetDescription(description) - ); + const string id = "Octopus.Tentacle.CrossPlatformBundle"; + var outFolder = ArtifactsDirectory / "nuget"; + + var octopus = InstallOctopusCli(); + // Note: Nuke automatically escapes this string by using the string interpolation syntax + ProcessTasks.StartProcess( + octopus, + $"package nuget create --id {id} --version {FullSemVer} --base-path {workingDirectory} --out-folder {outFolder} --author {author} --title {title} --description {description}" + ).WaitForExit(); }); [PublicAPI] @@ -649,4 +649,58 @@ string GetMicrok8sIpAddress() { "linux-arm64", ("arm64", "arm64") }, { "linux-arm", ("armhf", "armv7") } }; + + AbsolutePath InstallOctopusCli() + { + const string cliVersion = "2.11.0"; + + // Windows uses octopus.exe, everything else uses octopus + var cliName = EnvironmentInfo.IsWin ? "octopus.exe" : "octopus"; + + var unversionedCliFolder = TemporaryDirectory / "octopus-cli"; + var cliFolder = unversionedCliFolder / cliVersion; + var cliPath = cliFolder / cliName; + if (cliPath.FileExists()) + { + // Assume it has already been installed + return cliPath; + } + + cliFolder.CreateDirectory(); + + var osId = true switch + { + _ when EnvironmentInfo.IsWin => "windows", + _ when EnvironmentInfo.IsOsx => "macOS", + _ when EnvironmentInfo.IsLinux => "linux", + _ => throw new NotSupportedException("Unsupported OS") + }; + + var archId = EnvironmentInfo.IsArm64 + ? "arm64" + : "amd64"; + + var archiveExtension = EnvironmentInfo.IsWin ? "zip" : "tar.gz"; + + var downloadUri = $"https://github.com/OctopusDeploy/cli/releases/download/v{cliVersion}/octopus_{cliVersion}_{osId}_{archId}.{archiveExtension}"; + + var archiveDestination = unversionedCliFolder / $"octopus-cli-archive.{cliVersion}.{archiveExtension}"; + + // If the archive already exists, we will download it again + archiveDestination.DeleteFile(); + + Log.Information("Downloading Octopus CLI from {downloadUri}", downloadUri); + HttpTasks.HttpDownloadFile(downloadUri, archiveDestination); + + archiveDestination.UncompressTo(cliFolder); + + if (!EnvironmentInfo.IsWin) + { + // We need to make the file executable as Nuke doesn't do that for us + ProcessTasks.StartProcess("chmod", $"+x {cliPath}").WaitForExit(); + } + + Assert.FileExists(cliPath, "The Octopus CLI executable was not found after extracting the archive"); + return cliPath; + } }