Skip to content

Vso build step #571

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 35 commits into from
Aug 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
99ed965
Add NUnit TestAdapter packages to test projects to enable VS Test Exp…
Aug 9, 2015
cd5ee99
Add support for VSO Agent
Aug 10, 2015
51138e9
don't put placeholder in
Aug 10, 2015
416fce0
Update docs for vso-agent
Aug 10, 2015
328a48a
Initial stab at VSO build step
Aug 10, 2015
acfecc7
add missing comma
Aug 10, 2015
8b88798
Move to correct location
Aug 10, 2015
9a0475f
Generate build dir for VSO artifacts
Aug 10, 2015
a608692
updates
Aug 10, 2015
f2096c4
ensure local branch info is available
Aug 11, 2015
b518658
ensure use of ordinal ignore case
Aug 11, 2015
5d664ad
Handle VSO's pull requests. Need to check them out locally and they d…
Aug 11, 2015
d128fa7
doc update
Aug 11, 2015
e00c96b
more docs
Aug 11, 2015
845cf33
Use Shouldy
Aug 12, 2015
167f044
Create zip file artifact of VSO build step
Aug 12, 2015
c87ff69
fix path in yml
Aug 12, 2015
07808d2
clean up description
Aug 12, 2015
f95ec20
Set task.json version during build
Aug 12, 2015
74f8211
Moved nofetch option so it doesn't skip normalisation entirely when s…
JakeGinnivan Aug 13, 2015
1596e71
Removed need for powershell file, using inbuilt branch normalisation
JakeGinnivan Aug 13, 2015
9f58c6d
Using updated task.json file
JakeGinnivan Aug 13, 2015
3191611
GitVersion VSO build task all working
JakeGinnivan Aug 15, 2015
0fec093
Set langversion to stop suggesting c#6 features
JakeGinnivan Aug 15, 2015
c126cae
Renamed zip file for build task
JakeGinnivan Aug 15, 2015
76a0245
Fixed build error
JakeGinnivan Aug 15, 2015
b8577ed
Removed unneded string format
JakeGinnivan Aug 15, 2015
282f1c7
Moved GitPreparerTests into Core test project
JakeGinnivan Aug 16, 2015
79ec96a
Some updates to remote fixture. This will allow cleaner tests going f…
JakeGinnivan Aug 16, 2015
6d986d4
Added some initial tests around branch normalisation
JakeGinnivan Aug 16, 2015
1d767bf
Fixed merge issues
JakeGinnivan Aug 16, 2015
a701b08
Removed unneeded resources
JakeGinnivan Aug 16, 2015
c70bd16
Fixed powershell execution
JakeGinnivan Aug 16, 2015
db6633a
Appveyor settings update
JakeGinnivan Aug 16, 2015
ffdf6a7
Docs update
JakeGinnivan Aug 16, 2015
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ForSample/
*NugetTaskBuild*
*NugetRefBuild*
*NugetExeBuild*
*GitVersionVsoTaskBuild*
*GemBuild*

# Visual Studio profiler
Expand Down
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ build_script:
- cmd: 7z a "GitVersion_%GitVersion_NuGetVersion%.zip" .\build\NuGetCommandLineBuild\Tools\*.*
- cmd: appveyor PushArtifact "GitVersion_%GitVersion_NuGetVersion%.zip"

- ps: .\build\Update-GitVersionVsoTaskVersion.ps1 .\build\GitVersionVsoTaskBuild\task.json $env:GitVersion_Major $env:GitVersion_Minor $env:GitVersion_Patch
- cmd: 7z a "GitVersionVsoBuildTask_%GitVersion_NuGetVersion%.zip" .\build\GitVersionVsoTaskBuild\*.*
- cmd: appveyor PushArtifact "GitVersionVsoBuildTask_%GitVersion_NuGetVersion%.zip"

test_script:
- nunit-console "src\GitVersionTask.Tests\bin\%CONFIGURATION%\GitVersionTask.Tests.dll" "src\GitVersionExe.Tests\bin\%CONFIGURATION%\GitVersionExe.Tests.dll" "src\GitVersionCore.Tests\bin\%CONFIGURATION%\GitVersionCore.Tests.dll" /noshadow

Expand Down
17 changes: 17 additions & 0 deletions build/Update-GitVersionVsoTaskVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
param (
[string] $filePath,
[string] $major,
[string] $minor,
[string] $patch
)

# Get the task.json as a powershell object
$task = Get-Content -Raw -Path $filePath | ConvertFrom-Json

$task.version.Major = $major
$task.version.Minor = $minor
$task.version.Patch = $patch

# get this as a string again

