@@ -29,36 +29,44 @@ public override string GenerateSetVersionMessage(VersionVariables variables)
2929
3030 public override string [ ] GenerateSetParameterMessage ( string name , string value )
3131 {
32+ // There is no equivalent function in GitHub Actions.
33+
34+ return new string [ 0 ] ;
35+ }
36+
37+ public override void WriteIntegration ( System . Action < string > writer , VersionVariables variables , bool updateBuildNumber = true )
38+ {
39+ base . WriteIntegration ( writer , variables , updateBuildNumber ) ;
40+
3241 // https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
33- // However it's important that GitHub Actions does not parse the log output. The outgoing environment variables must be
34- // written to a temporary file (identified by the $GITHUB_ENV environment variable, which changes for every step in a workflow)
35- // which is then parsed. That file must also be UTF-8 or it will fail.
42+ // The outgoing environment variables must be written to a temporary file (identified by the $GITHUB_ENV environment
43+ // variable, which changes for every step in a workflow) which is then parsed. That file must also be UTF-8 or it will fail.
3644
37- if ( ! string . IsNullOrWhiteSpace ( value ) )
45+ if ( writer == null || ! updateBuildNumber )
3846 {
39- var gitHubSetEnvFilePath = environment . GetEnvironmentVariable ( GitHubSetEnvTempFileEnvironmentVariableName ) ;
40- var assignment = $ "GitVersion_{ name } ={ value } ";
47+ return ;
48+ }
49+
50+ var gitHubSetEnvFilePath = environment . GetEnvironmentVariable ( GitHubSetEnvTempFileEnvironmentVariableName ) ;
4151
42- if ( gitHubSetEnvFilePath != null )
52+ if ( gitHubSetEnvFilePath != null )
53+ {
54+ writer ( $ "Writing version variables to $GITHUB_ENV file for '{ GetType ( ) . Name } '.") ;
55+ using ( var streamWriter = File . AppendText ( gitHubSetEnvFilePath ) ) // Already uses UTF-8 as required by GitHub
4356 {
44- using ( var streamWriter = File . AppendText ( gitHubSetEnvFilePath ) ) // Already uses UTF-8 as required by GitHub
57+ foreach ( var variable in variables )
4558 {
46- streamWriter . WriteLine ( assignment ) ;
59+ if ( ! string . IsNullOrEmpty ( variable . Value ) )
60+ {
61+ streamWriter . WriteLine ( $ "GitVersion_{ variable . Key } ={ variable . Value } ") ;
62+ }
4763 }
48-
49- return new [ ]
50- {
51- $ "Writing \" { assignment } \" to the file at ${ GitHubSetEnvTempFileEnvironmentVariableName } "
52- } ;
5364 }
54-
55- return new [ ]
56- {
57- $ "Unable to write \" { assignment } \" to ${ GitHubSetEnvTempFileEnvironmentVariableName } because the environment variable is not set."
58- } ;
5965 }
60-
61- return new string [ 0 ] ;
66+ else
67+ {
68+ writer ( $ "Unable to write GitVersion variables to ${ GitHubSetEnvTempFileEnvironmentVariableName } because the environment variable is not set.") ;
69+ }
6270 }
6371
6472 public override string GetCurrentBranch ( bool usingDynamicRepos )
0 commit comments