Skip to content

Commit 7085a90

Browse files
authored
Introduce .ci/make.sh (#4838)
1 parent bb4846e commit 7085a90

11 files changed

+103
-84
lines changed

.ci/DockerFile

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ FROM mcr.microsoft.com/dotnet/core/sdk:${DOTNET_VERSION} AS elasticsearch-net-bu
33

44
WORKDIR /sln
55

6+
67
COPY ./*.sln ./nuget.config ./*.Build.props ./*.Build.targets ./
78

9+
COPY ./dotnet-tools.json ./
10+
RUN dotnet tool restore
11+
812
# todo standardize on Build.props as Directory.Build.props needs that form
913
COPY ./src/*.Build.props ./src/
1014
COPY ./tests/*.Build.props ./tests/
@@ -21,13 +25,12 @@ RUN for file in $(find . -name "*.?sproj"); do mkdir -p $(dirname $file)/$(basen
2125
COPY build/scripts/scripts.fsproj ./build/scripts/
2226
COPY .ci/Jenkins.csproj ./.ci/
2327

24-
RUN ls -al
25-
RUN ls -al tests
26-
RUN ls -al src
27-
RUN ls -al src/Elasticsearch.Net
28-
28+
# Install app dependencies
2929
RUN dotnet restore
3030

31-
# Install app dependencies
31+
# copy relevant files (see .dockerignore)
32+
COPY . .
33+
34+
# making sure enough git info is available inside the container
35+
RUN git rev-parse HEAD .
3236

33-
COPY . .

.ci/Jenkins.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
<TargetFramework>netcoreapp2.2</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<Content Include="..\.dockerignore">
9+
<Link>.dockerignore</Link>
10+
</Content>
11+
</ItemGroup>
12+
713
</Project>

.ci/make.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
# parameters are available to this script
3+
4+
5+
# common build entry script for all elasticsearch clients
6+
7+
# ./.ci/make.sh bump VERSION
8+
# ./.ci/make.sh release VERSION
9+
10+
script_path=$(dirname "$(realpath -s "$0")")
11+
repo=$(realpath "$script_path/../")
12+
13+
# shellcheck disable=SC1090
14+
cmd=$1
15+
VERSION=$2
16+
STACK_VERSION=$VERSION
17+
source "$script_path/functions/imports.sh"
18+
set -euo pipefail
19+
20+
output_folder=".ci/output"
21+
OUTPUT_DIR="$repo/${output_folder}"
22+
23+
DOTNET_VERSION=${DOTNET_VERSION-3.0.100}
24+
25+
echo -e "\033[34;1mINFO:\033[0m VERSION ${STACK_VERSION}\033[0m"
26+
echo -e "\033[34;1mINFO:\033[0m OUTPUT_DIR ${OUTPUT_DIR}\033[0m"
27+
echo -e "\033[34;1mINFO:\033[0m DOTNET_VERSION ${DOTNET_VERSION}\033[0m"
28+
29+
echo -e "\033[1m>>>>> Build [elastic/elasticsearch-net container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
30+
31+
docker build --file .ci/DockerFile --tag elastic/elasticsearch-net .
32+
33+
echo -e "\033[1m>>>>> Run [elastic/elasticsearch-net container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
34+
35+
mkdir -p "$OUTPUT_DIR"
36+
37+
docker run \
38+
--network=${network_name} \
39+
--env "DOTNET_VERSION" \
40+
--name test-runner \
41+
--volume "${OUTPUT_DIR}:/sln/${output_folder}" \
42+
--rm \
43+
elastic/elasticsearch-net \
44+
./build.sh release "$VERSION" "$output_folder" "skiptests"

.dockerignore

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
scripts/output
2-
.git
3-
4-
5-
.git
62

73
**/Obj/
84
**/obj/
@@ -35,8 +31,6 @@ PublishProfiles/
3531
*.vspx
3632
/.symbols
3733
nuget.exe
38-
*net45.csproj
39-
*k10.csproj
4034
App_Data/
4135
bower_components
4236
node_modules
@@ -48,3 +42,5 @@ node_modules
4842
launchSettings.json
4943
bin
5044
obj
45+
46+
.git/objects/*

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ build/tools/*
5757
!build/*.targets
5858
!build/scripts
5959

60+
.ci/output
61+
6062

6163
/dep/Newtonsoft.Json.4.0.2
6264
!docs/build

build/scripts/Commandline.fs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Scripts
77
open System
88
open System.Runtime.InteropServices
99
open Fake.Core
10+
open Fake.IO
1011

1112
//this is ugly but a direct port of what used to be duplicated in our DOS and bash scripts
1213
module Commandline =
@@ -80,7 +81,7 @@ Execution hints can be provided anywhere on the command line
8081

8182
type MultiTarget = All | One
8283

83-
type VersionArguments = { Version: string; }
84+
type VersionArguments = { Version: string; OutputLocation: string option }
8485
type TestArguments = { TrxExport: bool; CodeCoverage: bool; TestFilter: string option; }
8586
type IntegrationArguments = { TrxExport: bool; TestFilter: string option; ClusterFilter: string option; ElasticsearchVersions: string list; }
8687

@@ -197,7 +198,10 @@ Execution hints can be provided anywhere on the command line
197198
| ["profile"] -> parsed
198199
| "rest-spec-tests" :: tail -> { parsed with RemainingArguments = tail }
199200

200-
| ["release"; version] -> { parsed with CommandArguments = SetVersion { Version = version }; }
201+
| ["release"; version] -> { parsed with CommandArguments = SetVersion { Version = version; OutputLocation = None }; }
202+
| ["release"; version; path] ->
203+
if (not <| System.IO.Directory.Exists path) then failwithf "'%s' is not an existing directory" (Path.getFullName path)
204+
{ parsed with CommandArguments = SetVersion { Version = version; OutputLocation = Some path }; }
201205
| ["canary"] ->
202206
{
203207
parsed with CommandArguments = Test {

build/scripts/ReposTooling.fs

+5
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ module ReposTooling =
5757
let Rewriter args =
5858
restoreOnce.Force()
5959
Tooling.DotNet.ExecIn "." (List.append [assemblyRewriter] (List.ofSeq args)) |> ignore
60+
61+
let private packageValidator = "nupkg-validator"
62+
let PackageValidator args =
63+
restoreOnce.Force()
64+
Tooling.DotNet.ExecIn "." (List.append [packageValidator] (List.ofSeq args)) |> ignore
6065

build/scripts/Targets.fs

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ open System.IO
1010
open Build
1111
open Commandline
1212
open Bullseye
13+
open Octokit
1314
open ProcNet
1415
open Fake.Core
1516

@@ -90,7 +91,12 @@ module Main =
9091

9192
//RELEASE
9293
command "release" releaseChain <| fun _ ->
93-
printfn "Finished Release Build %O" artifactsVersion
94+
let outputPath = match parsed.CommandArguments with | SetVersion c -> c.OutputLocation | _ -> None
95+
match outputPath with
96+
| None -> printfn "Finished Release Build %O, artifacts available at: %s" artifactsVersion Paths.BuildOutput
97+
| Some path ->
98+
Fake.IO.Shell.cp_r Paths.BuildOutput path
99+
printfn "Finished Release Build %O, output copied to: %s" artifactsVersion path
94100

95101
conditional "test-nuget-package" (not parsed.SkipTests && Environment.isWindows) <| fun _ ->
96102
// run release unit tests puts packages in the system cache prevent this from happening locally

build/scripts/Versioning.fs

+14-68
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ open Commandline
1212
open Fake.Core
1313
open Fake.IO
1414
open Fake.IO.Globbing.Operators
15+
open Fake.Tools.Git
1516
open Newtonsoft.Json
1617

1718
module Versioning =
@@ -112,60 +113,7 @@ module Versioning =
112113
| NoChange n -> n
113114
| Update (newVersion, _) -> newVersion
114115

115-
let private sn () =
116-
match notWindows with
117-
| true -> "sn"
118-
| false ->
119-
let programFiles = Environment.environVar "PROGRAMFILES(X86)"
120-
if not (Directory.Exists programFiles) then failwith "Can not locate 64 bit program files"
121-
let windowsSdks = ["v10.0A"; "v8.1A"; "v8.1"; "v8.0"; "v7.0A";]
122-
let dotNetVersion = ["4.7.2"; "4.7.1"; "4.7"; "4.6.2"; "4.6.1"; "4.0"]
123-
let combinations = List.allPairs windowsSdks dotNetVersion
124-
let winFolder w = Path.Combine(programFiles, "Microsoft SDKs", "Windows", w, "bin")
125-
let sdkFolder w d =
126-
let folder = sprintf "NETFX %s Tools" d
127-
Path.Combine(winFolder w, folder)
128-
let snExe w d = Path.Combine(sdkFolder w d, "sn.exe")
129-
let sn = combinations |> List.map (fun (w, d) -> snExe w d) |> List.tryFind File.exists
130-
match sn with
131-
| Some sn -> sn
132-
| None -> failwithf "Could not locate sn.exe"
133-
134116
let private officialToken = "96c599bbe3e70f5d"
135-
let private keyFile = Paths.Keys "keypair.snk"
136-
137-
let private validate dll name =
138-
let sn = sn ()
139-
let out = Tooling.readQuiet sn ["-v"; dll;]
140-
141-
// Mono StrongName - version 5.18.1.0
142-
// returns `is strongnamed`
143-
let valid = (out.ExitCode, out.Output |> Seq.tryFindIndex(fun s -> s.Line.Contains("is valid") || s.Line.Contains("is strongnamed")))
144-
match valid with
145-
| (0, Some i) when i >= 0 -> printfn "%s is strongnamed" name
146-
| (_, _) -> failwithf "%s is NOT strongnamed" dll
147-
148-
let out = Tooling.readQuiet sn ["-T"; dll;]
149-
150-
let tokenMessage = (out.Output |> Seq.tryFind(fun s -> s.Line.Contains("Public key token", StringComparison.OrdinalIgnoreCase)));
151-
152-
// Mono StrongName - version 5.18.1.0
153-
// returns `Key Token:`
154-
let token =
155-
match tokenMessage with
156-
| Some s -> Some <| (s.Line.Replace("Public Key Token:", "").Replace("Public key token is", "")).Trim()
157-
| None -> None
158-
159-
let valid = (out.ExitCode, token)
160-
match valid with
161-
| (0, Some t) when t = officialToken -> printfn "%s was signed with official key token %s" name t
162-
| (_, Some t) -> printfn "%s was not signed with the official token: %s but %s" name officialToken t
163-
| (_, None) -> printfn "%s was not signed at all" name
164-
165-
let private validateDllStrongName dll name =
166-
match File.Exists dll with
167-
| true -> validate dll name
168-
| _ -> failwithf "Attempted to verify signature of %s but it was not found!" dll
169117

170118
let BuiltArtifacts (version: AnchoredVersion) =
171119
let packages =
@@ -179,14 +127,25 @@ module Versioning =
179127
packages
180128

181129
let ValidateArtifacts version =
182-
let fileVersion = version.AssemblyFile
183130
let tmp = "build/output/_packages/tmp"
184131

185132
let packages = BuiltArtifacts version
186133
printf "%O" packages
187134

188135
packages
136+
// do not validate versioned packages for now
137+
|> Seq.filter(fun f -> not <| f.NugetId.EndsWith(sprintf ".v%i" version.Assembly.Major))
189138
|> Seq.iter(fun p ->
139+
let v = sprintf "%O+%s" version.Full (Information.getCurrentSHA1("."))
140+
// loading dlls is locked down on APPVEYOR so we can not assert release mode
141+
let ciArgs =
142+
let appVeyor = Environment.hasEnvironVar "APPVEYOR"
143+
let azDevops = Environment.hasEnvironVar "TF_BUILD"
144+
if appVeyor || azDevops then ["-r"; "true"] else []
145+
ReposTooling.PackageValidator
146+
<| [p.Package; "-v"; v; "-a"; p.AssemblyName; "-k"; officialToken] @ ciArgs
147+
|> ignore
148+
190149
Zip.unzip tmp p.Package
191150
let nugetId = p.NugetId
192151

@@ -200,22 +159,9 @@ module Versioning =
200159

201160
let command = [ sprintf "previous-nuget|%s|%s|%s" nugetId (version.Full.ToString()) tfm;
202161
sprintf "directory|%s" fullPath
203-
"-a"; "-f"; "github-comment";]
162+
"-a"; "-f"; "github-comment"; "--output"; Paths.BuildOutput]
204163

205164
ReposTooling.Differ command
206165
)
207-
208-
!! (sprintf "%s/**/*.dll" tmp)
209-
|> Seq.iter(fun f ->
210-
let fv = FileVersionInfo.GetVersionInfo(f)
211-
let name = AssemblyName.GetAssemblyName(f)
212-
let a = name.Version
213-
printfn "Assembly: %A File: %s Product: %s => %s" a fv.FileVersion fv.ProductVersion f
214-
if (a.Minor > 0 || a.Revision > 0 || a.Build > 0) then failwith (sprintf "%s assembly version is not sticky to its major component" f)
215-
if (parse (fv.ProductVersion) <> version.Full) then
216-
failwith (sprintf "Expected product info %s to match new version %O " fv.ProductVersion fileVersion)
217-
218-
validateDllStrongName f f
219-
)
220166
Directory.delete tmp
221167
)

build/scripts/scripts.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<PackageReference Include="Fake.Core.SemVer" Version="5.15.0" />
4545
<PackageReference Include="Fake.IO.FileSystem" Version="5.15.0" />
4646
<PackageReference Include="Fake.IO.Zip" Version="5.15.0" />
47+
<PackageReference Include="Fake.Tools.Git" Version="5.15.0" />
4748

4849
<PackageReference Include="ILRepack" Version="2.1.0-beta1" />
4950
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />

dotnet-tools.json

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"commands": [
1414
"assembly-differ"
1515
]
16+
},
17+
"nupkg-validator": {
18+
"version": "0.3.1",
19+
"commands": [
20+
"nupkg-validator"
21+
]
1622
}
1723
}
1824
}

0 commit comments

Comments
 (0)