ConvertTo-Json $task | Set-Content -Path $filePath
25 changes: 25 additions & 0 deletions docs/more-info/build-server-setup/tfs-build-vnext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Visual Studio Online (Build vNext) Setup
## Basic Usage
In [Visual Studio Online](https://www.visualstudio.com/) build vNext (the web based build system) you can add GitVersion as a Build Step. This requires a one-time setup to import the GitVersion task into your VSO instance.

## Installing/updating the VSO Build Step
1. Install the `tfx` command line tool as shown [here](https://github.com/Microsoft/tfs-cli/blob/master/docs/buildtasks.md)
2. Download the GitVersion VSO extension from the latest release on the [GitVersion releases page](https://github.com/GitTools/GitVersion/releases) and unzip.
3. Run `tfx login` if you haven't yet, make sure to use `https://<server>.visualstudio.com/DefaultCollection` as the URL and provide a Personal Access Token
4. From the directory outside of where you unzipped the task, run `tfx upload .\GitVersionVsoTask` where GitVersionVsoTask is the directory containing the files.
5. It should successfully install

## Using the GitVersion VSO Build Step
From a VSO vNext Build Definition, select "Add a Step" and then in the Build category, choose GitVersion and Click Add. You'll probably want to drag the task to be at or near the top to ensure it executes before your other build steps.

If you want the GitVersionTask to update AssemblyInfo files, check the box in the task configuration. For advanced usage, you can pass additional options to the GitVersion exe in the Additional arguments section.

## Using the GitVersion Variables
GitVersion writes build parameters into VSO, so they will automatically be passed to your build scripts to use. It also writes GITVERSION_* environment variables that are available for any subsequent build step.


## Running inside Visual Studio Online
* We output the individual values of the GitVersion version as the build parameter: `GitVersion.*` (Eg: `GitVersion.Major`) if you need access to them in your build script

### NuGet in VSO
* If you use a command script to build your NuPkg, use `%GITVERSION_NUGETVERSION%` as the version parameter: `nuget.exe pack path\to\my.nuspec -version %GITVERSION_NUGETVERSION%`
5 changes: 5 additions & 0 deletions src/GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ public override string[] GenerateSetParameterMessage(string name, string value)
{
return new string[0];
}

public override string GetCurrentBranch()
{
throw new NotImplementedException();
}
}
}
27 changes: 27 additions & 0 deletions src/GitVersionCore.Tests/BuildServers/VsoAgentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using GitVersion;
using NUnit.Framework;
using Shouldly;

[TestFixture]
public class VsoAgentTests
{
[Test]
public void Develop_branch()
{
var versionBuilder = new VsoAgent();
var vsVersion = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4");
// Assert.AreEqual("##vso[task.setvariable variable=GitBuildNumber;]0.0.0-Unstable4", vsVersion);

vsVersion.ShouldBe(null);
}

[Test]
public void EscapeValues()
{
var versionBuilder = new VsoAgent();
var vsVersion = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");

vsVersion[0].ShouldBe("##vso[task.setvariable variable=GitVersion.Foo;]0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");
}

}
9 changes: 9 additions & 0 deletions src/GitVersionCore.Tests/Fixtures/LocalRepositoryFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using GitVersion;
using LibGit2Sharp;

public class LocalRepositoryFixture : RepositoryFixtureBase
{
public LocalRepositoryFixture(Config configuration, IRepository repository) : base(configuration, repository)
{
}
}
34 changes: 11 additions & 23 deletions src/GitVersionCore.Tests/Fixtures/RemoteRepositoryFixture.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
using System;

using GitVersion;
using LibGit2Sharp;
using GitVersion;
using LibGit2Sharp;

public class RemoteRepositoryFixture : RepositoryFixtureBase
{
public string LocalRepositoryPath;
public IRepository LocalRepository;

public RemoteRepositoryFixture(Func<string, IRepository> builder, Config configuration)
: base(builder, configuration)
{
CloneRepository();
CreateLocalRepository();
}

public RemoteRepositoryFixture(Config configuration)
: base(CreateNewRepository, configuration)
{
CloneRepository();
CreateLocalRepository();
}

public LocalRepositoryFixture LocalRepositoryFixture { get; private set; }


/// <summary>
/// Simulates running on build server
/// </summary>
public void InitialiseRepo()
{
new GitPreparer(null, null, new Authentication(), null, false, LocalRepositoryPath).Initialise(true);
new GitPreparer(null, null, new Authentication(), null, false, LocalRepositoryFixture.RepositoryPath).Initialise(true, null);
}

static IRepository CreateNewRepository(string path)
Expand All @@ -38,25 +37,14 @@ static IRepository CreateNewRepository(string path)
return repo;
}

void CloneRepository()
void CreateLocalRepository()
{
LocalRepositoryPath = PathHelper.GetTempPath();
LibGit2Sharp.Repository.Clone(RepositoryPath, LocalRepositoryPath);
LocalRepository = new Repository(LocalRepositoryPath);
LocalRepositoryFixture = CloneRepository();
}

public override void Dispose()
{
LocalRepository.Dispose();
try
{
DirectoryHelper.DeleteDirectory(LocalRepositoryPath);
}
catch (Exception e)
{
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", RepositoryPath, e.Message);
}

LocalRepositoryFixture.Dispose();
base.Dispose();
}
}
19 changes: 15 additions & 4 deletions src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@
public abstract class RepositoryFixtureBase : IDisposable
{
Dictionary<string, string> participants = new Dictionary<string, string>();
public string RepositoryPath;
public IRepository Repository;
Config configuration;
StringBuilder diagramBuilder;

protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder, Config configuration)
: this(configuration, repoBuilder(PathHelper.GetTempPath()))
{
}

