Skip to content

Commit a28dc70

Browse files
committed
Added appveyor config generation to init. Wizard is now an option rather than a question to start with
1 parent aa55a50 commit a28dc70

22 files changed

+239
-80
lines changed

GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static string GetConfigFilePath(string workingDirectory)
4242
public static void Init(string workingDirectory, IFileSystem fileSystem)
4343
{
4444
var configFilePath = GetConfigFilePath(workingDirectory);
45-
var config = new ConfigInitWizard().Run(Provide(workingDirectory, fileSystem));
45+
var config = new ConfigInitWizard().Run(Provide(workingDirectory, fileSystem), workingDirectory, fileSystem);
4646
if (config == null) return;
4747

4848
using (var stream = fileSystem.OpenWrite(configFilePath))
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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
35+
36+
before_build:
37+
- ps: ./tools/gitversion.exe /l console /output buildserver /updateAssemblyInfo
38+
39+
build:
40+
project: <your sln file>");
41+
}
42+
43+
void GenerateNuGetConfig(string workingDirectory, IFileSystem fileSystem)
44+
{
45+
WriteConfig(workingDirectory, fileSystem, @"install:
46+
- choco install gitversion.portable -pre
47+
48+
before_build:
49+
- ps: ./tools/gitversion.exe /l console /output buildserver /updateAssemblyInfo
50+
51+
build:
52+
project: <your sln file>
53+
54+
after_build:
55+
- cmd: ECHO nuget pack <Project>\<NuSpec>.nuspec -version ""%GitVersion_NuGetVersion%"" -prop ""target=%CONFIGURATION%""
56+
- cmd: nuget pack <Project>\<NuSpec>.nuspec - version ""%GitVersion_NuGetVersion%"" - prop ""target=%CONFIGURATION%""
57+
- cmd: appveyor PushArtifact ""<NuSpec>.%GitVersion_NuGetVersion%.nupkg""");
58+
}
59+
60+
void WriteConfig(string workingDirectory, IFileSystem fileSystem, string configContents)
61+
{
62+
var outputFilename = GetOutputFilename(workingDirectory, fileSystem);
63+
fileSystem.WriteAllText(outputFilename, configContents);
64+
Logger.WriteInfo(string.Format("AppVeyor sample config file written to {0}", outputFilename));
65+
}
66+
67+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
68+
{
69+
var prompt = new StringBuilder();
70+
if (AppVeyorConfigExists(workingDirectory, fileSystem))
71+
{
72+
prompt.AppendLine("GitVersion doesn't support modifying existing appveyor config files. We will generate appveyor.gitversion.yml instead");
73+
prompt.AppendLine();
74+
}
75+
76+
prompt.Append(@"What sort of config template would you like generated?
77+
78+
0) Back
79+
1) Generate basic (gitversion + msbuild) configuration
80+
2) Generate with NuGet package publish");
81+
82+
return prompt.ToString();
83+
}
84+
85+
string GetOutputFilename(string workingDirectory, IFileSystem fileSystem)
86+
{
87+
if (AppVeyorConfigExists(workingDirectory, fileSystem))
88+
{
89+
var count = 0;
90+
do
91+
{
92+
var path = Path.Combine(workingDirectory, string.Format("appveyor.gitversion{0}.yml", count == 0 ? string.Empty : "." + count));
93+
94+
if (!fileSystem.Exists(path))
95+
{
96+
return path;
97+
}
98+
99+
count++;
100+
} while (count < 10);
101+
throw new Exception("appveyor.gitversion.yml -> appveyor.gitversion.9.yml all exist. Pretty sure you have enough templates");
102+
}
103+
104+
return Path.Combine(workingDirectory, "appveyor.yml");
105+
}
106+
107+
static bool AppVeyorConfigExists(string workingDirectory, IFileSystem fileSystem)
108+
{
109+
return fileSystem.Exists(Path.Combine(workingDirectory, "appveyor.yml"));
110+
}
111+
112+
protected override string DefaultResult
113+
{
114+
get { return "0"; }
115+
}
116+
}
117+
}
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) Back
30+
1) AppVeyor";
31+
}
32+
33+
protected override string DefaultResult
34+
{
35+
get { return "0"; }
36+
}
37+
}
38+
}

GitVersionCore/Configuration/Init/EditConfigStep.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,55 @@
11
namespace GitVersion.Configuration.Init
22
{
33
using System.Collections.Generic;
4+
using GitVersion.Configuration.Init.BuildServer;
45
using GitVersion.Configuration.Init.SetConfig;
56
using GitVersion.Configuration.Init.Wizard;
7+
using GitVersion.Helpers;
68

79
public class EditConfigStep : 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
switch (result)
1214
{
1315
case "0":
1416
return StepResult.SaveAndExit();
1517
case "1":
1618
return StepResult.ExitWithoutSaving();
19+
1720
case "2":
18-
steps.Enqueue(new ConfigureBranches());
21+
steps.Enqueue(new PickBranchingStrategyStep());
1922
return StepResult.Ok();
23+
2024
case "3":
21-
steps.Enqueue(new GlobalModeSetting(new EditConfigStep(), false));
25+
steps.Enqueue(new ConfigureBranches());
2226
return StepResult.Ok();
2327
case "4":
28+
steps.Enqueue(new GlobalModeSetting(new EditConfigStep(), false));
29+
return StepResult.Ok();
30+
case "5":
2431
steps.Enqueue(new AssemblyVersioningSchemeSetting());
2532
return StepResult.Ok();
33+
case "6":
34+
steps.Enqueue(new SetupBuildScripts());
35+
return StepResult.Ok();
2636
}
27-
return StepResult.Ok();
37+
return StepResult.InvalidResponseSelected();
2838
}
2939

30-
protected override string GetPrompt(Config config)
40+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3141
{
3242
return string.Format(@"Which would you like to change?
3343
3444
0) Save changes and exit
3545
1) Exit without saving
36-
2) Branch specific configuration
37-
3) Branch Increment mode (per commit/after tag) (Current: {0})
38-
4) Assembly versioning scheme (Current: {1})", config.VersioningMode, config.AssemblyVersioningScheme);
46+
47+
2) Run getting started wizard
48+
49+
3) Branch specific configuration
50+
4) Branch Increment mode (per commit/after tag) (Current: {0})
51+
5) Assembly versioning scheme (Current: {1})
52+
6) Setup build scripts", config.VersioningMode, config.AssemblyVersioningScheme);
3953
}
4054

4155
protected override string DefaultResult

GitVersionCore/Configuration/Init/SetConfig/AssemblyVersioningSchemeSetting.cs

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

67
public class AssemblyVersioningSchemeSetting : ConfigInitWizardStep
78
{
8-
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)
910
{
1011
switch (result)
1112
{
@@ -33,7 +34,7 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3334
return StepResult.InvalidResponseSelected();
3435
}
3536

36-
protected override string GetPrompt(Config config)
37+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3738
{
3839
return @"What assembly versioning scheme do you want to use:
3940

GitVersionCore/Configuration/Init/SetConfig/ConfigureBranch.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GitVersion.Configuration.Init.SetConfig
22
{
33
using System.Collections.Generic;
44
using GitVersion.Configuration.Init.Wizard;
5+
using GitVersion.Helpers;
56

67
public class ConfigureBranch : ConfigInitWizardStep
78
{
@@ -14,7 +15,7 @@ public ConfigureBranch(string name, BranchConfig branchConfig)
1415
this.name = name;
1516
}
1617

17-
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)
1819
{
1920
switch (result)
2021
{
@@ -32,7 +33,7 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3233
return StepResult.InvalidResponseSelected();
3334
}
3435

35-
protected override string GetPrompt(Config config)
36+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3637
{
3738
return string.Format(@"What would you like to change for '{0}':
3839

GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ namespace GitVersion.Configuration.Init.SetConfig
44
using System.Collections.Generic;
55
using System.Linq;
66
using GitVersion.Configuration.Init.Wizard;
7+
using GitVersion.Helpers;
78

89
public class ConfigureBranches : ConfigInitWizardStep
910
{
10-
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)
1112
{
1213
int parsed;
1314
if (int.TryParse(result, out parsed))
@@ -31,7 +32,7 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3132
return StepResult.InvalidResponseSelected();
3233
}
3334

34-
protected override string GetPrompt(Config config)
35+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3536
{
3637
return @"Which branch would you like to configure:
3738

GitVersionCore/Configuration/Init/SetConfig/GlobalModeSetting.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System.Collections.Generic;
44
using GitVersion.Configuration.Init.Wizard;
5+
using GitVersion.Helpers;
56

67
public class GlobalModeSetting : ConfigInitWizardStep
78
{
@@ -14,7 +15,7 @@ public GlobalModeSetting(ConfigInitWizardStep returnToStep, bool isPartOfWizard)
1415
this.isPartOfWizard = isPartOfWizard;
1516
}
1617

17-
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)
1819
{
1920
switch (result)
2021
{
@@ -35,7 +36,7 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3536
return StepResult.InvalidResponseSelected();
3637
}
3738

38-
protected override string GetPrompt(Config config)
39+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3940
{
4041
return string.Format(@"What do you want the default increment mode to be (can be overriden per branch):
4142
{0}

GitVersionCore/Configuration/Init/SetConfig/SetBranchIncrementMode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GitVersion.Configuration.Init.SetConfig
22
{
33
using System.Collections.Generic;
44
using GitVersion.Configuration.Init.Wizard;
5+
using GitVersion.Helpers;
56

67
public class SetBranchIncrementMode : ConfigInitWizardStep
78
{
@@ -14,7 +15,7 @@ public SetBranchIncrementMode(string name, BranchConfig branchConfig)
1415
this.branchConfig = branchConfig;
1516
}
1617

17-
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)
1819
{
1920
switch (result)
2021
{
@@ -34,7 +35,7 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3435
return StepResult.InvalidResponseSelected();
3536
}
3637

37-
protected override string GetPrompt(Config config)
38+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
3839
{
3940
return string.Format(@"What do you want the increment mode for {0} to be?
4041

GitVersionCore/Configuration/Init/SetConfig/SetBranchTag.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GitVersion.Configuration.Init.SetConfig
22
{
33
using System.Collections.Generic;
44
using GitVersion.Configuration.Init.Wizard;
5+
using GitVersion.Helpers;
56

67
public class SetBranchTag : ConfigInitWizardStep
78
{
@@ -14,7 +15,7 @@ public SetBranchTag(string name, BranchConfig branchConfig)
1415
this.branchConfig = branchConfig;
1516
}
1617

17-
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)
1819
{
1920
if (string.IsNullOrWhiteSpace(result))
2021
{
@@ -37,7 +38,7 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3738
}
3839
}
3940

40-
protected override string GetPrompt(Config config)
41+
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
4142
{
4243
return @"This sets the pre-release tag which will be used for versions on this branch (beta, rc etc)
4344

0 commit comments

Comments
 (0)