Skip to content

Commit 6fabd82

Browse files
committed
Allow mocked updates
1 parent 9bfbc48 commit 6fabd82

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/Runner.Listener/SelfUpdater.cs

+27-5
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,36 @@ private async Task DownloadLatestRunner(CancellationToken token)
182182

183183
try
184184
{
185-
archiveFile = await DownLoadRunner(latestRunnerDirectory, packageDownloadUrl, packageHashValue, token);
186-
187-
if (string.IsNullOrEmpty(archiveFile))
185+
#if DEBUG
186+
// Much of the update process (targetVersion, archive) is server-side, this is a way to control it from here for testing specific update scenarios
187+
// Add files like 'runner_v2.281.2.tar.gz' or 'runner_v2.283.0.zip' depending on your platform in your runner root folder
188+
var isMockUpdate = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_IS_MOCK_UPDATE"));
189+
if (isMockUpdate)
188190
{
189-
throw new TaskCanceledException($"Runner package '{packageDownloadUrl}' failed after {Constants.RunnerDownloadRetryMaxAttempts} download attempts");
191+
// the env var should be of format 'v2.281.2,v2.283.0,v2.283.1,v2.284.0'
192+
var mockVersions = Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_MOCK_VERSION_LIST").Split(',');
193+
if (mockVersions.Any())
194+
{
195+
var targetVersion = mockVersions.First();
196+
archiveFile = "runner_" + targetVersion;
197+
var newMockVersions = string.Join(",", mockVersions.Skip(1));
198+
Environment.SetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_MOCK_VERSION_LIST", newMockVersions);
199+
_updateTrace.Add($"Mocking update with file: {archiveFile}, nothing is downloaded");
200+
}
190201
}
202+
#else
203+
// archiveFile is not null only if we mocked it above
204+
if (archiveFile == null)
205+
{
206+
archiveFile = await DownLoadRunner(latestRunnerDirectory, packageDownloadUrl, packageHashValue, token);
191207

192-
await ValidateRunnerHash(archiveFile, packageHashValue);
208+
if (string.IsNullOrEmpty(archiveFile))
209+
{
210+
throw new TaskCanceledException($"Runner package '{packageDownloadUrl}' failed after {Constants.RunnerDownloadRetryMaxAttempts} download attempts");
211+
}
212+
await ValidateRunnerHash(archiveFile, packageHashValue);
213+
}
214+
#endif
193215

194216
await ExtractRunnerPackage(archiveFile, latestRunnerDirectory, token);
195217
}

0 commit comments

Comments
 (0)