11using System . Collections . Generic ;
2+ using System . IO ;
23using GitVersion ;
34using GitVersion . BuildAgents ;
45using GitVersionCore . Tests . Helpers ;
@@ -15,6 +16,7 @@ public class GitHubActionsTests : TestBase
1516 {
1617 private IEnvironment environment ;
1718 private GitHubActions buildServer ;
19+ private string githubSetEnvironmentTempFilePath ;
1820
1921 [ SetUp ]
2022 public void SetUp ( )
@@ -26,12 +28,21 @@ public void SetUp()
2628 environment = sp . GetService < IEnvironment > ( ) ;
2729 buildServer = sp . GetService < GitHubActions > ( ) ;
2830 environment . SetEnvironmentVariable ( GitHubActions . EnvironmentVariableName , "true" ) ;
31+
32+ githubSetEnvironmentTempFilePath = Path . GetTempFileName ( ) ;
33+ environment . SetEnvironmentVariable ( GitHubActions . GitHubSetEnvTempFileEnvironmentVariableName , githubSetEnvironmentTempFilePath ) ;
2934 }
3035
3136 [ TearDown ]
3237 public void TearDown ( )
3338 {
3439 environment . SetEnvironmentVariable ( GitHubActions . EnvironmentVariableName , null ) ;
40+ environment . SetEnvironmentVariable ( GitHubActions . GitHubSetEnvTempFileEnvironmentVariableName , null ) ;
41+ if ( githubSetEnvironmentTempFilePath != null && File . Exists ( githubSetEnvironmentTempFilePath ) )
42+ {
43+ File . Delete ( githubSetEnvironmentTempFilePath ) ;
44+ githubSetEnvironmentTempFilePath = null ;
45+ }
3546 }
3647
3748 [ Test ]
@@ -97,8 +108,8 @@ public void GetCurrentBranchShouldHandlePullRequests()
97108 }
98109
99110 [ TestCase ( "Something" , "1.0.0" ,
100- "\" GitVersion_Something=1.0.0\" >> $GITHUB_ENV" ) ]
101- public void GetSetParameterMessage ( string key , string value , string expectedResult )
111+ "Writing \" GitVersion_Something=1.0.0\" to the file at $GITHUB_ENV" , "GitVersion_Something=1.0.0 ") ]
112+ public void GetSetParameterMessage ( string key , string value , string expectedResult , string expectedFileResult )
102113 {
103114 // Assert
104115 environment . GetEnvironmentVariable ( "GitVersion_Something" ) . ShouldBeNullOrWhiteSpace ( ) ;
@@ -109,6 +120,10 @@ public void GetSetParameterMessage(string key, string value, string expectedResu
109120 // Assert
110121 result . ShouldContain ( s => true , 1 ) ;
111122 result . ShouldBeEquivalentTo ( new [ ] { expectedResult } ) ;
123+ var resultLines = File . ReadAllLines ( githubSetEnvironmentTempFilePath ) ;
124+ resultLines . ShouldContain ( s => true , 1 ) ;
125+ resultLines . ShouldBeEquivalentTo ( new [ ] { expectedFileResult } ) ;
126+
112127 }
113128
114129 [ Test ]
@@ -141,7 +156,7 @@ public void ShouldWriteIntegration()
141156 "Executing GenerateSetVersionMessage for 'GitHubActions'." ,
142157 "" ,
143158 "Executing GenerateBuildLogOutput for 'GitHubActions'." ,
144- "\" GitVersion_Major=1.0.0\" >> $GITHUB_ENV"
159+ "Writing \" GitVersion_Major=1.0.0\" to the file at $GITHUB_ENV"
145160 } ;
146161
147162 string . Join ( Environment . NewLine , list )
0 commit comments