Skip to content

Commit

Permalink
Update build pipeline to include tar.gz artefacts (#374)
Browse files Browse the repository at this point in the history
* Output tar.gz for non windows platform

* Rename sha256 output file to match the full name of the target

* Always create zip for all platforms

---------

Co-authored-by: fluxzy-ci <[email protected]>
  • Loading branch information
haga-rak and fluxzy-ci authored Feb 2, 2025
1 parent 1ed8c02 commit 63eb78d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
47 changes: 47 additions & 0 deletions build/Fluxzy.Build/CompressionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2021 - Haga Rakotoharivelo - https://github.com/haga-rak

using System.Formats.Tar;
using System.IO.Compression;
using System.Runtime.InteropServices;

namespace Fluxzy.Build
{
public static class CompressionHelper
{
internal static void CreateZip(string inputDirectory, string outputFile)
{
// add extension if missing

if (!outputFile.EndsWith(".zip"))
{
outputFile += ".zip";
}

ZipFile.CreateFromDirectory(inputDirectory, outputFile, CompressionLevel.Optimal,
includeBaseDirectory:false);
}

public static void CreateCompressed(string inputDirectory, string outputFile)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
CreateTarGz(inputDirectory, outputFile);
}

CreateZip(inputDirectory, outputFile);
}

internal static void CreateTarGz(string inputDirectory, string outputFile)
{
if (!outputFile.EndsWith(".tar.gz"))
{
outputFile += ".tar.gz";
}

using FileStream fs = new(outputFile, FileMode.CreateNew, FileAccess.Write);
using GZipStream gz = new(fs, CompressionMode.Compress, leaveOpen: true);

TarFile.CreateFromDirectory(inputDirectory, gz, includeBaseDirectory: false);
}
}
}
2 changes: 1 addition & 1 deletion build/Fluxzy.Build/GhPublishHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public async Task<bool> AddAssets(string tagName, IEnumerable<FileInfo> fileInfo
{
using var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(HashHelper.GetWinGetHash(fileInfo)));

var hashPayload = new ReleaseAssetUpload(Path.GetFileNameWithoutExtension(fileInfo.Name) + ".sha256",
var hashPayload = new ReleaseAssetUpload($"{fileInfo.Name}.sha256",
"text/plain", memoryStream, null);

await client.Repository.Release.UploadAsset(release, hashPayload);
Expand Down
10 changes: 3 additions & 7 deletions build/Fluxzy.Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static async Task<string> GetRunningVersionShort()

private static string GetFileName(string runtimeIdentifier, string version)
{
return $"fluxzy-cli-{version}-{runtimeIdentifier}.zip";
return $"fluxzy-cli-{version}-{runtimeIdentifier}";
}

private static async Task Upload(FileInfo fullFile)
Expand Down Expand Up @@ -269,12 +269,8 @@ await RunAsync("dotnet",
foreach (var runtimeIdentifier in TargetRuntimeIdentifiers[current]) {
var outDirectory = $".artefacts/{runtimeIdentifier}";

ZipFile.CreateFromDirectory(
outDirectory,
$".artefacts/final/{GetFileName(runtimeIdentifier, runningVersion)}",
CompressionLevel.Optimal,
false
);
CompressionHelper.CreateCompressed(outDirectory,
$".artefacts/final/{GetFileName(runtimeIdentifier, runningVersion)}");
}
});

Expand Down

0 comments on commit 63eb78d

Please sign in to comment.