Skip to content

Commit

Permalink
Use private field for script path
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussell committed Dec 17, 2024
1 parent 97c2c9d commit 5e7d906
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions eng/update-dependencies/ScriptRunnerUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@ namespace Dotnet.Docker
/// </summary>
public class ScriptRunnerUpdater : IDependencyUpdater
{
public required string ScriptPath { get; init; }
private readonly string _scriptPath;

private ScriptRunnerUpdater()
private ScriptRunnerUpdater(string scriptPath)
{
_scriptPath = scriptPath;
}

public static IDependencyUpdater GetDockerfileUpdater(string repoRoot)
{
return new ScriptRunnerUpdater()
{
ScriptPath = Path.Combine(repoRoot, "eng", "dockerfile-templates", "Get-GeneratedDockerfiles.ps1")
};
string scriptPath = Path.Combine(repoRoot, "eng", "dockerfile-templates", "Get-GeneratedDockerfiles.ps1");
return new ScriptRunnerUpdater(scriptPath);
}

public static IDependencyUpdater GetReadMeUpdater(string repoRoot)
{
return new ScriptRunnerUpdater()
{
ScriptPath = Path.Combine(repoRoot, "eng", "readme-templates", "Get-GeneratedReadmes.ps1")
};
string scriptPath = Path.Combine(repoRoot, "eng", "readme-templates", "Get-GeneratedReadmes.ps1");
return new ScriptRunnerUpdater(scriptPath);
}

public IEnumerable<DependencyUpdateTask> GetUpdateTasks(IEnumerable<IDependencyInfo> dependencyInfos) =>
Expand All @@ -47,24 +44,24 @@ public IEnumerable<DependencyUpdateTask> GetUpdateTasks(IEnumerable<IDependencyI

private void ExecuteScript()
{
Trace.TraceInformation($"Executing '{ScriptPath}'");
Trace.TraceInformation($"Executing '{_scriptPath}'");

// Support both execution within Windows 10, Nano Server and Linux environments.
Process process;
try
{
process = Process.Start("pwsh", ScriptPath);
process = Process.Start("pwsh", _scriptPath);
process.WaitForExit();
}
catch (Win32Exception)
{
process = Process.Start("powershell", ScriptPath);
process = Process.Start("powershell", _scriptPath);
process.WaitForExit();
}

if (process.ExitCode != 0)
{
throw new InvalidOperationException($"Unable to successfully execute '{ScriptPath}'");
throw new InvalidOperationException($"Unable to successfully execute '{_scriptPath}'");
}
}
}
Expand Down

0 comments on commit 5e7d906

Please sign in to comment.