1
1
using System . Collections . Generic ;
2
+ using System . IO ;
2
3
using GitVersion ;
3
4
using GitVersion . BuildAgents ;
4
5
using GitVersionCore . Tests . Helpers ;
@@ -15,6 +16,7 @@ public class GitHubActionsTests : TestBase
15
16
{
16
17
private IEnvironment environment ;
17
18
private GitHubActions buildServer ;
19
+ private string githubSetEnvironmentTempFilePath ;
18
20
19
21
[ SetUp ]
20
22
public void SetUp ( )
@@ -26,12 +28,21 @@ public void SetUp()
26
28
environment = sp . GetService < IEnvironment > ( ) ;
27
29
buildServer = sp . GetService < GitHubActions > ( ) ;
28
30
environment . SetEnvironmentVariable ( GitHubActions . EnvironmentVariableName , "true" ) ;
31
+
32
+ githubSetEnvironmentTempFilePath = Path . GetTempFileName ( ) ;
33
+ environment . SetEnvironmentVariable ( GitHubActions . GitHubSetEnvTempFileEnvironmentVariableName , githubSetEnvironmentTempFilePath ) ;
29
34
}
30
35
31
36
[ TearDown ]
32
37
public void TearDown ( )
33
38
{
34
39
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
+ }
35
46
}
36
47
37
48
[ Test ]
@@ -97,8 +108,8 @@ public void GetCurrentBranchShouldHandlePullRequests()
97
108
}
98
109
99
110
[ 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 )
102
113
{
103
114
// Assert
104
115
environment . GetEnvironmentVariable ( "GitVersion_Something" ) . ShouldBeNullOrWhiteSpace ( ) ;
@@ -109,6 +120,10 @@ public void GetSetParameterMessage(string key, string value, string expectedResu
109
120
// Assert
110
121
result . ShouldContain ( s => true , 1 ) ;
111
122
result . ShouldBeEquivalentTo ( new [ ] { expectedResult } ) ;
123
+ var resultLines = File . ReadAllLines ( githubSetEnvironmentTempFilePath ) ;
124
+ resultLines . ShouldContain ( s => true , 1 ) ;
125
+ resultLines . ShouldBeEquivalentTo ( new [ ] { expectedFileResult } ) ;
126
+
112
127
}
113
128
114
129
[ Test ]
@@ -141,7 +156,7 @@ public void ShouldWriteIntegration()
141
156
"Executing GenerateSetVersionMessage for 'GitHubActions'." ,
142
157
"" ,
143
158
"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"
145
160
} ;
146
161
147
162
string . Join ( Environment . NewLine , list )
0 commit comments