Skip to content

Commit 11a3db7

Browse files
committed
Generate a random key to be able to build if one does not exist build script's release routing will warn if assembly tokens do not match the known Nest/Elasticsearch-Net public key token though.
1 parent 757067b commit 11a3db7

File tree

9 files changed

+79
-45
lines changed

9 files changed

+79
-45
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ _ReSharper*/
3434
_NCrunch*/
3535
[Tt]est[Rr]esult*
3636

37+
keypair.snk
38+
private.snk
39+
*.snk
3740
build/keys/private.snk
3841
build/keys/keypair.snk
3942
build/*

build/build.fsx

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ Target "Clean" (fun _ ->
1818
)
1919

2020
Target "BuildApp" (fun _ ->
21+
let msbuildProperties = [
22+
("Configuration","Release");
23+
("PreBuildEvent","ECHO");
24+
]
25+
2126
//Compile each csproj and output it seperately in build/output/PROJECTNAME
2227
!! "src/**/*.csproj"
2328
|> Seq.map(fun f -> (f, buildDir + directoryInfo(f).Name.Replace(".csproj", "")))
24-
|> Seq.iter(fun (f,d) -> MSBuildRelease d "Build" (seq { yield f }) |> ignore)
29+
|> Seq.iter(fun (f,d) -> MSBuild d "Build" msbuildProperties (seq { yield f }) |> ignore)
2530

2631
//Scan for xml docs and patch them to replace <inheritdoc /> with the documentation
2732
//from their interfaces
@@ -38,38 +43,50 @@ Target "Test" (fun _ ->
3843
)
3944

4045
let keyFile = "build/keys/keypair.snk"
41-
let validateSignedAssembly = fun name ->
46+
47+
let createKeys = fun _ ->
4248
let sn = "build/tools/sn/sn.exe"
4349
ExecProcess(fun p ->
4450
p.FileName <- sn
45-
p.Arguments <- sprintf @"-v build\output\%s.dll" name
46-
) (TimeSpan.FromMinutes 5.0)
47-
48-
let signAssembly = fun name ->
49-
let ilmerge = "build/tools/ilmerge/ILMerge.exe"
50-
let platform = @"/targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
51-
let i = sprintf "build\\output\\%s\\%s" name name
52-
let o = sprintf "build\\output\\%s" name
51+
p.Arguments <- sprintf @"-k %s" keyFile
52+
) (TimeSpan.FromMinutes 5.0) |> ignore
53+
54+
ExecProcess(fun p ->
55+
p.FileName <- sn
56+
p.Arguments <- sprintf @"-p %s %s" keyFile "build/keys/public.snk"
57+
) (TimeSpan.FromMinutes 5.0) |> ignore
58+
59+
Target "CreateKeysIfAbsent" (fun _ ->
60+
if not (fileExists keyFile) then createKeys()
61+
)
62+
63+
let validateSignedAssembly = fun name ->
64+
let sn = "build/tools/sn/sn.exe"
65+
let out = (ExecProcessAndReturnMessages(fun p ->
66+
p.FileName <- sn
67+
p.Arguments <- sprintf @"-v build\output\%s\%s.dll" name name
68+
) (TimeSpan.FromMinutes 5.0))
69+
70+
let valid = (out.ExitCode, out.Messages.FindIndex(fun s -> s.Contains("is valid")))
71+
72+
match valid with
73+
| (0, i) when i >= 0 -> trace (sprintf "%s was signed correctly" name)
74+
| (_, _) -> failwithf "{0} was not validly signed"
5375

54-
let dll = i + ".dll"
55-
let outdll = o + ".dll"
56-
let pdb = o + ".pdb"
57-
58-
let signExitCode = (
59-
ExecProcess(fun p ->
60-
p.FileName <- ilmerge
61-
p.Arguments <- (sprintf "%s /keyfile:%s /out:%s %s"
62-
dll keyFile outdll platform)
63-
) (TimeSpan.FromMinutes 5.0)
64-
)
65-
66-
let validateExitCode = validateSignedAssembly name
67-
match (signExitCode, validateExitCode) with
68-
| (0,0) ->
69-
MoveFile (DirectoryName dll) outdll
70-
MoveFile (DirectoryName dll) pdb
71-
| _ ->
72-
failwithf "Failed to sign {0}" name
76+
let out = (ExecProcessAndReturnMessages(fun p ->
77+
p.FileName <- sn
78+
p.Arguments <- sprintf @"-T build\output\%s\%s.dll" name name
79+
) (TimeSpan.FromMinutes 5.0))
80+
81+
let tokenMessage = (out.Messages.Find(fun s -> s.Contains("Public key token is")));
82+
let token = (tokenMessage.Replace("Public key token is", "")).Trim();
83+
84+
let valid = (out.ExitCode, token)
85+
let oficialToken = "96c599bbe3e70f5d"
86+
match valid with
87+
| (0, t) when t = oficialToken ->
88+
trace (sprintf "%s was signed with official key token %s" name t)
89+
| (_, t) -> traceFAKE "%s was not signed with the official token: %s but %s" name oficialToken t
7390

