-
Notifications
You must be signed in to change notification settings - Fork 654
Adding support to generate WiX version files #1386
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
Closed
ruhullahshah
wants to merge
7
commits into
GitTools:master
from
ruhullahshah:feature/add_support_for_emitting_vars_in_wix_format
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c0364c
Adding support to generate Wix version files
ruhullahshah 131e1ba
Merge branch 'master' into feature/add_support_for_emitting_vars_in_w…
ruhullahshah 8513d23
Added Testcases
ruhullahshah 423b388
Merge branch 'master' into feature/add_support_for_emitting_vars_in_w…
ruhullahshah d7a737f
Merge branch 'master' into feature/add_support_for_emitting_vars_in_w…
ruhullahshah 9874d50
Merge branch 'master' into feature/add_support_for_emitting_vars_in_w…
ruhullahshah f2e279e
Revert "Merge branch 'master' into feature/add_support_for_emitting_v…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace GitVersion | ||
{ | ||
using Helpers; | ||
|
||
using System; | ||
using System.Text; | ||
using System.Xml; | ||
|
||
public class WixVersionFileUpdater : IDisposable | ||
{ | ||
string workingDirectory; | ||
VersionVariables variables; | ||
IFileSystem fileSystem; | ||
private const string WIX_VERSION_FILE = "GitVersion_WixVersion.wxi "; | ||
|
||
public WixVersionFileUpdater(string workingDirectory, VersionVariables variables, IFileSystem fileSystem) | ||
{ | ||
this.workingDirectory = workingDirectory; | ||
this.variables = variables; | ||
this.fileSystem = fileSystem; | ||
} | ||
|
||
public static string GetWixVersionFileName() | ||
{ | ||
return WIX_VERSION_FILE; | ||
} | ||
|
||
public void Update() | ||
{ | ||
Logger.WriteInfo("Updating GitVersion_WixVersion.wxi"); | ||
|
||
XmlDocument doc = new XmlDocument(); | ||
doc.LoadXml(GetWixFormatFromVersionVariables()); | ||
|
||
XmlDeclaration xmlDecl = doc.CreateXmlDeclaration("1.0", "utf-8", null); | ||
XmlElement root = doc.DocumentElement; | ||
doc.InsertBefore(xmlDecl, root); | ||
|
||
using (var fs = fileSystem.OpenWrite(WIX_VERSION_FILE)) | ||
{ | ||
doc.Save(fs); | ||
} | ||
} | ||
|
||
private string GetWixFormatFromVersionVariables() | ||
{ | ||
StringBuilder builder = new StringBuilder(); | ||
builder.Append("<Include xmlns=\"http://schemas.microsoft.com/wix/2006/wi\">\n"); | ||
var availableVariables = VersionVariables.AvailableVariables; | ||
foreach (var variable in availableVariables) | ||
{ | ||
string value = null; | ||
variables.TryGetValue(variable, out value); | ||
builder.Append(string.Format("\t<?define {0}=\"{1}\"?>\n", variable, value)); | ||
} | ||
builder.Append("</Include>\n"); | ||
return builder.ToString(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Logger.WriteInfo(string.Format("Done writing {0}", WIX_VERSION_FILE)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
namespace GitVersionExe.Tests | ||
{ | ||
using System.IO; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
|
||
using GitVersion; | ||
using GitTools.Testing; | ||
using System.Collections.Generic; | ||
using System.Xml; | ||
|
||
[TestFixture] | ||
class UpdateWixVersionFileTests | ||
{ | ||
private string WixVersionFileName; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
WixVersionFileName = WixVersionFileUpdater.GetWixVersionFileName(); | ||
} | ||
|
||
[Test] | ||
public void WixVersionFileCreationTest() | ||
{ | ||
using (var fixture = new EmptyRepositoryFixture()) | ||
{ | ||
fixture.MakeATaggedCommit("1.2.3"); | ||
fixture.MakeACommit(); | ||
|
||
GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile"); | ||
Assert.IsTrue(File.Exists(Path.Combine(fixture.RepositoryPath, WixVersionFileName))); | ||
} | ||
} | ||
|
||
[Test] | ||
public void WixVersionFileVarCountTest() | ||
{ | ||
//Make sure we have captured all the version variables by count in the Wix version file | ||
using (var fixture = new EmptyRepositoryFixture()) | ||
{ | ||
fixture.MakeATaggedCommit("1.2.3"); | ||
fixture.MakeACommit(); | ||
|
||
var gitVersionExecutionResults = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null); | ||
VersionVariables vars = gitVersionExecutionResults.OutputVariables; | ||
|
||
GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile"); | ||
|
||
var gitVersionVarsInWix = GetGitVersionVarsInWixFile(Path.Combine(fixture.RepositoryPath, WixVersionFileName)); | ||
var gitVersionVars = VersionVariables.AvailableVariables; | ||
|
||
Assert.AreEqual(gitVersionVars.Count(), gitVersionVarsInWix.Count); | ||
} | ||
} | ||
|
||
[Test] | ||
public void WixVersionFileContentTest() | ||
{ | ||
using (var fixture = new EmptyRepositoryFixture()) | ||
{ | ||
fixture.MakeATaggedCommit("1.2.3"); | ||
fixture.MakeACommit(); | ||
|
||
var gitVersionExecutionResults = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null); | ||
VersionVariables vars = gitVersionExecutionResults.OutputVariables; | ||
|
||
GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile"); | ||
|
||
var gitVersionVarsInWix = GetGitVersionVarsInWixFile(Path.Combine(fixture.RepositoryPath, WixVersionFileName)); | ||
var gitVersionVars = VersionVariables.AvailableVariables; | ||
|
||
foreach (var variable in gitVersionVars) | ||
{ | ||
string value = null; | ||
vars.TryGetValue(variable, out value); | ||
//Make sure the variable is present in the Wix file | ||
Assert.IsTrue(gitVersionVarsInWix.ContainsKey(variable)); | ||
//Make sure the values are equal | ||
Assert.AreEqual(value, gitVersionVarsInWix[variable]); | ||
} | ||
} | ||
} | ||
|
||
private Dictionary<string, string> GetGitVersionVarsInWixFile(string file) | ||
{ | ||
var gitVersionVarsInWix = new Dictionary<string, string>(); | ||
using (var reader = new XmlTextReader(file)) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
if (reader.Name == "define") | ||
{ | ||
string[] component = reader.Value.Split('='); | ||
gitVersionVarsInWix[component[0]] = component[1].TrimStart('"').TrimEnd('"'); | ||
} | ||
} | ||
} | ||
return gitVersionVarsInWix; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only
GitVersionExe
tests and not forGitVersionCore
? Also, don't you agree approval tests such as this is better suited for file manipulation testing such as this?GitVersion/src/GitVersionCore.Tests/AssemblyInfoFileUpdaterTests.cs
Lines 26 to 40 in ee5b77a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain this in detail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure. Approval tests allows you to create a file on disk that is what the test is compared against. If the content matches, the test is successful, otherwise it fails and a diff is presented.
The above test will verify the manipulated file content against the following approved text file:
GitVersion/src/GitVersionCore.Tests/Approved/cs/AssemblyInfoFileUpdaterTests.ShouldCreateAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo.approved.txt
Lines 1 to 13 in ee5b77a