Skip to content

Commit

Permalink
Try to reuse artifacts directory
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Nov 9, 2024
1 parent b1a1018 commit 460d44b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Runner/JobBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,24 @@ private async Task PostAsJsonAsync(string path, object? value, string? queryArgs
}
}

protected static string GetRoughSizeString(long size)
{
double kb = size / 1024d;
double mb = kb / 1024d;

if (mb >= 1)
{
return $"{(int)mb} MB";
}

if (kb >= 1)
{
return $"{(int)kb} KB";
}

return $"{size} B";
}

protected int GetTotalSystemMemoryGB()
{
var memory = _hardwareInfo?.MemoryStatus;
Expand Down
48 changes: 47 additions & 1 deletion Runner/Jobs/JitDiffJob.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Runner.Jobs;
using Azure.Storage.Blobs.Models;
using System.IO.Compression;

namespace Runner.Jobs;

internal sealed class JitDiffJob : JobBase
{
Expand All @@ -15,8 +18,12 @@ protected override async Task RunJobCoreAsync()

await CloneRuntimeAndSetupToolsAsync(this);

await TryDownloadPreviousBuildArtifactsAsync();

await BuildAndCopyRuntimeBranchBitsAsync(this, "main");

await UploadBuildArtifactsAsync();

await RunProcessAsync("git", "switch pr", workDir: "runtime");

await BuildAndCopyRuntimeBranchBitsAsync(this, "pr");
Expand Down Expand Up @@ -96,6 +103,45 @@ public static async Task BuildAndCopyRuntimeBranchBitsAsync(JobBase job, string
await copyReleaseBitsTask;
}

private async Task TryDownloadPreviousBuildArtifactsAsync()
{
try
{
var artifactsBlob = PersistentStateClient.GetBlobClient("runtime-artifacts-main.zip");
if (await artifactsBlob.ExistsAsync(JobTimeout))
{
await LogAsync($"Downloading previous artifacts ...");
var content = (await artifactsBlob.DownloadContentAsync(JobTimeout)).Value;

await LogAsync($"Extracting previous artifacts ({GetRoughSizeString(content.Details.ContentLength)}) ...");
ZipFile.ExtractToDirectory(content.Content.ToStream(), "runtime/artifacts");
}
}
catch (Exception ex)
{
await LogAsync($"Failed to download previous artifacts: {ex}");
}
}

private async Task UploadBuildArtifactsAsync()
{
try
{
await LogAsync($"Compressing artifacts directory ...");
using var ms = new MemoryStream(512 * 1024 * 1024);
ZipFile.CreateFromDirectory("runtime/artifacts", ms, CompressionLevel.Optimal, includeBaseDirectory: false);
ms.Position = 0;

await LogAsync($"Uploading artifacts directory ({GetRoughSizeString(ms.Length)}) ...");
var artifactsBlob = PersistentStateClient.GetBlobClient("runtime-artifacts-main.zip");
await artifactsBlob.UploadAsync(ms, overwrite: true, JobTimeout);
}
catch (Exception ex)
{
await LogAsync($"Failed to upload artifacts: {ex}");
}
}

private async Task<string> CollectFrameworksDiffsAsync()
{
try
Expand Down

0 comments on commit 460d44b

Please sign in to comment.