Skip to content

Commit ed9878c

Browse files
committed
Merge pull request #479 from JakeGinnivan/InitImprovements
Init improvements
2 parents 718b220 + 043ebdd commit ed9878c

29 files changed

+403
-191
lines changed

GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GitVersion
22
{
33
using System.IO;
44
using System.Text;
5+
using GitVersion.Configuration.Init.Wizard;
56
using GitVersion.Helpers;
67

78
public class ConfigurationProvider
@@ -41,7 +42,7 @@ static string GetConfigFilePath(string workingDirectory)
4142
public static void Init(string workingDirectory, IFileSystem fileSystem)
4243
{
4344
var configFilePath = GetConfigFilePath(workingDirectory);
44-
var config = new ConfigInitWizard().Run(Provide(workingDirectory, fileSystem));
45+
var config = new ConfigInitWizard().Run(Provide(workingDirectory, fileSystem), workingDirectory, fileSystem);
4546
if (config == null) return;
4647

4748
using (var stream = fileSystem.OpenWrite(configFilePath))
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
namespace GitVersion.Configuration.Init.BuildServer
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Text;
7+
using GitVersion.Configuration.Init.Wizard;
8+
using GitVersion.Helpers;
9+
10+
class AppVeyorSetup : ConfigInitWizardStep
11+
{
12+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
13+
{
14+
switch (result)
15+
{
16+
case "0":
17+
steps.Enqueue(new EditConfigStep());
18+
return StepResult.Ok();
19+
case "1":
20+
GenerateBasicConfig(workingDirectory, fileSystem);
21+
steps.Enqueue(new EditConfigStep());
22+
return StepResult.Ok();
23+
case "2":
24+
GenerateNuGetConfig(workingDirectory, fileSystem);
25+
steps.Enqueue(new EditConfigStep());
26+
return StepResult.Ok();
27+
}
28+
return StepResult.InvalidResponseSelected();
29+
}
30+
31+
void GenerateBasicConfig(string workingDirectory, IFileSystem fileSystem)
32+
{
33+
WriteConfig(workingDirectory, fileSystem, @"install:
34+
- choco install gitversion.portable -pre -y
35+
36+
before_build:
37+
- nuget restore
38+
- ps: gitversion /l console /output buildserver /updateAssemblyInfo
39+
40+
build:
41+
project: <your sln file>");
42+
}
43+
44+
void GenerateNuGetConfig(string workingDirectory, IFileSystem fileSystem)
45+
{
46+
WriteConfig(workingDirectory, fileSystem, @"install:
47+
- choco install gitversion.portable -pre -y
48+
49+
assembly_info:
50+
patch: false
51+
52+
before_build:
53+
- nuget restore
54+
- ps: gitversion /l console /output buildserver /updateAssemblyInfo
55+
56+
build:
57+
project: <your sln file>
58+
59+
after_build:
60+
- cmd: ECHO nuget pack <Project>\<NuSpec>.nuspec -version ""%GitVersion_NuGetVersion%"" -prop ""target=%CONFIGURATION%""
61+
- cmd: nuget pack <Project>\<NuSpec>.nuspec -version ""%GitVersion_NuGetVersion%"" -prop ""target=%CONFIGURATION%""
62+
- cmd: appveyor PushArtifact ""<NuSpec>.%GitVersion_NuGetVersion%.nupkg""");
63+
}
64+
65+
void WriteConfig(string workingDirectory, IFileSystem fileSystem, string configContents)
66+
{
67+
var outputFilename = GetOutputFilename(workingDirectory, fileSystem);
68+
fileSystem.WriteAllText(outputFilename, configContents);
69+
Logger.WriteInfo(string.Format("AppVeyor sample config file written to {0}", outputFilename));
70+
}
71+
72+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
73+
{
74+
var prompt = new StringBuilder();
75+
if (AppVeyorConfigExists(workingDirectory, fileSystem))
76+
{
77+
prompt.AppendLine("GitVersion doesn't support modifying existing appveyor config files. We will generate appveyor.gitversion.yml instead");
78+
prompt.AppendLine();
79+
}
80+
81+
prompt.Append(@"What sort of config template would you like generated?
82+
83+
0) Go Back
84+
1) Generate basic (gitversion + msbuild) configuration
85+
2) Generate with NuGet package publish");
86+
87+
return prompt.ToString();
88+
}
89+
90+
string GetOutputFilename(string workingDirectory, IFileSystem fileSystem)
91+
{
92+
if (AppVeyorConfigExists(workingDirectory, fileSystem))
93+
{
94+
var count = 0;
95+
do
96+
{
97+
var path = Path.Combine(workingDirectory, string.Format("appveyor.gitversion{0}.yml", count == 0 ? string.Empty : "." + count));
98+
99+
if (!fileSystem.Exists(path))
100+
{
101+
return path;
102+
}
103+
104+
count++;
105+
} while (count < 10);
106+
throw new Exception("appveyor.gitversion.yml -> appveyor.gitversion.9.yml all exist. Pretty sure you have enough templates");
107+
}
108+
109+
return Path.Combine(workingDirectory, "appveyor.yml");
110+
}
111+
112+
static bool AppVeyorConfigExists(string workingDirectory, IFileSystem fileSystem)
113+
{
114+
return fileSystem.Exists(Path.Combine(workingDirectory, "appveyor.yml"));
115+
}
116+
117+
protected override string DefaultResult
118+
{
119+
get { return "0"; }
120+
}
121+
}
122+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace GitVersion.Configuration.Init.BuildServer
2+
{
3+
using System.Collections.Generic;
4+
using GitVersion.Configuration.Init.Wizard;
5+
using GitVersion.Helpers;
6+
7+
class SetupBuildScripts : ConfigInitWizardStep
8+
{
9+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
10+
{
11+
switch (result)
12+
{
13+
case "0":
14+
steps.Enqueue(new EditConfigStep());
15+
return StepResult.Ok();
16+
case "1":
17+
steps.Enqueue(new AppVeyorSetup());
18+
return StepResult.Ok();
19+
}
20+
return StepResult.Ok();
21+
}
22+
23+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
24+
{
25+
return @"What build server are you using?
26+
27+
Want to see more? Contribute a pull request!
28+
29+
0) Go Back
30+
1) AppVeyor";
31+
}
32+
33+
protected override string DefaultResult
34+
{
35+
get { return "0"; }
36+
}
37+
}
38+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace GitVersion.Configuration.Init
2+
{
3+
using System.Collections.Generic;
4+
using GitVersion.Configuration.Init.BuildServer;
5+
using GitVersion.Configuration.Init.SetConfig;
6+
using GitVersion.Configuration.Init.Wizard;
7+
using GitVersion.Helpers;
8+
9+
public class EditConfigStep : ConfigInitWizardStep
10+
{
11+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
12+
{
13+
switch (result)
14+
{
15+
case "0":
16+
return StepResult.SaveAndExit();
17+
case "1":
18+
return StepResult.ExitWithoutSaving();
19+
20+
case "2":
21+
steps.Enqueue(new PickBranchingStrategyStep());
22+
return StepResult.Ok();
23+
24+
case "3":
25+
steps.Enqueue(new SetNextVersion());
26+
return StepResult.Ok();
27+
28+
case "4":
29+
steps.Enqueue(new ConfigureBranches());
30+
return StepResult.Ok();
31+
case "5":
32+
steps.Enqueue(new GlobalModeSetting(new EditConfigStep(), false));
33+
return StepResult.Ok();
34+
case "6":
35+
steps.Enqueue(new AssemblyVersioningSchemeSetting());
36+
return StepResult.Ok();
37+
case "7":
38+
steps.Enqueue(new SetupBuildScripts());
39+
return StepResult.Ok();
40+
}
41+
return StepResult.InvalidResponseSelected();
42+
}
43+
44+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
45+
{
46+
return string.Format(@"Which would you like to change?
47+
48+
0) Save changes and exit
49+
1) Exit without saving
50+
51+
2) Run getting started wizard
52+
53+
3) Set next version number
54+
4) Branch specific configuration
55+
5) Branch Increment mode (per commit/after tag) (Current: {0})
56+
6) Assembly versioning scheme (Current: {1})
57+
7) Setup build scripts", config.VersioningMode, config.AssemblyVersioningScheme);
58+
}
59+
60+
protected override string DefaultResult
61+
{
62+
get { return null; }
63+
}
64+
}
65+
}

GitVersionCore/Configuration/Wizard/AssemblyVersioningSchemeSetting.cs renamed to GitVersionCore/Configuration/Init/SetConfig/AssemblyVersioningSchemeSetting.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
namespace GitVersion
1+
namespace GitVersion.Configuration.Init.SetConfig
22
{
33
using System.Collections.Generic;
4+
using GitVersion.Helpers;
5+
using Wizard;
46

57
public class AssemblyVersioningSchemeSetting : ConfigInitWizardStep
68
{
7-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
9+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
810
{
911
switch (result)
1012
{
@@ -32,11 +34,11 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3234
return StepResult.InvalidResponseSelected();
3335
}
3436

35-
protected override string GetPrompt(Config config)
37+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3638
{
3739
return @"What assembly versioning scheme do you want to use:
3840
39-
0) Back
41+
0) Go Back
4042
1) Major.0.0.0
4143
2) Major.Minor.0.0
4244
3) Major.Minor.Patch.0 (default)

GitVersionCore/Configuration/Wizard/ConfigureBranch.cs renamed to GitVersionCore/Configuration/Init/SetConfig/ConfigureBranch.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
namespace GitVersion
1+
namespace GitVersion.Configuration.Init.SetConfig
22
{
33
using System.Collections.Generic;
4+
using GitVersion.Configuration.Init.Wizard;
5+
using GitVersion.Helpers;
46

57
public class ConfigureBranch : ConfigInitWizardStep
68
{
@@ -13,7 +15,7 @@ public ConfigureBranch(string name, BranchConfig branchConfig)
1315
this.name = name;
1416
}
1517

16-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
18+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
1719
{
1820
switch (result)
1921
{
@@ -31,11 +33,11 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3133
return StepResult.InvalidResponseSelected();
3234
}
3335

34-
protected override string GetPrompt(Config config)
36+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3537
{
3638
return string.Format(@"What would you like to change for '{0}':
3739
38-
0) Back
40+
0) Go Back
3941
1) Branch Pre-release tag (Current: {1})
4042
2) Branch Increment mode (per commit/after tag) (Current: {2})", name, branchConfig.Tag, branchConfig.VersioningMode);
4143
}

GitVersionCore/Configuration/Wizard/ConfigureBranches.cs renamed to GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
namespace GitVersion
1+
namespace GitVersion.Configuration.Init.SetConfig
22
{
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using GitVersion.Configuration.Init.Wizard;
7+
using GitVersion.Helpers;
68

79
public class ConfigureBranches : ConfigInitWizardStep
810
{
9-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
11+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
1012
{
1113
int parsed;
1214
if (int.TryParse(result, out parsed))
@@ -30,11 +32,11 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3032
return StepResult.InvalidResponseSelected();
3133
}
3234

33-
protected override string GetPrompt(Config config)
35+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3436
{
3537
return @"Which branch would you like to configure:
3638
37-
0) Back
39+
0) Go Back
3840
" + string.Join("\r\n", OrderedBranches(config).Select((c, i) => string.Format("{0}) {1}", i + 1, c.Key)));
3941
}
4042

GitVersionCore/Configuration/Wizard/SetConfig/GlobalModeSetting.cs renamed to GitVersionCore/Configuration/Init/SetConfig/GlobalModeSetting.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
namespace GitVersion.Configuration.Wizard.SetConfig
1+
namespace GitVersion.Configuration.Init.SetConfig
22
{
33
using System.Collections.Generic;
4+
using GitVersion.Configuration.Init.Wizard;
5+
using GitVersion.Helpers;
46

57
public class GlobalModeSetting : ConfigInitWizardStep
68
{
@@ -13,7 +15,7 @@ public GlobalModeSetting(ConfigInitWizardStep returnToStep, bool isPartOfWizard)
1315
this.isPartOfWizard = isPartOfWizard;
1416
}
1517

16-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
18+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
1719
{
1820
switch (result)
1921
{
@@ -34,14 +36,14 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3436
return StepResult.InvalidResponseSelected();
3537
}
3638

37-
protected override string GetPrompt(Config config)
39+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3840
{
3941
return string.Format(@"What do you want the default increment mode to be (can be overriden per branch):
4042
{0}
4143
1) Follow SemVer and only increment when a release has been tagged (continuous delivery mode)
4244
2) Increment based on branch config every commit (continuous deployment mode)
4345
{1}",
44-
!isPartOfWizard ? "0) Back" : string.Empty,
46+
!isPartOfWizard ? "0) Go Back" : string.Empty,
4547
isPartOfWizard ? "3) Skip" : string.Empty);
4648
}
4749

0 commit comments

Comments
 (0)