Skip to content

Commit

Permalink
Merge pull request #21 from elastic/fix/build-scripts
Browse files Browse the repository at this point in the history
Introduce refactored build scripts
  • Loading branch information
Mpdreamz authored Jan 8, 2024
2 parents 073bb3b + 126a0d6 commit 78706ae
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 224 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<PropertyGroup>
<MinVerDefaultPreReleasePhase>canary</MinVerDefaultPreReleasePhase>
<MinVerDefaultPreReleaseIdentifiers>canary.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>

<LangVersion>latest</LangVersion>
Expand All @@ -21,6 +21,6 @@
<ArtifactsPath>$(MSBuildThisFileDirectory).artifacts</ArtifactsPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MinVer" Version="2.3.1" PrivateAssets="all" />
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="all" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions Elastic.OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "docs", "docs\docs.csproj", "{37AF68F4-59EF-4B10-B1A0-87DEEB37CDCA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{AAD39891-0B70-47FA-A212-43E1AAE5DF56}"
ProjectSection(SolutionItems) = preProject
tests\Directory.Build.props = tests\Directory.Build.props
tests\xunit.runner.json = tests\xunit.runner.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.OpenTelemetry.Tests", "tests\Elastic.OpenTelemetry.Tests\Elastic.OpenTelemetry.Tests.csproj", "{22BF9223-3A6D-4197-8527-3E4E43A98A81}"
EndProject
Expand Down
8 changes: 4 additions & 4 deletions build/build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Argu" Version="6.1.1"/>
<PackageReference Include="Bullseye" Version="3.5.0"/>
<PackageReference Include="Proc" Version="0.6.2"/>
<PackageReference Include="Argu" Version="6.1.4" />
<PackageReference Include="Bullseye" Version="4.2.1" />
<PackageReference Include="Proc.Fs" Version="0.7.2" />
<PackageReference Include="Fake.Tools.Git" Version="5.20.3"/>
</ItemGroup>

Expand All @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="scripts\Paths.fs"/>
<Compile Include="scripts\BuildInformation.fs" />
<Compile Include="scripts\CommandLine.fs"/>
<Compile Include="scripts\Targets.fs"/>
<Compile Include="scripts\Program.fs"/>
Expand Down
60 changes: 60 additions & 0 deletions build/scripts/BuildInformation.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

module BuildInformation

open System
open System.IO
open System.Threading
open Fake.Core
open Proc.Fs
open Fake.Tools.Git

type BuildConfiguration =
static member ValidateAssemblyName = false
static member GenerateApiChanges = false

type Software =
static member Organization = "elastic"
static member Repository = "elastic-otel-dotnet"
static member GithubMoniker = $"%s{Software.Organization}/%s{Software.Repository}"
static member SignKey = "069ca2728db333c1"

static let restore =
Lazy<unit>((fun _ -> exec { run "dotnet" "tool" "restore" }), LazyThreadSafetyMode.ExecutionAndPublication)

static let versionInfo =
Lazy<SemVerInfo>(fun _ ->
let sha = Information.getCurrentSHA1 "."
let output = exec {
binary "dotnet"
arguments "minver" "-p" "canary.0" "-m" "0.1"
find (fun l -> not(l.Error))
}
SemVer.parse <| $"%s{output.Line}+%s{sha}"
, LazyThreadSafetyMode.ExecutionAndPublication)

static member Version = restore.Value; versionInfo.Value

type Paths =
static member private Root =
let mutable dir = DirectoryInfo(".")
while dir.GetFiles("*.sln").Length = 0 do dir <- dir.Parent
Environment.CurrentDirectory <- dir.FullName
dir

static member RelativePathToRoot path = Path.GetRelativePath(Paths.Root.FullName, path)

static member ArtifactFolder = DirectoryInfo(Path.Combine(Paths.Root.FullName, ".artifacts"))
static member ArtifactPath t = DirectoryInfo(Path.Combine(Paths.ArtifactFolder.FullName, t))

type OS =
| OSX | Windows | Linux
with
static member Current =
match int Environment.OSVersion.Platform with
| 4 | 128 -> Linux
| 6 -> OSX
| _ -> Windows

55 changes: 39 additions & 16 deletions build/scripts/CommandLine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ module CommandLine

open Argu
open Microsoft.FSharp.Reflection
open System
open Bullseye

