Skip to content

Commit 38332e1

Browse files
committed
Use files not env
1 parent 161666a commit 38332e1

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

src/Runner.Listener/SelfUpdater.cs

+31-19
Original file line numberDiff line numberDiff line change
@@ -188,35 +188,47 @@ private async Task DownloadLatestRunner(CancellationToken token)
188188
// This should not be in the release build to prevent tampering with updates
189189
var isMockUpdate = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_IS_MOCK_UPDATE"));
190190
if (isMockUpdate)
191-
{ int waitInSeconds = 20;
191+
{
192+
int waitInSeconds = 20;
192193
while (!Debugger.IsAttached && waitInSeconds-- > 0)
193194
{
194195
await Task.Delay(1000);
195196
}
196197
Debugger.Break();
197-
// the env var should be of format GITHUB_ACTIONS_RUNNER_MOCK_VERSION_LIST='v2.281.2,v2.283.0,v2.283.1,v2.284.0'
198-
var mockVersions = Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_MOCK_VERSION_LIST").Split(',');
199-
200-
_terminal.WriteLine(string.Join(",", mockVersions));
201-
if (mockVersions.Any())
198+
// the runner-mock-versions.txt file should be of format
199+
// v2.281.2
200+
// v2.283.0
201+
// v2.283.1
202+
// v2.284.0
203+
var mockVersionsPath = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), "runner-mock-versions.txt");
204+
if (File.Exists(mockVersionsPath))
202205
{
203-
var targetVersion = mockVersions.First();
206+
var mockVersions = File.ReadAllLines(Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), "runner-mock-versions.txt"));
204207

205-
if (_targetPackage.Platform.StartsWith("win"))
206-
{
207-
archiveFile = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), $"runner{targetVersion}.zip");
208-
}
209-
else
208+
_terminal.WriteLine(string.Join(",", mockVersions));
209+
if (mockVersions.Any())
210210
{
211-
archiveFile = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), $"runner{targetVersion}.tar.gz");
212-
}
211+
var targetVersion = mockVersions.First();
213212

214-
_terminal.WriteLine($"Mock target version is: {targetVersion}");
213+
if (_targetPackage.Platform.StartsWith("win"))
214+
{
215+
archiveFile = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), $"runner{targetVersion}.zip");
216+
}
217+
else
218+
{
219+
archiveFile = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), $"runner{targetVersion}.tar.gz");
220+
}
221+
222+
_terminal.WriteLine($"Mock target version is: {targetVersion}");
215223

216-
var newMockVersions = string.Join(",", mockVersions.Skip(1));
217-
Environment.SetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_MOCK_VERSION_LIST", newMockVersions);
218-
_updateTrace.Add($"Mocking update with file: {archiveFile}, nothing is downloaded");
219-
_terminal.WriteLine($"Mocking update with file: {archiveFile}, nothing is downloaded");
224+
File.Delete(mockVersionsPath);
225+
if(mockVersions.Length > 1)
226+
{
227+
File.WriteAllLines(mockVersionsPath, mockVersions.Skip(1));
228+
}
229+
_updateTrace.Add($"Mocking update with file: {archiveFile}, nothing is downloaded");
230+
_terminal.WriteLine($"Mocking update with file: {archiveFile}, nothing is downloaded");
231+
}
220232
}
221233
}
222234
// archiveFile is not null only if we mocked it above

0 commit comments

Comments
 (0)