Skip to content

Commit

Permalink
Using new octopus cli to pack cross-platform bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysparry committed Nov 8, 2024
1 parent 09e1d68 commit 4d5ee41
Showing 1 changed file with 63 additions and 9 deletions.
72 changes: 63 additions & 9 deletions build/Build.Pack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 4d5ee41

Please sign in to comment.