From 3f23d1de3f7f90d1632e34ace774e2b7886010a8 Mon Sep 17 00:00:00 2001 From: Westin Miller Date: Wed, 30 Aug 2017 15:02:43 -0700 Subject: [PATCH 1/2] New versioning system. --- Concealment/Properties/AssemblyInfo.cs | 33 ++++++-------------------- Jenkinsfile | 4 ++-- Versioning/AssemblyVersion.cs | 4 ++++ Versioning/version.ps1 | 20 ++++++++++++++++ 4 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 Versioning/AssemblyVersion.cs create mode 100644 Versioning/version.ps1 diff --git a/Concealment/Properties/AssemblyInfo.cs b/Concealment/Properties/AssemblyInfo.cs index 88ed95a..da86832 100644 --- a/Concealment/Properties/AssemblyInfo.cs +++ b/Concealment/Properties/AssemblyInfo.cs @@ -1,36 +1,17 @@ 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("Concealment")] [assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Concealment")] -[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyProduct("Torch")] +[assembly: AssemblyCopyright("Copyright © Torch API 2017")] [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("e5c0184b-7dc4-43d8-872e-2f71162748aa")] - -// 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")] +#if DEBUG +[assembly: AssemblyConfiguration("Debug")] +#else +[assembly: AssemblyConfiguration("Release")] +#endif \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 7eeb302..84adddf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,8 +9,8 @@ def test_with_torch(branch) } stage('Build + Torch ' + branch) { - bat "\"${tool 'MSBuild'}msbuild\" Concealment.sln /p:Configuration=Release /p:Platform=x64 /t:Clean" - // bat "\"${tool 'MSBuild'}msbuild\" Concealment.sln /p:Configuration=Release /p:Platform=x64 /t:TransformOnBuild" + currentBuild.description = bat(returnStdout: true, script: '@powershell -File Versioning/version.ps1').trim() + bat "\"${tool 'MSBuild'}msbuild\" Essentials.sln /p:Configuration=Release /p:Platform=x64 /t:Clean" bat "\"${tool 'MSBuild'}msbuild\" Concealment.sln /p:Configuration=Release /p:Platform=x64" } diff --git a/Versioning/AssemblyVersion.cs b/Versioning/AssemblyVersion.cs new file mode 100644 index 0000000..c663bea --- /dev/null +++ b/Versioning/AssemblyVersion.cs @@ -0,0 +1,4 @@ +using System.Reflection; + +[assembly: AssemblyVersion("0.0.0.0")] +[assembly: AssemblyInformationalVersion("v0.0.0-dev")] diff --git a/Versioning/version.ps1 b/Versioning/version.ps1 new file mode 100644 index 0000000..2e624b4 --- /dev/null +++ b/Versioning/version.ps1 @@ -0,0 +1,20 @@ +$gitVersion = git describe --tags +$gitSimpleVersion = git describe --tags --abbrev=0 +if ($gitSimpleVersion.Equals($gitVersion)) { + $buildSalt = 0 +} else { + $gitLatestCommit = git rev-parse --short HEAD + $buildSalt = [System.Numerics.BigInteger]::Abs([System.Numerics.BigInteger]::Parse($gitLatestCommit, [System.Globalization.NumberStyles]::HexNumber) % 16383) + 1 +} +$dotNetVersion = echo $gitSimpleVersion | Select-String -Pattern "([0-9]+)\.([0-9]+)\.([0-9]+)" | % {$_.Matches} | %{$_.Groups[1].Value+"."+$_.Groups[2].Value+"."+$_.Groups[3].Value+".$buildSalt"} + +$fileContent = @" +using System.Reflection; + +[assembly: AssemblyVersion("$dotNetVersion")] +[assembly: AssemblyInformationalVersion("$gitVersion")] +"@ + +echo $fileContent | Set-Content "$PSScriptRoot/AssemblyVersion.cs" + +echo "$gitVersion / $dotNetVersion" \ No newline at end of file From 6fd5cbfdc5b58e2a1095b04bd9a0df5013cbaf18 Mon Sep 17 00:00:00 2001 From: Westin Miller Date: Wed, 30 Aug 2017 22:56:48 -0700 Subject: [PATCH 2/2] Testing Project Automatic Versioning --- Concealment.Tests/Concealment.Tests.csproj | 93 ++++++++++++++++++++ Concealment.Tests/Properties/AssemblyInfo.cs | 17 ++++ Concealment.Tests/ReflectionTestManager.cs | 72 +++++++++++++++ Concealment.Tests/TestUtils.cs | 35 ++++++++ Concealment.Tests/TorchReflectionTest.cs | 72 +++++++++++++++ Concealment.Tests/packages.config | 12 +++ Concealment.sln | 13 ++- Concealment/Concealment.csproj | 3 + Concealment/ConcealmentPlugin.cs | 2 +- Jenkinsfile | 7 +- 10 files changed, 321 insertions(+), 5 deletions(-) create mode 100644 Concealment.Tests/Concealment.Tests.csproj create mode 100644 Concealment.Tests/Properties/AssemblyInfo.cs create mode 100644 Concealment.Tests/ReflectionTestManager.cs create mode 100644 Concealment.Tests/TestUtils.cs create mode 100644 Concealment.Tests/TorchReflectionTest.cs create mode 100644 Concealment.Tests/packages.config diff --git a/Concealment.Tests/Concealment.Tests.csproj b/Concealment.Tests/Concealment.Tests.csproj new file mode 100644 index 0000000..8775b42 --- /dev/null +++ b/Concealment.Tests/Concealment.Tests.csproj @@ -0,0 +1,93 @@ + + + + + {53EFDFD0-9BCA-4E67-ABB2-628715E3F74B} + Library + Properties + Concealment.Tests + Concealment.Tests + v4.6.1 + 512 + + + + 1591,0649 + + + true + $(SolutionDir)\bin-test\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + $(SolutionDir)\bin-test\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + $(SolutionDir)\bin-test\x64\Release\Concealment.Tests.xml + + + + ..\packages\NLog.4.4.12\lib\net45\NLog.dll + True + + + + + + + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll + + + ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll + + + $(SolutionDir)\TorchBinaries\Torch.dll + True + + + $(SolutionDir)\TorchBinaries\Torch.API.dll + True + + + + + Properties\AssemblyVersion.cs + + + + + + + + + {E5C0184B-7DC4-43D8-872E-2F71162748AA} + Concealment + True + + + + + + + + + + \ No newline at end of file diff --git a/Concealment.Tests/Properties/AssemblyInfo.cs b/Concealment.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1551025 --- /dev/null +++ b/Concealment.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,17 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Torch Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Torch")] +[assembly: AssemblyCopyright("Copyright © Torch API 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] + +#if DEBUG +[assembly: AssemblyConfiguration("Debug")] +#else +[assembly: AssemblyConfiguration("Release")] +#endif \ No newline at end of file diff --git a/Concealment.Tests/ReflectionTestManager.cs b/Concealment.Tests/ReflectionTestManager.cs new file mode 100644 index 0000000..425024e --- /dev/null +++ b/Concealment.Tests/ReflectionTestManager.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using Torch.Utils; + +namespace Torch.Tests +{ + public class ReflectionTestManager + { + #region FieldProvider + public struct FieldRef + { + public FieldInfo Field; + + public FieldRef(FieldInfo f) + { + Field = f; + } + + public override string ToString() + { + if (Field == null) + return "Ignored"; + return Field.DeclaringType?.FullName + "." + Field.Name; + } + } + + private readonly HashSet _getters = new HashSet(); + private readonly HashSet _setters = new HashSet(); + private readonly HashSet _invokers = new HashSet(); + + public ReflectionTestManager() + { + _getters.Add(new object[] { new FieldRef(null) }); + _setters.Add(new object[] { new FieldRef(null) }); + _invokers.Add(new object[] { new FieldRef(null) }); + } + + public ReflectionTestManager Init(Assembly asm) + { + foreach (Type type in asm.GetTypes()) + Init(type); + return this; + } + + public ReflectionTestManager Init(Type type) + { + foreach (FieldInfo field in type.GetFields(BindingFlags.Static | + BindingFlags.Instance | + BindingFlags.Public | + BindingFlags.NonPublic)) + { + if (field.GetCustomAttribute() != null) + _invokers.Add(new object[] { new FieldRef(field) }); + if (field.GetCustomAttribute() != null) + _getters.Add(new object[] { new FieldRef(field) }); + if (field.GetCustomAttribute() != null) + _setters.Add(new object[] { new FieldRef(field) }); + } + return this; + } + + public IEnumerable Getters => _getters; + + public IEnumerable Setters => _setters; + + public IEnumerable Invokers => _invokers; + + #endregion + + } +} diff --git a/Concealment.Tests/TestUtils.cs b/Concealment.Tests/TestUtils.cs new file mode 100644 index 0000000..323186b --- /dev/null +++ b/Concealment.Tests/TestUtils.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Torch.Utils; + +namespace Torch.Tests +{ + public sealed class TestUtils + { + public static void Init() + { + if (_torchResolver == null) + _torchResolver = new TorchAssemblyResolver(GetGameBinaries()); + } + + private static string GetGameBinaries() + { + string dir = Environment.CurrentDirectory; + while (!string.IsNullOrWhiteSpace(dir)) + { + string gameBin = Path.Combine(dir, "GameBinaries"); + if (Directory.Exists(gameBin)) + return gameBin; + + dir = Path.GetDirectoryName(dir); + } + throw new Exception("GetGameBinaries failed to find a folder named GameBinaries in the directory tree"); + } + + private static TorchAssemblyResolver _torchResolver; + } +} diff --git a/Concealment.Tests/TorchReflectionTest.cs b/Concealment.Tests/TorchReflectionTest.cs new file mode 100644 index 0000000..88b0574 --- /dev/null +++ b/Concealment.Tests/TorchReflectionTest.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Torch.Tests; +using Torch.Utils; +using Xunit; + +namespace Concealment.Tests +{ + public class TorchReflectionTest + { + static TorchReflectionTest() + { + TestUtils.Init(); + } + + private static ReflectionTestManager _manager; + + private static ReflectionTestManager Manager() + { + TestUtils.Init(); + if (_manager != null) + return _manager; + return _manager = new ReflectionTestManager().Init(typeof(ConcealmentPlugin).Assembly); + } + + public static IEnumerable Getters => Manager().Getters; + + public static IEnumerable Setters => Manager().Setters; + + public static IEnumerable Invokers => Manager().Invokers; + + #region Binding + [Theory] + [MemberData(nameof(Getters))] + public void TestBindingGetter(ReflectionTestManager.FieldRef field) + { + if (field.Field == null) + return; + Assert.True(ReflectedManager.Process(field.Field)); + if (field.Field.IsStatic) + Assert.NotNull(field.Field.GetValue(null)); + } + + [Theory] + [MemberData(nameof(Setters))] + public void TestBindingSetter(ReflectionTestManager.FieldRef field) + { + if (field.Field == null) + return; + Assert.True(ReflectedManager.Process(field.Field)); + if (field.Field.IsStatic) + Assert.NotNull(field.Field.GetValue(null)); + } + + [Theory] + [MemberData(nameof(Invokers))] + public void TestBindingInvoker(ReflectionTestManager.FieldRef field) + { + if (field.Field == null) + return; + Assert.True(ReflectedManager.Process(field.Field)); + if (field.Field.IsStatic) + Assert.NotNull(field.Field.GetValue(null)); + } + #endregion + } +} diff --git a/Concealment.Tests/packages.config b/Concealment.Tests/packages.config new file mode 100644 index 0000000..30eb495 --- /dev/null +++ b/Concealment.Tests/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Concealment.sln b/Concealment.sln index 1cf89d7..19ab1dc 100644 --- a/Concealment.sln +++ b/Concealment.sln @@ -3,7 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26730.8 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment", "Concealment/Concealment.csproj", "{E5C0184B-7DC4-43D8-872E-2F71162748AA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment", "Concealment\Concealment.csproj", "{E5C0184B-7DC4-43D8-872E-2F71162748AA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Versioning", "Versioning", "{57BAE926-D9EB-40F2-AC36-007A1E2ED296}" + ProjectSection(SolutionItems) = preProject + Versioning\AssemblyVersion.cs = Versioning\AssemblyVersion.cs + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment.Tests", "Concealment.Tests\Concealment.Tests.csproj", "{53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +22,10 @@ Global {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|x64.Build.0 = Debug|x64 {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|x64.ActiveCfg = Release|x64 {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|x64.Build.0 = Release|x64 + {53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}.Debug|x64.ActiveCfg = Debug|x64 + {53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}.Debug|x64.Build.0 = Debug|x64 + {53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}.Release|x64.ActiveCfg = Release|x64 + {53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Concealment/Concealment.csproj b/Concealment/Concealment.csproj index b5bf5d4..0832507 100644 --- a/Concealment/Concealment.csproj +++ b/Concealment/Concealment.csproj @@ -141,6 +141,9 @@ + + Properties\AssemblyVersion.cs + diff --git a/Concealment/ConcealmentPlugin.cs b/Concealment/ConcealmentPlugin.cs index dc8d654..9d3a4bf 100644 --- a/Concealment/ConcealmentPlugin.cs +++ b/Concealment/ConcealmentPlugin.cs @@ -31,7 +31,7 @@ namespace Concealment { - [Plugin("Concealment", "1.2.1", "17f44521-b77a-4e85-810f-ee73311cf75d")] + [Plugin("Concealment", typeof(ConcealmentPlugin), "17f44521-b77a-4e85-810f-ee73311cf75d")] public sealed class ConcealmentPlugin : TorchPluginBase, IWpfPlugin { public Persistent Settings { get; private set; } diff --git a/Jenkinsfile b/Jenkinsfile index 84adddf..1be6957 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,11 +10,11 @@ def test_with_torch(branch) stage('Build + Torch ' + branch) { currentBuild.description = bat(returnStdout: true, script: '@powershell -File Versioning/version.ps1').trim() - bat "\"${tool 'MSBuild'}msbuild\" Essentials.sln /p:Configuration=Release /p:Platform=x64 /t:Clean" + bat "\"${tool 'MSBuild'}msbuild\" Concealment.sln /p:Configuration=Release /p:Platform=x64 /t:Clean" bat "\"${tool 'MSBuild'}msbuild\" Concealment.sln /p:Configuration=Release /p:Platform=x64" } - /* + stage('Test + Torch ' + branch) { bat 'IF NOT EXIST reports MKDIR reports' bat "\"packages/xunit.runner.console.2.2.0/tools/xunit.console.exe\" \"bin-test/x64/Release/Concealment.Tests.dll\" -parallel none -xml \"reports/Concealment.Tests.xml\"" @@ -32,7 +32,7 @@ def test_with_torch(branch) ]] ]) } - */ + return true } catch (e) { return false @@ -42,6 +42,7 @@ def test_with_torch(branch) node { stage('Checkout') { checkout scm + bat 'git pull --tags' } stage('Acquire SE') {