From 4d9c33d9e4c5e263aec482aa0786bd7227280d6d Mon Sep 17 00:00:00 2001 From: Hugo Dahl Date: Wed, 2 Mar 2022 20:28:24 -0600 Subject: [PATCH 1/2] Break out of for loop on success Addresses item 1 of issue #726 --- src/Shared/Utilities.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Shared/Utilities.cs b/src/Shared/Utilities.cs index 9e375f66..c20f34a0 100644 --- a/src/Shared/Utilities.cs +++ b/src/Shared/Utilities.cs @@ -19,6 +19,7 @@ internal static void FileOperationWithRetry(Action operation) try { operation(); + break; } catch (IOException ex) when (ex.HResult == ProcessCannotAccessFileHR && retriesLeft > 0) { From b6e44c3bf9cf0162883638828caea08ccacc3f74 Mon Sep 17 00:00:00 2001 From: Hugo Dahl Date: Wed, 2 Mar 2022 20:38:28 -0600 Subject: [PATCH 2/2] Use 'File.AppendLine()' to generate output Let the 'System.IO.File' provider handle newlines between entries rather than manually inserting them Addresses item 2 of #726 --- src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs b/src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs index 48ca3bbf..f3931042 100644 --- a/src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs +++ b/src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs @@ -28,7 +28,7 @@ internal class GitHubActions : ICloudBuild public IReadOnlyDictionary SetCloudBuildVariable(string name, string value, TextWriter stdout, TextWriter stderr) { - Utilities.FileOperationWithRetry(() => File.AppendAllText(EnvironmentFile, $"{Environment.NewLine}{name}={value}{Environment.NewLine}")); + Utilities.FileOperationWithRetry(() => File.AppendAllLines(EnvironmentFile, new [] {$"{name}={value}"})); return GetDictionaryFor(name, value); }