From 80a27bc5c39b4c9d1f50988f728a1401670896da Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 29 Dec 2014 22:32:12 +0100 Subject: [PATCH] Adding better build labeller --- .../SharedLabeller/Properties/AssemblyInfo.cs | 36 +++++ .../Building/SharedLabeller/SharedLabeller.cs | 133 ++++++++++++++++++ .../SharedLabeller/SharedLabeller.csproj | 65 +++++++++ .../SharedLabeller/SharedLabeller.sln | 20 +++ ...et.SharedLabeller.CruiseControl.plugin.dll | Bin 0 -> 7168 bytes 5 files changed, 254 insertions(+) create mode 100644 BuildFiles/Building/SharedLabeller/Properties/AssemblyInfo.cs create mode 100644 BuildFiles/Building/SharedLabeller/SharedLabeller.cs create mode 100644 BuildFiles/Building/SharedLabeller/SharedLabeller.csproj create mode 100644 BuildFiles/Building/SharedLabeller/SharedLabeller.sln create mode 100644 BuildFiles/Building/ccnet.SharedLabeller.CruiseControl.plugin.dll diff --git a/BuildFiles/Building/SharedLabeller/Properties/AssemblyInfo.cs b/BuildFiles/Building/SharedLabeller/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..16a68f15 --- /dev/null +++ b/BuildFiles/Building/SharedLabeller/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SharedLabeller")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SharedLabeller")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("71a8ae4e-af6d-42fd-b62a-96c09044e24a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BuildFiles/Building/SharedLabeller/SharedLabeller.cs b/BuildFiles/Building/SharedLabeller/SharedLabeller.cs new file mode 100644 index 00000000..64ac1569 --- /dev/null +++ b/BuildFiles/Building/SharedLabeller/SharedLabeller.cs @@ -0,0 +1,133 @@ +using System.IO; +using System.Text; + +using Exortech.NetReflector; +using ThoughtWorks.CruiseControl.Core; +using ThoughtWorks.CruiseControl.Remote; + +// this namespace could be altered and several classes could be put into the same if you'd want to combine several plugins in one dll +namespace ccnet.SharedLabeller.CruiseControl.plugin +{ + [ReflectorType("sharedLabeller")] + public class SharedLabeller : ILabeller + { + /// + /// The path where the file that holds the shared label should be located + /// + /// none + [ReflectorProperty("sharedLabelFilePath", Required = true)] + public string SharedLabelFilePath { get; set; } + + /// + /// Any string to be put in front of all labels. Mutually exclusive with PrefixFile. + /// + [ReflectorProperty("prefix", Required = false)] + public string Prefix { get; set; } + + /// + /// File with string to be put in front of all labels. Mutually exclusive with Prefix. + /// + [ReflectorProperty("prefixFile", Required = false)] + public string PrefixFile { get; set; } + + /// + /// If true, the label will be incremented even if the build fails. Otherwise it will only be incremented if the build succeeds. + /// + [ReflectorProperty("incrementOnFailure", Required = false)] + public bool IncrementOnFailure { get; set; } + + /// + /// If false, the label will never be incremented when this project is builded. This is usefull for deployment builds that + /// should use the last successfull of two or more builds + /// + [ReflectorProperty("increment", Required = false)] + public bool Increment { get; set; } + + /// + /// Allows you to set the initial build number. + /// This will only be used when on the first build of a project, meaning that when you change this value, + /// you'll have to stop the CCNet service and delete the state file. + /// + /// 0 + [ReflectorProperty("initialBuildLabel", Required = false)] + public int InitialBuildLabel { get; set; } + + public SharedLabeller() + { + IncrementOnFailure = false; + Increment = true; + InitialBuildLabel = 768; + } + + #region ILabeller Members + + public string Generate(IIntegrationResult integrationResult) + { + if (ShouldIncrementLabel(integrationResult.LastIntegration)) + { + return Prefix + this.GetLabel(); + } + else + { + return integrationResult.LastIntegration.Label; + } + } + + public void Run(IIntegrationResult integrationResult) + { + integrationResult.Label = Generate(integrationResult); + } + + #endregion + + /// + /// Get and increments the label, unless increment is false then it only gets the label + /// + /// + private string GetLabel() + { + ThoughtWorks.CruiseControl.Core.Util.Log.Debug("About to read label prefix file. Filename: {0}", PrefixFile); + string prefix = System.IO.File.ReadAllText (PrefixFile).Trim(); + + ThoughtWorks.CruiseControl.Core.Util.Log.Debug("About to read build number file. Filename: {0}", SharedLabelFilePath); + using (FileStream fileStream = File.Open(this.SharedLabelFilePath, + FileMode.OpenOrCreate, + FileAccess.ReadWrite, + FileShare.None)) + { + // read last build number from file + var bytes = new byte[fileStream.Length]; + fileStream.Read(bytes, 0, bytes.Length); + + string rawBuildNumber = Encoding.UTF8.GetString(bytes); + + // parse last build number + int previousBuildNumber; + if (!int.TryParse(rawBuildNumber, out previousBuildNumber)) + { + previousBuildNumber = InitialBuildLabel - 1; + } + + if (!Increment) + { + return previousBuildNumber.ToString(); + } + + int newBuildNumber = previousBuildNumber + 1; + + // increment build number and write back to file + bytes = Encoding.UTF8.GetBytes(newBuildNumber.ToString()); + + fileStream.Seek(0, SeekOrigin.Begin); + fileStream.Write(bytes, 0, bytes.Length); + + return newBuildNumber.ToString(); + } + } + + private bool ShouldIncrementLabel(IntegrationSummary integrationSummary) + { + return integrationSummary == null || integrationSummary.Status == IntegrationStatus.Success || IncrementOnFailure; + } + } +} \ No newline at end of file diff --git a/BuildFiles/Building/SharedLabeller/SharedLabeller.csproj b/BuildFiles/Building/SharedLabeller/SharedLabeller.csproj new file mode 100644 index 00000000..4e00f4e9 --- /dev/null +++ b/BuildFiles/Building/SharedLabeller/SharedLabeller.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409} + Library + Properties + SharedLabeller + ccnet.SharedLabeller.CruiseControl.plugin + v3.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\NetReflector.dll + + + + + + + + + ..\ThoughtWorks.CruiseControl.Core.dll + + + ..\ThoughtWorks.CruiseControl.MSBuild.dll + + + ..\ThoughtWorks.CruiseControl.Remote.dll + + + + + + + + + \ No newline at end of file diff --git a/BuildFiles/Building/SharedLabeller/SharedLabeller.sln b/BuildFiles/Building/SharedLabeller/SharedLabeller.sln new file mode 100644 index 00000000..239bb43d --- /dev/null +++ b/BuildFiles/Building/SharedLabeller/SharedLabeller.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedLabeller", "SharedLabeller.csproj", "{AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/BuildFiles/Building/ccnet.SharedLabeller.CruiseControl.plugin.dll b/BuildFiles/Building/ccnet.SharedLabeller.CruiseControl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