mirror of
https://github.com/actions/runner.git
synced 2025-12-10 20:36:49 +00:00
* Added Snapshot TemplateToken to AgentJobRequestMessage * WIP for processing the snapshot token * Changed snapshot post job step condition to Success, added comments * Refactored snapshot post-job step * Added evaluation of snapshot token to retrieve image name * Added snapshot to workflow schema * Fixed linter error * Migrated snapshot logic to new SnapshotOperationProvider * Fixed linter error * Fixed linter errors * Fixed linter error * Fixed linter errors * Updated L0 tests * Fixed linter errors * Added new JobExtensionL0 tests for snapshot post-job step * Added JobExtensionL0 test case for snapshot mappings * Added SnapshotOperationProviderL0 tests * Enabled nullable types for SnapshotOperationProvider and its tests * Added more assertions to SnapshotOperationProviderL0 tests * Fixed linter errors * Made sure TestHostContexts are disposed of properlyh in SnapshotOperationProviderL0 tests * Resolved PR comments * Fixed formatting * Removed redundant reference * Addressed PR comments
33 lines
1.5 KiB
C#
33 lines
1.5 KiB
C#
#nullable enable
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using GitHub.DistributedTask.Pipelines;
|
|
using GitHub.Runner.Common;
|
|
using GitHub.Runner.Sdk;
|
|
namespace GitHub.Runner.Worker;
|
|
|
|
[ServiceLocator(Default = typeof(SnapshotOperationProvider))]
|
|
public interface ISnapshotOperationProvider : IRunnerService
|
|
{
|
|
Task CreateSnapshotRequestAsync(IExecutionContext executionContext, Snapshot snapshotRequest);
|
|
}
|
|
|
|
public class SnapshotOperationProvider : RunnerService, ISnapshotOperationProvider
|
|
{
|
|
public Task CreateSnapshotRequestAsync(IExecutionContext executionContext, Snapshot snapshotRequest)
|
|
{
|
|
var snapshotRequestFilePath = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), ".snapshot", "request.json");
|
|
var snapshotRequestDirectoryPath = Path.GetDirectoryName(snapshotRequestFilePath);
|
|
if (snapshotRequestDirectoryPath != null)
|
|
{
|
|
Directory.CreateDirectory(snapshotRequestDirectoryPath);
|
|
}
|
|
|
|
IOUtil.SaveObject(snapshotRequest, snapshotRequestFilePath);
|
|
executionContext.Output($"Request written to: {snapshotRequestFilePath}");
|
|
executionContext.Output("This request will be processed after the job completes. You will not receive any feedback on the snapshot process within the workflow logs of this job.");
|
|
executionContext.Output("If the snapshot process is successful, you should see a new image with the requested name in the list of available custom images when creating a new GitHub-hosted Runner.");
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|