Skip to content

Add config wizard changes to support private repositories on Appveyor #927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions src/GitVersionCore/Configuration/Init/BuildServer/AppVeyorSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ namespace GitVersion.Configuration.Init.BuildServer
using GitVersion.Configuration.Init.Wizard;
using GitVersion.Helpers;

enum ProjectVisibility
{
Public = 0,
Private = 1
}

class AppVeyorSetup : ConfigInitWizardStep
{
public AppVeyorSetup(IConsole console, IFileSystem fileSystem) : base(console, fileSystem)
private ProjectVisibility _projectVisibility;

public AppVeyorSetup(IConsole console, IFileSystem fileSystem, ProjectVisibility visibility) : base(console, fileSystem)
{
_projectVisibility = visibility;
}

protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory)
Expand All @@ -32,38 +41,55 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
return StepResult.InvalidResponseSelected();
}

static private string GetGVCommand(ProjectVisibility visibility)
{
switch (visibility)
{
case ProjectVisibility.Public:
return " - ps: gitversion /l console /output buildserver /updateAssemblyInfo";
case ProjectVisibility.Private:
return " - ps: gitversion $env:APPVEYOR_BUILD_FOLDER /l console /output buildserver /updateAssemblyInfo /nofetch /b $env:APPVEYOR_REPO_BRANCH";
default:
return "";
}
}

void GenerateBasicConfig(string workingDirectory)
{
WriteConfig(workingDirectory, FileSystem, @"install:
WriteConfig(workingDirectory, FileSystem, String.Format(@"install:
- choco install gitversion.portable -pre -y

before_build:
- nuget restore
- ps: gitversion /l console /output buildserver /updateAssemblyInfo
{0}

build:
project: <your sln file>");
project: <your sln file>",
GetGVCommand(_projectVisibility)
));
}

void GenerateNuGetConfig(string workingDirectory)
{
WriteConfig(workingDirectory, FileSystem, @"install:
WriteConfig(workingDirectory, FileSystem, String.Format(@"install:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use string interpolation here instead just as an FYI.

- choco install gitversion.portable -pre -y

assembly_info:
patch: false

before_build:
- nuget restore
- ps: gitversion /l console /output buildserver /updateAssemblyInfo
{0}

build:
project: <your sln file>

after_build:
- cmd: ECHO nuget pack <Project>\<NuSpec>.nuspec -version ""%GitVersion_NuGetVersion%"" -prop ""target=%CONFIGURATION%""
- cmd: nuget pack <Project>\<NuSpec>.nuspec -version ""%GitVersion_NuGetVersion%"" -prop ""target=%CONFIGURATION%""
- cmd: appveyor PushArtifact ""<NuSpec>.%GitVersion_NuGetVersion%.nupkg""");
- cmd: appveyor PushArtifact ""<NuSpec>.%GitVersion_NuGetVersion%.nupkg""",
GetGVCommand(_projectVisibility)
));
}

void WriteConfig(string workingDirectory, IFileSystem fileSystem, string configContents)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace GitVersion.Configuration.Init.BuildServer
{
using System.Collections.Generic;
using GitVersion.Configuration.Init.Wizard;
using GitVersion.Helpers;

class AppveyorPublicPrivate : ConfigInitWizardStep
{
public AppveyorPublicPrivate(IConsole console, IFileSystem fileSystem) : base(console, fileSystem)
{
}

protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory)
{
switch (result)
{
case "0":
steps.Enqueue(new EditConfigStep(Console, FileSystem));
return StepResult.Ok();
case "1":
steps.Enqueue(new AppVeyorSetup(Console, FileSystem, ProjectVisibility.Public));
return StepResult.Ok();
case "2":
steps.Enqueue(new AppVeyorSetup(Console, FileSystem, ProjectVisibility.Private));
return StepResult.Ok();
}
return StepResult.Ok();
}

protected override string GetPrompt(Config config, string workingDirectory)
{
return @"Is your project public or private?

That is ... does it require authentication to clone/pull?

0) Go Back
1) Public
2) Private";
}

protected override string DefaultResult
{
get { return "0"; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
steps.Enqueue(new EditConfigStep(Console, FileSystem));
return StepResult.Ok();
case "1":
steps.Enqueue(new AppVeyorSetup(Console, FileSystem));
steps.Enqueue(new AppveyorPublicPrivate(Console, FileSystem));
return StepResult.Ok();
}
return StepResult.Ok();
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Compile Include="Configuration\ConsoleAdapter.cs" />
<Compile Include="Configuration\IConsole.cs" />
<Compile Include="Configuration\IgnoreConfig.cs" />
<Compile Include="Configuration\Init\BuildServer\AppveyorPublicPrivate.cs" />
<Compile Include="Configuration\Init\BuildServer\AppVeyorSetup.cs" />
<Compile Include="Configuration\Init\BuildServer\SetupBuildScripts.cs" />
<Compile Include="Configuration\Init\SetConfig\AssemblyVersioningSchemeSetting.cs" />
Expand Down