type Arguments =
type Build =
| [<CliPrefix(CliPrefix.None);SubCommand>] Clean
| [<CliPrefix(CliPrefix.None);SubCommand>] Version
| [<CliPrefix(CliPrefix.None);SubCommand>] Build
| [<CliPrefix(CliPrefix.None);SubCommand>] Test

Expand All @@ -19,33 +22,53 @@ type Arguments =
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] GenerateApiChanges
| [<CliPrefix(CliPrefix.None);SubCommand>] Release

| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] CreateReleaseOnGithub
| [<CliPrefix(CliPrefix.None);SubCommand>] Publish

| [<Inherit;AltCommandLine("-s")>] SingleTarget of bool
| [<Inherit;AltCommandLine("-s")>] SingleTarget
| [<Inherit>] Token of string
| [<Inherit;AltCommandLine("-c")>] CleanCheckout of bool
| [<Inherit;AltCommandLine("-c")>] SkipDirtyCheck
with
interface IArgParserTemplate with
member this.Usage =
match this with
// commands
| Clean -> "clean known output locations"
| Version -> "print version information"
| Build -> "Run build"
| Test -> "Runs build then tests"
| Release -> "runs build, tests, and create and validates the packages shy of publishing them"
| Publish -> "Runs the full release"

| SingleTarget _ -> "Runs the provided sub command without running their dependencies"
| Token _ -> "Token to be used to authenticate with github"
| CleanCheckout _ -> "Skip the clean checkout check that guards the release/publish targets"

// steps
| PristineCheck
| GeneratePackages
| ValidatePackages
| GenerateReleaseNotes
| GenerateApiChanges
| CreateReleaseOnGithub
-> "Undocumented, dependent target"
member this.Name =
match FSharpValue.GetUnionFields(this, typeof<Arguments>) with
| GenerateApiChanges -> "Undocumented, dependent target"

// flags
| SingleTarget -> "Runs the provided sub command without running their dependencies"
| Token _ -> "Token to be used to authenticate with github"
| SkipDirtyCheck -> "Skip the clean checkout check that guards the release/publish targets"

member this.StepName =
match FSharpValue.GetUnionFields(this, typeof<Build>) with
| case, _ -> case.Name.ToLowerInvariant()

static member Targets =
let cases = FSharpType.GetUnionCases(typeof<Build>)
seq {
for c in cases do
if c.GetFields().Length = 0 then
FSharpValue.MakeUnion(c, [| |]) :?> Build
}

static member Ignore (_: Build) _ = ()

static member Step action (target: Build) parsed =
Targets.Target(target.StepName, Action(fun _ -> action(parsed)))

static member Cmd (dependsOn: Build list) (composedOf: Build list) action (target: Build) (parsed: ParseResults<Build>) =
let singleTarget = parsed.TryGetResult SingleTarget |> Option.isSome
let dependsOn = if singleTarget then [] else dependsOn

let steps = dependsOn @ composedOf |> List.map (_.StepName)
Targets.Target(target.StepName, steps, Action(fun _ -> action parsed))

29 changes: 0 additions & 29 deletions build/scripts/Paths.fs

This file was deleted.

22 changes: 13 additions & 9 deletions build/scripts/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,30 @@ open CommandLine

[<EntryPoint>]
let main argv =
let parser = ArgumentParser.Create<Arguments>(programName = "./build.sh")
let argv = if argv.Length = 0 then ["build"] |> Array.ofList else argv
let parser = ArgumentParser.Create<Build>(programName = "./build.sh")
let parsed =
try
let parsed = parser.ParseCommandLine(inputs = argv, raiseOnUsage = true)
let arguments = parsed.GetSubCommand()
Some (parsed, arguments)
Some parsed
with e ->
printfn "%s" e.Message
printfn $"%s{e.Message}"
None

match parsed with
| None -> 2
| Some (parsed, arguments) ->
| Some parsed ->

let target = arguments.Name
let target = parsed.GetSubCommand().StepName
Targets.Setup parsed

Targets.Setup parsed arguments
let swallowTypes = [typeof<ProcExecException>; typeof<ExceptionExiter>]
let shortErrorsFor = (fun e -> swallowTypes |> List.contains (e.GetType()) )

async {
do! Async.SwitchToThreadPool ()
return! Targets.RunTargetsAndExitAsync([target], shortErrorsFor, fun _ -> ":") |> Async.AwaitTask
} |> Async.RunSynchronously

Targets.RunTargetsAndExit
([target], (fun e -> swallowTypes |> List.contains (e.GetType()) ), ":")
0

Loading

0 comments on commit 78706ae

Please sign in to comment.