@@ -8,21 +8,29 @@ namespace JenkinsConsoleUtility.Commands
88{
99 public class VersionVarWriter : ICommand
1010 {
11- private const string DefaultApiSpecFilePath = "../../../../API_Specs" ; // Relative path to Generate.js
11+ private const string DefaultApiSpecFilePath = "../../../../API_Specs" ; // Relative path from default VS output folder
1212 private const string DefaultApiSpecGitHubUrl = "https://raw.githubusercontent.com/PlayFab/API_Specs/master/" ;
1313 private const string DefaultApiSpecPlayFabUrl = "https://www.playfabapi.com/apispec/" ;
14- private static string _apiSpecPath , _apiSpecGitUrl , _apiSpecPfUrl ; // Exactly one of these is expected to be set
14+ private string _apiSpecPath , _apiSpecGitUrl , _apiSpecPfUrl ; // Exactly one of these is expected to be set
1515
1616 private static readonly string [ ] MyCommandKeys = { "versionVarWriter" , "version" } ;
1717 public string [ ] CommandKeys { get { return MyCommandKeys ; } }
18- private static readonly string [ ] MyMandatoryArgKeys = { "workspacePath" , "destFile" , " sdkName" } ;
18+ private static readonly string [ ] MyMandatoryArgKeys = { "sdkName" } ;
1919 public string [ ] MandatoryArgKeys { get { return MyMandatoryArgKeys ; } }
2020
21- public int Execute ( Dictionary < string , string > args )
21+ // If this command runs, make the results accessible to other modules
22+ public static string sdkVersionString ;
23+ public static string major ;
24+ public static string minor ;
25+ public static string date ;
26+ public static bool set = false ;
27+
28+ public int Execute ( Dictionary < string , string > argsLc , Dictionary < string , string > argsCased )
2229 {
23- var destFile = JenkinsConsoleUtility . GetArgVar ( args , "destFile" ) ;
24- var workspacePath = JenkinsConsoleUtility . GetArgVar ( args , "workspacePath" ) ;
25- var sdkName = JenkinsConsoleUtility . GetArgVar ( args , "sdkName" ) ;
30+ string destFile , workspacePath ;
31+ JenkinsConsoleUtility . TryGetArgVar ( out destFile , argsLc , "destFile" ) ;
32+ JenkinsConsoleUtility . TryGetArgVar ( out workspacePath , argsLc , "workspacePath" ) ;
33+ var sdkName = JenkinsConsoleUtility . GetArgVar ( argsLc , "sdkName" ) ;
2634 var sdkGenKey = GetSdkGenKey ( sdkName ) ;
2735
2836 if ( string . IsNullOrEmpty ( sdkGenKey ) )
@@ -31,12 +39,12 @@ public int Execute(Dictionary<string, string> args)
3139 return 1 ;
3240 }
3341
34- if ( args . ContainsKey ( "apispecpath" ) )
35- _apiSpecPath = JenkinsConsoleUtility . GetArgVar ( args , "apiSpecPath" ) ;
36- else if ( args . ContainsKey ( "apispecgiturl" ) )
37- _apiSpecGitUrl = JenkinsConsoleUtility . GetArgVar ( args , "apiSpecGitUrl" ) ;
38- else if ( args . ContainsKey ( "apispecpfurl" ) )
39- _apiSpecPfUrl = JenkinsConsoleUtility . GetArgVar ( args , "apiSpecPfUrl" ) ;
42+ if ( argsLc . ContainsKey ( "apispecpath" ) )
43+ _apiSpecPath = JenkinsConsoleUtility . GetArgVar ( argsLc , "apiSpecPath" ) ;
44+ else if ( argsLc . ContainsKey ( "apispecgiturl" ) )
45+ _apiSpecGitUrl = JenkinsConsoleUtility . GetArgVar ( argsLc , "apiSpecGitUrl" ) ;
46+ else if ( argsLc . ContainsKey ( "apispecpfurl" ) )
47+ _apiSpecPfUrl = JenkinsConsoleUtility . GetArgVar ( argsLc , "apiSpecPfUrl" ) ;
4048 else
4149 {
4250 JenkinsConsoleUtility . FancyWriteToConsole ( "Api-Spec input not defined. Please input one of: apiSpecPath, apiSpecGitUrl, apiSpecPfUrl" ) ;
@@ -45,7 +53,6 @@ public int Execute(Dictionary<string, string> args)
4553
4654 var versionJson = GetApiJson ( "SdkManualNotes.json" ) ;
4755 var sdkNotes = JsonWrapper . DeserializeObject < SdkManualNotes > ( versionJson ) ;
48- string sdkVersionString ;
4956 if ( ! sdkNotes . sdkVersion . TryGetValue ( sdkGenKey , out sdkVersionString ) )
5057 {
5158 JenkinsConsoleUtility . FancyWriteToConsole ( "SdkManualNotes.json does not contain: " + sdkGenKey ) ;
@@ -54,20 +61,27 @@ public int Execute(Dictionary<string, string> args)
5461 }
5562
5663 var sdkPieces = sdkVersionString . Split ( '.' ) ;
57- using ( var outputFile = new StreamWriter ( Path . Combine ( workspacePath , destFile ) ) )
64+ major = sdkPieces [ 0 ] ; minor = sdkPieces [ 1 ] ; date = sdkPieces [ sdkPieces . Length - 1 ] ;
65+ set = true ;
66+
67+ // Write this to a Jenkins environment variable file, if defined
68+ if ( ! string . IsNullOrEmpty ( destFile ) )
5869 {
59- outputFile . WriteLine ( "sdkVersion = " + sdkVersionString ) ;
60- outputFile . WriteLine ( "sdkDate = " + sdkPieces [ sdkPieces . Length - 1 ] ) ;
61- JenkinsConsoleUtility . FancyWriteToConsole ( "sdkVersion = " + sdkVersionString ) ;
62- JenkinsConsoleUtility . FancyWriteToConsole ( "sdkDate = " + sdkPieces [ sdkPieces . Length - 1 ] ) ;
70+ using ( var outputFile = new StreamWriter ( Path . Combine ( workspacePath , destFile ) ) )
71+ {
72+ outputFile . WriteLine ( "sdkVersion = " + sdkVersionString ) ;
73+ outputFile . WriteLine ( "sdkDate = " + date ) ;
74+ JenkinsConsoleUtility . FancyWriteToConsole ( "sdkVersion = " + sdkVersionString ) ;
75+ JenkinsConsoleUtility . FancyWriteToConsole ( "sdkDate = " + date ) ;
76+ }
6377 }
6478 return 0 ;
6579 }
6680
6781 /// <summary>
6882 /// Fetch the given file based on the input settings (_apiSpecPath, _apiSpecGitUrl, or _apiSpecPfUrl)
6983 /// </summary>
70- private static string GetApiJson ( string filename )
84+ private string GetApiJson ( string filename )
7185 {
7286 if ( _apiSpecPath != null )
7387 {
@@ -100,7 +114,7 @@ private static string GetApiJson(string filename)
100114 /// This bit of hard coding is particularly bad, because it's arbitrary, and historically not entirely reliable
101115 /// We need a better resolution for this
102116 /// </summary>
103- private static string GetSdkGenKey ( string sdkName )
117+ private string GetSdkGenKey ( string sdkName )
104118 {
105119 switch ( sdkName . ToLower ( ) )
106120 {
@@ -127,7 +141,7 @@ private static string GetSdkGenKey(string sdkName)
127141 /// Convert a filename to a URL on the PlayFab API server
128142 /// - If Possible, else use GitHub.
129143 /// </summary>
130- private static string GetPfServerUrl ( string filename )
144+ private string GetPfServerUrl ( string filename )
131145 {
132146 switch ( filename . ToLower ( ) )
133147 {
@@ -155,7 +169,7 @@ private static string GetPfServerUrl(string filename)
155169 /// Wrap and synchronize a HTTPS-get call
156170 /// Converts a url into the corresponding string-file-contents
157171 /// </summary>
158- private static async Task < string > SimpleHttpGet ( string fullUrl )
172+ private async Task < string > SimpleHttpGet ( string fullUrl )
159173 {
160174 if ( string . IsNullOrEmpty ( fullUrl ) )
161175 return "" ;
0 commit comments