protected RepositoryFixtureBase(Config configuration, IRepository repository)
{
ConfigurationProvider.ApplyDefaultsTo(configuration);
diagramBuilder = new StringBuilder();
diagramBuilder.AppendLine("@startuml");
this.configuration = configuration;
RepositoryPath = PathHelper.GetTempPath();
Repository = repoBuilder(RepositoryPath);
Repository = repository;
Repository.Config.Set("user.name", "Test");
Repository.Config.Set("user.email", "[email protected]");
IsForTrackedBranchOnly = true;
}

public bool IsForTrackedBranchOnly { private get; set; }
public IRepository Repository { get; private set; }
public string RepositoryPath { get { return Repository.Info.WorkingDirectory.TrimEnd('\\'); } }

public void Checkout(string branch)
{
Expand Down Expand Up @@ -190,4 +194,11 @@ public virtual void Dispose()
Trace.WriteLine(string.Empty);
Trace.WriteLine(diagramBuilder.ToString());
}

public LocalRepositoryFixture CloneRepository(Config config = null)
{
var localPath = PathHelper.GetTempPath();
LibGit2Sharp.Repository.Clone(RepositoryPath, localPath);
return new LocalRepositoryFixture(config ?? new Config(), new Repository(localPath));
}
}
75 changes: 75 additions & 0 deletions src/GitVersionCore.Tests/GitHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace GitVersionCore.Tests
{
using GitVersion;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;

public class GitHelperTests
{
[Test]
public void NormalisationOfPullRequestsWithFetch()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeACommit();

fixture.Repository.CreateBranch("feature/foo").Checkout();
fixture.Repository.MakeACommit();
var commit = fixture.Repository.CreatePullRequestRef("feature/foo", "master", prNumber: 3);
using (var localFixture = fixture.CloneRepository())
{
localFixture.Checkout(commit.Sha);
GitHelper.NormalizeGitDirectory(localFixture.RepositoryPath, new Authentication(), noFetch: false, currentBranch: string.Empty);

var normalisedPullBranch = localFixture.Repository.FindBranch("pull/3/merge");
normalisedPullBranch.ShouldNotBe(null);
}
}
}

[Test]
public void NormalisationOfPullRequestsWithoutFetch()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeACommit();

fixture.Repository.CreateBranch("feature/foo").Checkout();
fixture.Repository.MakeACommit();
var commit = fixture.Repository.CreatePullRequestRef("feature/foo", "master", prNumber: 3, allowFastFowardMerge: true);
using (var localFixture = fixture.CloneRepository())
{
localFixture.Checkout(commit.Sha);
GitHelper.NormalizeGitDirectory(localFixture.RepositoryPath, new Authentication(), noFetch: true, currentBranch: "refs/pull/3/merge");

var normalisedPullBranch = localFixture.Repository.FindBranch("pull/3/merge");
normalisedPullBranch.ShouldNotBe(null);
}
}
}

[Test]
public void UpdatesLocalBranchesWhen()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeACommit();

fixture.Repository.CreateBranch("feature/foo").Checkout();
fixture.Repository.MakeACommit();
using (var localFixture = fixture.CloneRepository())
{
localFixture.Checkout("feature/foo");
// Advance remote
var advancedCommit = fixture.Repository.MakeACommit();
GitHelper.NormalizeGitDirectory(localFixture.RepositoryPath, new Authentication(), noFetch: false, currentBranch: null);

var normalisedBranch = localFixture.Repository.FindBranch("feature/foo");
normalisedBranch.ShouldNotBe(null);
normalisedBranch.Tip.Sha.ShouldBe(advancedCommit.Sha);
}
}
}
}
}
Loading