Skip to content

Commit

Permalink
Fix issues with packing solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
WaelHamze committed Jan 28, 2019
1 parent 590123f commit 6302e68
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void LogVerbose(string format, params object[] args)
string msg = PrefixMsg("Verbose: ", format);
if (args.Length != 0)
{
Debug.WriteLine(format, msg);
Debug.WriteLine(msg, args);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ public void TestPackSolutions()

SolutionPackConfig config = new SolutionPackConfig();
config.Solutions.Add(new SolutionPackOptions()
{
Folder = folder,
MappingFile = mapping,
IncludeVersionInName = true,
PackageType = SolutionPackager_PackageType.Both,
TreamWarningsAsErrors = false,
{
Folder = folder,
MappingFile = mapping,
IncludeVersionInName = true,
PackageType = SolutionPackager_PackageType.Both,
TreamWarningsAsErrors = false,
IncrementReleaseVersion = true,
Version = string.Empty
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ bool treatWarningsAsErrors
{
StringBuilder arguments = new StringBuilder();

Logger.LogVerbose("Generating Solution Packager Arguments");

arguments.Append($" /action:{action.ToString()}");
arguments.Append($" /zipFile:\"{ZipFile}\"");
arguments.Append($" /folder:\"{Folder}\"");
Expand Down Expand Up @@ -183,6 +185,8 @@ bool treatWarningsAsErrors
arguments.Append($" /localize");
}

Logger.LogVerbose("Solution Packager Arguments: {0}", arguments.ToString());

ProcessStartInfo packagerInfo = new ProcessStartInfo()
{
FileName = Packager,
Expand All @@ -202,13 +206,17 @@ bool treatWarningsAsErrors
packagerProcess.OutputDataReceived += PackagerProcess_OutputDataReceived;
packagerProcess.ErrorDataReceived += PackagerProcess_ErrorDataReceived;

Logger.LogVerbose("Invoking SolutionPackager: {0}", Packager);

bool start = packagerProcess.Start();
packagerProcess.BeginOutputReadLine();
packagerProcess.BeginErrorReadLine();

packagerProcess.WaitForExit(1000*60*15); //15 minutes

exitCode = packagerProcess.ExitCode;

Logger.LogVerbose("SolutionPackager exit code@ {0}", exitCode);
}

if (exitCode != 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xrm.Framework.CI.Common.Logging;

namespace Xrm.Framework.CI.Common
Expand All @@ -24,11 +21,14 @@ public SolutionPackagerManager(

public bool PackSolution(
string solutionPackager,
string outputFolder,
string folder,
SolutionPackager_PackageType packageType,
bool includeVersionInName,
string mappingFile,
bool treatWarningsAsErrors,
bool incrementReleaseVersion,
string version,
string logsDirectory
)
{
Expand All @@ -42,6 +42,32 @@ string logsDirectory
throw new Exception("Invalid solution file");
}

Logger.LogInformation("Packing Solution Name: {0} - Version {1}", info.UniqueName, info.Version);

string newVersion;

if (incrementReleaseVersion)
{
Logger.LogVerbose("Incrementing release version");

int release = Int32.Parse(info.Version.Substring(info.Version.LastIndexOf(".") + 1));
newVersion = $"{info.Version.Substring(0, info.Version.LastIndexOf(".") + 1)}{release + 1}";

solutionXml.UpdateSolutionVersion(folder, newVersion);
}
else if (!string.IsNullOrEmpty(version))
{
Logger.LogInformation("Updating solution version to {0}", version);

solutionXml.UpdateSolutionVersion(folder, version);

newVersion = version;
}
else
{
newVersion = info.Version;
}

SolutionNameGenerator generator = new SolutionNameGenerator();

string zipFile;
Expand All @@ -51,7 +77,7 @@ string logsDirectory
{
zipFile = generator.GetZipName(
info.UniqueName,
info.Version,
newVersion,
managed);
}
else
Expand All @@ -61,13 +87,18 @@ string logsDirectory
string.Empty,
managed);
}
string zipFilePath = $"{outputFolder}\\{zipFile}";

string log = $"PackagerLog_{zipFile.Replace(".zip", "")}_{DateTime.Now.ToString("yyyy_MM_dd__HH_mm")}.txt";
Logger.LogVerbose("zipFile: {0}", zipFilePath);

string log = $"{logsDirectory}\\PackagerLog_{zipFile.Replace(".zip", "")}_{DateTime.Now.ToString("yyyy_MM_dd__HH_mm")}.txt";

Logger.LogVerbose("log: {0}", log);

SolutionPackager packager = new SolutionPackager(
Logger,
solutionPackager,
zipFile,
zipFilePath,
folder,
log
);
Expand All @@ -84,6 +115,26 @@ public List<bool> PackSolutions(
string configFilePath,
string logsDirectory)
{
if (!File.Exists(solutionPackager))
{
throw new Exception(string.Format("SolutionPackager.exe file couldn't be found at {0}", solutionPackager));
}

if (!Directory.Exists(outputFolder))
{
throw new Exception(string.Format("outputFolder couldn't be found at {0}", outputFolder));
}

if (!File.Exists(configFilePath))
{
throw new Exception(string.Format("Config file couldn't be found at {0}", configFilePath));
}

if (!Directory.Exists(logsDirectory))
{
throw new Exception(string.Format("logsDirectory couldn't be found at {0}", logsDirectory));
}

SolutionPackConfig config =
Serializers.ParseJson<SolutionPackConfig>(configFilePath);

Expand All @@ -98,11 +149,14 @@ public List<bool> PackSolutions(

bool result = PackSolution(
solutionPackager,
outputFolder,
folder,
option.PackageType,
option.IncludeVersionInName,
mapping,
option.TreamWarningsAsErrors,
option.IncrementReleaseVersion,
option.Version,
logsDirectory
);

Expand All @@ -114,6 +168,8 @@ public List<bool> PackSolutions(
}
}

Logger.LogInformation("{0} solutions processed out of {1}", results.Count, config.Solutions.Count);

return results;
}
}
Expand All @@ -127,6 +183,7 @@ public class SolutionPackOptions
public SolutionPackager_PackageType PackageType { get; set; }
public bool IncludeVersionInName { get; set; }
public bool TreamWarningsAsErrors { get; set; }
public bool IncrementReleaseVersion { get; set; }
public string Version { get; set; }

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ public XrmSolutionInfo GetXrmSolutionInfoFromFolder(
}
}

public void UpdateSolutionVersion(string folder, string version)
{
string solutionFile = folder + "\\Other\\Solution.xml";

Logger.LogVerbose("Reading Solution File: {0}", solutionFile);

XElement solutionNode;

using (var reader = new StreamReader(solutionFile))
{
solutionNode = XElement.Load(reader);
string uniqueName = solutionNode.Descendants("UniqueName").First().Value;

Logger.LogVerbose(string.Format("Updating Version for Solution: {0}", uniqueName));

solutionNode.Descendants("Version").First().Value = version;
}

solutionNode.Save(solutionFile);

Logger.LogInformation("Version Updated to: {0}", version);
}

private XrmSolutionInfo GetXrmSolutionInfoFromStream(StreamReader reader)
{
XrmSolutionInfo info = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Xrm.Framework.CI.PowerShell.Cmdlets
/// <code>C:\PS>Export-XrmSolution -ConnectionString "" -EntityName "account"</code>
/// <para>Exports the "" managed solution to "" location</para>
/// </example>
[Cmdlet(VerbsData.Compress, "XrmSolution")]
[Cmdlet(VerbsData.Compress, "XrmSolutions")]
[OutputType(typeof(WhoAmIResponse))]
public class CompressXrmSolutionUsingConfig : CommandBase
{
Expand Down Expand Up @@ -57,7 +57,7 @@ protected override void ProcessRecord()

SolutionPackagerManager packagerManager = new SolutionPackagerManager(Logger);

List<bool> results = packagerManager.PackSolutions(SolutionPackagerPath, LogsDirectory, ConfigFilePath, LogsDirectory);
List<bool> results = packagerManager.PackSolutions(SolutionPackagerPath, OutputFolder, ConfigFilePath, LogsDirectory);

if (results.Contains(false))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ param(
[string]$solutionPackagerPath, #Path to solutionpackager.exe
[string]$OutputFolder,
[string]$ConfigFilePath,
[int]$LogsDirectory
[string]$LogsDirectory
)

$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"

Write-Verbose 'Entering PackSolutionsUsingConfig.ps1'

Expand Down

0 comments on commit 6302e68

Please sign in to comment.