7491
let nugetPack = fun name ->
7592

@@ -91,11 +108,12 @@ let buildDocs = fun action ->
91108
let node = @"build\tools\Node.js\node.exe"
92109
let wintersmith = @"..\build\tools\node_modules\wintersmith\bin\wintersmith"
93110
ExecProcess (fun p ->
94-
p.WorkingDirectory <- "new_docs"
95-
p.FileName <- node
96-
p.Arguments <- sprintf "\"%s\" %s" wintersmith action
97-
) (TimeSpan.FromMinutes (if action = "preview" then 300.0 else 5.0))
98-
111+
p.WorkingDirectory <- "new_docs"
112+
p.FileName <- node
113+
p.Arguments <- sprintf "\"%s\" %s" wintersmith action
114+
)
115+
(TimeSpan.FromMinutes (if action = "preview" then 300.0 else 5.0))
116+
99117
Target "Version" (fun _ ->
100118
let v = (getBuildParamOrDefault "version" "0.1.0")
101119
let version = SemVerHelper.parse v
@@ -109,14 +127,14 @@ Target "Release" (fun _ ->
109127
if not <| fileExists keyFile
110128
then failwithf "{0} does not exist to sign the assemblies" keyFile
111129

112-
//signAssembly("Elasticsearch.Net")
113-
//signAssembly("Elasticsearch.Net.Connection.Thrift")
114-
//signAssembly("Nest")
115-
116130
nugetPack("Elasticsearch.Net")
117131
nugetPack("Elasticsearch.Net.Connection.Thrift")
118132
nugetPack("Nest")
119133

134+
validateSignedAssembly("Elasticsearch.Net")
135+
validateSignedAssembly("Elasticsearch.Net.Connection.Thrift")
136+
validateSignedAssembly("Nest")
137+
120138
)
121139

122140
Target "Docs" (fun _ -> buildDocs "build" |> ignore)
@@ -127,6 +145,7 @@ Target "DocsPreview" (fun _ ->
127145

128146
// Dependencies
129147
"Clean"
148+
==> "CreateKeysIfAbsent"
130149
==> "BuildApp"
131150
==> "Test"
132151
==> "Build"
@@ -135,6 +154,7 @@ Target "DocsPreview" (fun _ ->
135154
==> "Release"
136155

137156
"DocsPreview"
157+
"CreateKeysIfAbsent"
138158
"Version"
139159
// start build
140160
RunTargetOrDefault "Build"

build/keys/public.snk

0 Bytes
Binary file not shown.

src/Connections/Elasticsearch.Net.Connection.Thrift/Elasticsearch.Net.Connection.Thrift.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<SignAssembly>true</SignAssembly>
6969
</PropertyGroup>
7070
<PropertyGroup>
71-
<AssemblyOriginatorKeyFile>keypair.snk</AssemblyOriginatorKeyFile>
71+
<AssemblyOriginatorKeyFile>..\..\..\build\keys\keypair.snk</AssemblyOriginatorKeyFile>
7272
</PropertyGroup>
7373
<ItemGroup>
7474
<Reference Include="NetReflector, Version=1.1.2009.1214, Culture=neutral, PublicKeyToken=2f4dd8b32acbcd8e, processorArchitecture=MSIL">
@@ -140,6 +140,10 @@
140140
</ItemGroup>
141141
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
142142
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
143+
<PropertyGroup>
144+
<PreBuildEvent>IF NOT EXIST "$(SolutionDir)..\build\keys\keypair.snk" (CD "$(SolutionDir).." &amp;&amp; "build.bat" CreateKeysIfAbsent &amp;&amp; CD %25~dp0)
145+
</PreBuildEvent>
146+
</PropertyGroup>
143147
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
144148
Other similar extension points exist, see Microsoft.Common.targets.
145149
<Target Name="BeforeBuild">

src/Elasticsearch.Net/Elasticsearch.Net.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<SignAssembly>true</SignAssembly>
3636
</PropertyGroup>
3737
<PropertyGroup>
38-
<AssemblyOriginatorKeyFile>keypair.snk</AssemblyOriginatorKeyFile>
38+
<AssemblyOriginatorKeyFile>..\..\build\keys\keypair.snk</AssemblyOriginatorKeyFile>
3939
</PropertyGroup>
4040
<ItemGroup>
4141
<Reference Include="System" />
@@ -110,6 +110,10 @@
110110
<None Include="packages.config" />
111111
</ItemGroup>
112112
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
113+
<PropertyGroup>
114+
<PreBuildEvent>IF NOT EXIST "$(SolutionDir)..\build\keys\keypair.snk" (CD "$(SolutionDir).." &amp;&amp; "build.bat" CreateKeysIfAbsent &amp;&amp; CD %25~dp0)
115+
</PreBuildEvent>
116+
</PropertyGroup>
113117
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
114118
Other similar extension points exist, see Microsoft.Common.targets.
115119
<Target Name="BeforeBuild">

src/Elasticsearch.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Build", "_Build", "{432D55
2828
..\build\build.fsx = ..\build\build.fsx
2929
..\build\Elasticsearch.Net.Connection.Thrift.nuspec = ..\build\Elasticsearch.Net.Connection.Thrift.nuspec
3030
..\build\Elasticsearch.Net.nuspec = ..\build\Elasticsearch.Net.nuspec
31+
..\build\InheritDoc.fsx = ..\build\InheritDoc.fsx
3132
..\build\NEST.nuspec = ..\build\NEST.nuspec
3233
..\build\NESTBuild.proj = ..\build\NESTBuild.proj
33-
patch_inheritdoc.fsx = patch_inheritdoc.fsx
3434
EndProjectSection
3535
EndProject
3636
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nest.Tests.Unit", "Tests\Nest.Tests.Unit\Nest.Tests.Unit.csproj", "{97408393-78AC-45DF-BE6E-4C219A2E456D}"

src/Nest/ElasticClient-CreateIndex.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public IIndicesOperationResponse CreateIndex(string index,
2020
descriptor,
2121
(p, d) => this.RawDispatch.IndicesCreateDispatch<IndicesOperationResponse>(p, d._IndexSettings)
2222
);
23-
}
23+
}
2424

2525
/// <inheritdoc />
2626
public Task<IIndicesOperationResponse> CreateIndexAsync(string index,

src/Nest/IElasticClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Task<IValidateResponse> ValidateAsync<T>(Func<ValidateQueryDescriptor<T>, Valida
171171
/// A closed index can be opened which will then go through the normal recovery process.
172172
/// <para> </para>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html
173173
/// </summary>
174-
/// <param name="closeSelector">A descriptor thata describes the close index operation</param>
174+
/// <param name="closeIndexSelector">A descriptor thata describes the close index operation</param>
175175
Task<IIndicesOperationResponse> CloseIndexAsync(Func<CloseIndexDescriptor, CloseIndexDescriptor> closeIndexSelector);
176176

177177
/// <summary>

src/Nest/Nest.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<SignAssembly>true</SignAssembly>
7171
</PropertyGroup>
7272
<PropertyGroup>
73-
<AssemblyOriginatorKeyFile>keypair.snk</AssemblyOriginatorKeyFile>
73+
<AssemblyOriginatorKeyFile>..\..\build\keys\keypair.snk</AssemblyOriginatorKeyFile>
7474
</PropertyGroup>
7575
<ItemGroup>
7676
<Reference Include="Microsoft.CSharp" />
@@ -750,12 +750,15 @@
750750
</ProjectReference>
751751
</ItemGroup>
752752
<ItemGroup>
753-
<None Include="keypair.snk" />
754753
<None Include="packages.config" />
755754
</ItemGroup>
756755
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
757756
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
758757
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
758+
<PropertyGroup>
759+
<PreBuildEvent>IF NOT EXIST "$(SolutionDir)..\build\keys\keypair.snk" (CD "$(SolutionDir).." &amp;&amp; "build.bat" CreateKeysIfAbsent &amp;&amp; CD %25~dp0)
760+
</PreBuildEvent>
761+
</PropertyGroup>
759762
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
760763
Other similar extension points exist, see Microsoft.Common.targets.
761764
<Target Name="BeforeBuild">

0 commit comments

Comments
 (0)