@@ -8,21 +8,29 @@ namespace JenkinsConsoleUtility.Commands
8
8
{
9
9
public class VersionVarWriter : ICommand
10
10
{
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
12
12
private const string DefaultApiSpecGitHubUrl = "https://raw.githubusercontent.com/PlayFab/API_Specs/master/" ;
13
13
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
15
15
16
16
private static readonly string [ ] MyCommandKeys = { "versionVarWriter" , "version" } ;
17
17
public string [ ] CommandKeys { get { return MyCommandKeys ; } }
18
- private static readonly string [ ] MyMandatoryArgKeys = { "workspacePath" , "destFile" , " sdkName" } ;
18
+ private static readonly string [ ] MyMandatoryArgKeys = { "sdkName" } ;
19
19
public string [ ] MandatoryArgKeys { get { return MyMandatoryArgKeys ; } }
20
20
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 )
22
29
{
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" ) ;
26
34
var sdkGenKey = GetSdkGenKey ( sdkName ) ;
27
35
28
36
if ( string . IsNullOrEmpty ( sdkGenKey ) )
@@ -31,12 +39,12 @@ public int Execute(Dictionary<string, string> args)
31
39
return 1 ;
32
40
}
33
41
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" ) ;
40
48
else
41
49
{
42
50
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)
45
53
46
54
var versionJson = GetApiJson ( "SdkManualNotes.json" ) ;
47
55
var sdkNotes = JsonWrapper . DeserializeObject < SdkManualNotes > ( versionJson ) ;
48
- string sdkVersionString ;
49
56
if ( ! sdkNotes . sdkVersion . TryGetValue ( sdkGenKey , out sdkVersionString ) )
50
57
{
51
58
JenkinsConsoleUtility . FancyWriteToConsole ( "SdkManualNotes.json does not contain: " + sdkGenKey ) ;
@@ -54,20 +61,27 @@ public int Execute(Dictionary<string, string> args)
54
61
}
55
62
56
63
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 ) )
58
69
{
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
+ }
63
77
}
64
78
return 0 ;
65
79
}
66
80
67
81
/// <summary>
68
82
/// Fetch the given file based on the input settings (_apiSpecPath, _apiSpecGitUrl, or _apiSpecPfUrl)
69
83
/// </summary>
70
- private static string GetApiJson ( string filename )
84
+ private string GetApiJson ( string filename )
71
85
{
72
86
if ( _apiSpecPath != null )
73
87
{
@@ -100,7 +114,7 @@ private static string GetApiJson(string filename)
100
114
/// This bit of hard coding is particularly bad, because it's arbitrary, and historically not entirely reliable
101
115
/// We need a better resolution for this
102
116
/// </summary>
103
- private static string GetSdkGenKey ( string sdkName )
117
+ private string GetSdkGenKey ( string sdkName )
104
118
{
105
119
switch ( sdkName . ToLower ( ) )
106
120
{
@@ -127,7 +141,7 @@ private static string GetSdkGenKey(string sdkName)
127
141
/// Convert a filename to a URL on the PlayFab API server
128
142
/// - If Possible, else use GitHub.
129
143
/// </summary>
130
- private static string GetPfServerUrl ( string filename )
144
+ private string GetPfServerUrl ( string filename )
131
145
{
132
146
switch ( filename . ToLower ( ) )
133
147
{
@@ -155,7 +169,7 @@ private static string GetPfServerUrl(string filename)
155
169
/// Wrap and synchronize a HTTPS-get call
156
170
/// Converts a url into the corresponding string-file-contents
157
171
/// </summary>
158
- private static async Task < string > SimpleHttpGet ( string fullUrl )
172
+ private async Task < string > SimpleHttpGet ( string fullUrl )
159
173
{
160
174
if ( string . IsNullOrEmpty ( fullUrl ) )
161
175
return "" ;
0 commit comments