From 079c6fb0aee20a16fcf55b22645e8045e10594bb Mon Sep 17 00:00:00 2001 From: bchavez Date: Wed, 18 Jan 2017 15:11:48 -0800 Subject: [PATCH] Strong name Bogus. Fixes #52. --- .gitignore | 8 +-- HISTORY.md | 3 ++ Source/Bogus.snk.enc | 2 + Source/Bogus.snk.pub | Bin 0 -> 160 bytes Source/Bogus/AssemblyAttributes.cs | 3 -- Source/Bogus/Bogus.csproj | 1 - Source/Bogus/Properties/AssemblyInfo.cs | 19 +++---- Source/Bogus/project.json | 3 +- Source/Builder/Utils.fsx | 63 +++++++++++++++++++----- Source/Builder/build.fsx | 58 ++++++++++++++++++---- Source/paket.dependencies | 1 + appveyor.yml | 4 ++ 12 files changed, 124 insertions(+), 41 deletions(-) create mode 100644 Source/Bogus.snk.enc create mode 100644 Source/Bogus.snk.pub delete mode 100644 Source/Bogus/AssemblyAttributes.cs diff --git a/.gitignore b/.gitignore index 221ad54e..59341702 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,10 @@ paket.lock .paket/paket.exe __test +/__package +/__compile +/Source/Bogus.snk + Source/Builder/node_modules/** # User-specific files @@ -162,7 +166,5 @@ $RECYCLE.BIN/ # Mac crap .DS_Store -/Source/Coinbase.Tests/App.config /nuget.push.bat -/__package -/__compile + diff --git a/HISTORY.md b/HISTORY.md index 8cacd539..43e9ef06 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,6 @@ +## v9.0.1 +* New Feature: Bogus is now a signed assembly; PublicToken: fa1bb3f3f218129a + ## v8.0.4 * New Feature: Added `PickRandom(IEnumerable)` overload. Thanks joleharkes. diff --git a/Source/Bogus.snk.enc b/Source/Bogus.snk.enc new file mode 100644 index 00000000..5b44fac6 --- /dev/null +++ b/Source/Bogus.snk.enc @@ -0,0 +1,2 @@ +:Yy yPV 61h2Rw2(o]fF~x$䜞Pj+PXNߏ@qKx^(( \ No newline at end of file diff --git a/Source/Bogus.snk.pub b/Source/Bogus.snk.pub new file mode 100644 index 0000000000000000000000000000000000000000..95b3ec3fafe961411cc9803199f459359ba18be7 GIT binary patch literal 160 zcmV;R0AK$ABme*efB*oL000060ssI2Bme+XQ$aBR1ONa50098mfuO!t7W7ce1t|E8 z`EGl+g6+8Kng&sP#49um-DFCW8mkO^Ndmzs@AJ@_Ka4XFCMa!H!*3#AGxTtq=`}Ck z7RR=D7E)4-D|ZGz8K$ct?s+zkRWD%Lk5D)=;?}Ebug;T9$a8EY{W%)KhN=|ZTUlB9 ORBp0ZLF63!Vp^iyfIn6M literal 0 HcmV?d00001 diff --git a/Source/Bogus/AssemblyAttributes.cs b/Source/Bogus/AssemblyAttributes.cs deleted file mode 100644 index 5923e64e..00000000 --- a/Source/Bogus/AssemblyAttributes.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Bogus.Tests")] \ No newline at end of file diff --git a/Source/Bogus/Bogus.csproj b/Source/Bogus/Bogus.csproj index acd9090d..0d28c0c2 100644 --- a/Source/Bogus/Bogus.csproj +++ b/Source/Bogus/Bogus.csproj @@ -45,7 +45,6 @@ - diff --git a/Source/Bogus/Properties/AssemblyInfo.cs b/Source/Bogus/Properties/AssemblyInfo.cs index 38ce51da..76892144 100644 --- a/Source/Bogus/Properties/AssemblyInfo.cs +++ b/Source/Bogus/Properties/AssemblyInfo.cs @@ -1,25 +1,20 @@ // using System.Reflection; +using System.Runtime.CompilerServices; [assembly: AssemblyTitleAttribute("Bogus Fake Data Generator for .NET")] [assembly: AssemblyProductAttribute("Bogus")] [assembly: AssemblyCompanyAttribute("Brian Chavez")] -[assembly: AssemblyCopyrightAttribute("Brian Chavez © 2016")] +[assembly: AssemblyCopyrightAttribute("Brian Chavez © 2015")] [assembly: AssemblyVersionAttribute("0.0.0")] [assembly: AssemblyFileVersionAttribute("0.0.0")] -[assembly: AssemblyInformationalVersionAttribute("0.0.0-localbuild built on 24/11/2016 22:44:53")] +[assembly: AssemblyInformationalVersionAttribute("0.0.0-localbuild built on 1/1/2015 12:00:00 AM")] [assembly: AssemblyTrademarkAttribute("Apache License v2.0")] -[assembly: AssemblyDescriptionAttribute("http://www.github.com/bchavez/Bogus")] +[assembly: AssemblyDescriptionAttribute("https://github.com/bchavez/Bogus")] +[assembly: InternalsVisibleToAttribute("Bogus.Tests")] namespace System { internal static class AssemblyVersionInformation { - internal const System.String AssemblyTitle = "Bogus Fake Data Generator for .NET"; - internal const System.String AssemblyProduct = "Bogus"; - internal const System.String AssemblyCompany = "Brian Chavez"; - internal const System.String AssemblyCopyright = "Brian Chavez © 2016"; - internal const System.String AssemblyVersion = "0.0.0"; - internal const System.String AssemblyFileVersion = "0.0.0"; - internal const System.String AssemblyInformationalVersion = "0.0.0-localbuild built on 24/11/2016 22:44:53"; - internal const System.String AssemblyTrademark = "Apache License v2.0"; - internal const System.String AssemblyDescription = "http://www.github.com/bchavez/Bogus"; + internal const string Version = "0.0.0"; + internal const string InformationalVersion = "0.0.0-localbuild built on 1/1/2015 12:00:00 AM"; } } diff --git a/Source/Bogus/project.json b/Source/Bogus/project.json index 2836ab7d..9804f732 100644 --- a/Source/Bogus/project.json +++ b/Source/Bogus/project.json @@ -22,7 +22,7 @@ "owners": [ "Brian Chavez" ], - "releaseNotes": "## v8.0.1-beta-1\r\n* Allow `Faker.RuleFor` rules to be overridden. Last set rule wins.\r\n\r\n## v7.1.7\r\n* `Faker.AssertConfigurationIsValid` to help in unit testing scenarios.\r\n* Add `Internet.Ipv6` method to generate IPv6 addresses.\r\n\r\n## v7.1.6\r\n* Added `f => f.Commerce` on `Faker`.\r\n\r\n## v7.1.5\r\n* Added `cz`/Czech locale\r\n* Updated `en`, `nl`, `pl`, `sk`, `sv` locales.\r\n* Realistic Dutch city naming\r\n* `Randomizer.AlphaNumeric` added.\r\n* `Randomizer.Double` now accepts `(min,max)` arguments\r\n* Added convenience `Randomizer` for random `Decimal`, `Float`, `Byte`, `Bytes`, `SByte`, `Int`, `UInt`, `ULong`, `Long`, `Short`, `UShort`, `Char` and `Chars`.\r\n\r\n## v7.1.4\r\n* Newtonsoft Json 9.0.1 dependency support.\r\n\r\n\r\nFull History Here: https://github.com/bchavez/Bogus/blob/master/HISTORY.md", + "releaseNotes": "", "iconUrl": "https://raw.githubusercontent.com/bchavez/Bogus/master/Docs/logo.png", "projectUrl": "https://github.com/bchavez/Bogus", "licenseUrl": "https://raw.githubusercontent.com/bchavez/Bogus/master/LICENSE", @@ -33,6 +33,7 @@ } }, "buildOptions": { + "keyFile": "", "xmlDoc": true, "configurations": { "Debug": { diff --git a/Source/Builder/Utils.fsx b/Source/Builder/Utils.fsx index 7c3f14a7..70ec9249 100644 --- a/Source/Builder/Utils.fsx +++ b/Source/Builder/Utils.fsx @@ -13,6 +13,7 @@ open Fake open AssemblyInfoFile +open Fake.AppVeyor module BuildContext = @@ -37,7 +38,8 @@ module BuildContext = let Version = WithoutPreReleaseName FullVersion - + let IsTaggedBuild = + AppVeyorEnvironment.RepoTag open System @@ -82,6 +84,9 @@ module Setup = type Projects(projectName : string, folders : Folders) = let solutionFile = folders.Source @@ sprintf "%s.sln" projectName let globalJson = folders.Source @@ "global.json" + let snkFile = folders.Source @@ sprintf "%s.snk" projectName + let snkFilePublic = folders.Source @@ sprintf "%s.snk.pub" projectName + let dnvmVersion = let json = JsonValue.Parse(System.IO.File.ReadAllText(globalJson)) json?sdk?version.AsString() @@ -89,9 +94,8 @@ module Setup = member this.SolutionFile = solutionFile member this.GlobalJson = globalJson member this.DnvmVersion = dnvmVersion - - - + member this.SnkFile = snkFile + member this.SnkFilePublic = snkFilePublic open Setup @@ -139,12 +143,31 @@ type NugetProject(name : string, assemblyTitle : string, folders : Folders) = member this.Title = assemblyTitle +let ReadFileAsHexString file = + let bytes = ReadFileAsBytes file + let sb = new System.Text.StringBuilder() + let toHex (b : byte)= + b.ToString("x2") + + let acc = bytes + |> Array.fold (fun (acc:System.Text.StringBuilder) b -> + acc.Append(toHex b) + ) sb + acc.ToString() +type BuildInfoParams = { DateTime:System.DateTime; ExtraAttrs:list } -let MakeBuildInfo (project: NugetProject) (folders : Folders) = +let MakeBuildInfo (project: NugetProject) (folders : Folders) setParams = + + let bip : BuildInfoParams = { + DateTime = System.DateTime.UtcNow + ExtraAttrs = [] + } |> setParams + let path = folders.Source @@ project.Name @@ "/Properties/AssemblyInfo.cs" - let infoVersion = sprintf "%s built on %s" BuildContext.FullVersion (System.DateTime.UtcNow.ToString()) - let copyright = sprintf "Brian Chavez © %i" (System.DateTime.UtcNow.Year) + let infoVersion = sprintf "%s built on %s" BuildContext.FullVersion (bip.DateTime.ToString()) + let copyright = sprintf "Brian Chavez © %i" (bip.DateTime.Year) + let attrs = [ Attribute.Title project.Title @@ -155,9 +178,9 @@ let MakeBuildInfo (project: NugetProject) (folders : Folders) = Attribute.FileVersion BuildContext.Version Attribute.InformationalVersion infoVersion Attribute.Trademark "Apache License v2.0" - Attribute.Description "http://www.github.com/bchavez/Bogus" ] - CreateCSharpAssemblyInfo path attrs + + CreateCSharpAssemblyInfo path (attrs @ bip.ExtraAttrs) open System.Reflection @@ -236,21 +259,39 @@ module Helpers = open FSharp.Data open FSharp.Data.JsonExtensions - let shellExec cmdPath args target = + let shellExec cmdPath args workingDir = let result = ExecProcess ( fun info -> info.FileName <- cmdPath - info.WorkingDirectory <- target + info.WorkingDirectory <- workingDir info.Arguments <- args ) System.TimeSpan.MaxValue if result <> 0 then failwith (sprintf "'%s' failed" cmdPath + " " + args) + let shellExecSecret cmdPath args workingDir = + let ok = directExec ( + fun info -> + info.FileName <- cmdPath + info.WorkingDirectory <- workingDir + info.Arguments <- args + ) + if not ok then failwith (sprintf "'%s' failed" cmdPath) + let findOnPath name = let executable = tryFindFileOnPath name match executable with | Some exec -> exec | None -> failwith (sprintf "'%s' can't find" name) + let encryptFile file secret = + let secureFile = findToolInSubPath "secure-file.exe" "." + let args = sprintf "-encrypt %s -secret %s" file secret + shellExecSecret secureFile args "." + + let decryptFile file secret = + let secureFile = findToolInSubPath "secure-file.exe" "." + let args = sprintf "-decrypt %s.enc -secret %s" file secret + shellExecSecret secureFile args "." let dotnet args workingDir = let executable = findOnPath "dotnet.exe" diff --git a/Source/Builder/build.fsx b/Source/Builder/build.fsx index 88b3aca0..b9abf87c 100644 --- a/Source/Builder/build.fsx +++ b/Source/Builder/build.fsx @@ -37,18 +37,19 @@ Target "msb" (fun _ -> let tag = "msb_build"; + let buildProps = [ + "AssemblyOriginatorKeyFile", Projects.SnkFile + "SignAssembly", BuildContext.IsTaggedBuild.ToString() + ] + !! BogusProject.ProjectFile - |> MSBuildRelease (BogusProject.OutputDirectory @@ tag) "Build" + |> MSBuildReleaseExt (BogusProject.OutputDirectory @@ tag) buildProps "Build" |> Log "AppBuild-Output: " !! TestProject.ProjectFile - |> MSBuildDebug "" "Build" + |> MSBuild "" "Build" (("Configuration", "Debug")::buildProps) |> Log "AppBuild-Output: " - -// !! GridTestProject.ProjectFile -// |> MSBuildDebug "" "Build" -// |> Log "AppBuild-Output: " ) @@ -89,7 +90,6 @@ Target "push" (fun _ -> trace "NuGet Push Task" failwith "Only CI server should publish on NuGet" - ) @@ -100,12 +100,28 @@ Target "zip" (fun _ -> !!(BogusProject.OutputDirectory @@ "**") |> Zip Folders.CompileOutput (Folders.Package @@ BogusProject.Zip) ) +open AssemblyInfoFile + +let MakeAttributes (includeSnk:bool) = + let attrs = [ + Attribute.Description GitHubUrl + ] + if includeSnk then + let pubKey = ReadFileAsHexString Projects.SnkFilePublic + let visibleTo = sprintf "%s, PublicKey=%s" TestProject.Name pubKey + attrs @ [ Attribute.InternalsVisibleTo(visibleTo) ] + else + attrs @ [ Attribute.InternalsVisibleTo(TestProject.Name) ] + Target "BuildInfo" (fun _ -> trace "Writing Assembly Build Info" - MakeBuildInfo BogusProject Folders + MakeBuildInfo BogusProject Folders (fun bip -> + { bip with + ExtraAttrs = MakeAttributes(BuildContext.IsTaggedBuild) } ) + JsonPoke "version" BuildContext.FullVersion BogusProject.ProjectJson let releaseNotes = History.NugetText Files.History GitHubUrl @@ -119,6 +135,13 @@ Target "Clean" (fun _ -> JsonPoke "version" "0.0.0-localbuild" BogusProject.ProjectJson JsonPoke "packOptions.releaseNotes" "" BogusProject.ProjectJson + JsonPoke "buildOptions.keyFile" "" BogusProject.ProjectJson + + MakeBuildInfo BogusProject Folders (fun bip -> + {bip with + DateTime = System.DateTime.Parse("1/1/2015") + ExtraAttrs = MakeAttributes(false) } ) + ) let RunTests() = @@ -132,6 +155,7 @@ let RunTests() = OutputFile = Files.TestResultFile ErrorLevel = TestRunnerErrorLevel.Error }) + open Fake.AppVeyor Target "ci" (fun _ -> @@ -139,31 +163,44 @@ Target "ci" (fun _ -> ) Target "test" (fun _ -> - trace "CI TEST" + trace "TEST" RunTests() ) Target "citest" (fun _ -> + trace "CI TEST" RunTests() UploadTestResultsXml TestResultsType.NUnit Folders.Test ) +Target "setup-snk"(fun _ -> + trace "Decrypting Strong Name Key (SNK) file." + let decryptSecret = environVarOrFail "SNKFILE_SECRET" + decryptFile Projects.SnkFile decryptSecret + + JsonPoke "buildOptions.keyFile" Projects.SnkFile BogusProject.ProjectJson +) + "Clean" ==> "restore" ==> "BuildInfo" + -//build systems +//build systems, order matters "BuildInfo" + =?> ("setup-snk", BuildContext.IsTaggedBuild) ==> "dnx" ==> "zip" "BuildInfo" + =?> ("setup-snk", BuildContext.IsTaggedBuild) ==> "msb" ==> "zip" "BuildInfo" + =?> ("setup-snk", BuildContext.IsTaggedBuild) ==> "mono" ==> "zip" @@ -180,6 +217,7 @@ Target "citest" (fun _ -> "zip" ==> "ci" + //test task depends on msbuild "msb" ==> "test" diff --git a/Source/paket.dependencies b/Source/paket.dependencies index b68b420b..0ad55b1c 100644 --- a/Source/paket.dependencies +++ b/Source/paket.dependencies @@ -13,3 +13,4 @@ group build nuget NuGet.CommandLine == 2.8.6 nuget NUnit.Runners == 2.6.4 nuget Newtonsoft.Json + nuget secure-file diff --git a/appveyor.yml b/appveyor.yml index 7eff6434..59aab057 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,9 @@ version: '{build}' +environment: + SNKFILE_SECRET: #SecretDatabase.kdbx / OpenSource / Bogus.snk.enc + secure: Bce2VwNFEBM1oWspgNlpTXSH290GZmc5DCuxjnAX72nBWNbR0S2tq/odIdfv2+t3bA9xzFHEwqvjGVEWgg5ZdfWUYj+PSBr+con0PiUGng0= + skip_commits: message: /(//skip\W*ci)|(read\W*me)/