Skip to content

Commit 27d9174

Browse files
committed
Refactor build scripts and workflows for consistency
This brings them inline with the other .NET repositories at Elastic
1 parent e7d5741 commit 27d9174

File tree

11 files changed

+416
-64
lines changed

11 files changed

+416
-64
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ permissions:
1111
contents: read
1212
packages: write
1313

14-
env:
15-
BASE_IMAGE: mcr.microsoft.com/dotnet/nightly/runtime-deps:8.0-jammy-chiseled-aot
16-
BASE_IMAGE_SINGLE: mcr.microsoft.com/dotnet/nightly/runtime-deps:8.0-jammy-chiseled
17-
DOCKER_TAG: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && 'latest;edge' || 'edge' }}
18-
1914
jobs:
2015
deploy:
2116
runs-on: ubuntu-latest
@@ -70,24 +65,6 @@ jobs:
7065
username: ${{ github.actor }}
7166
password: ${{ secrets.GITHUB_TOKEN }}
7267

73-
- name: Publish docs-builder
74-
run: |
75-
dotnet publish "src/docs-builder/docs-builder.csproj" \
76-
/t:PublishContainer \
77-
-p DebugType=none \
78-
-p ContainerUser=1001:1001 \
79-
-p ContainerBaseImage=${{ env.BASE_IMAGE }} \
80-
-p ContainerRegistry=ghcr.io \
81-
-p ContainerImageTags='"${{ env.DOCKER_TAG }};${{ steps.bootstrap.outputs.full-version }}"' \
82-
-p ContainerRepository=${{ github.repository }}
8368

84-
- name: Publish docs-generator
85-
run: |
86-
dotnet publish "src/docs-generator/docs-generator.csproj" \
87-
/t:PublishContainer \
88-
-p DebugType=none \
89-
-p ContainerUser=1001:1001 \
90-
-p ContainerBaseImage=${{ env.BASE_IMAGE_SINGLE }} \
91-
-p ContainerRegistry=ghcr.io \
92-
-p ContainerImageTags='"${{ env.DOCKER_TAG }};${{ steps.bootstrap.outputs.full-version }}"' \
93-
-p ContainerRepository=elastic/docs-generator \
69+
- name: publish containers
70+
run: ./build.sh publishcontainers

.github/workflows/pr.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ jobs:
3030
- name: Bootstrap Action Workspace
3131
id: bootstrap
3232
uses: ./.github/actions/bootstrap
33-
33+
34+
- name: lint
35+
run: ./build.sh lint
36+
3437
- name: build
3538
run: ./build.sh
36-
39+
40+
- name: test
41+
run: ./build.sh test
42+
3743
- name: publish AOT
38-
run: ./build.sh publish
44+
run: ./build.sh publishbinaries
3945

build/BuildInformation.fs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
module BuildInformation
6+
7+
open System
8+
open System.IO
9+
open System.Threading
10+
open System.Xml.Linq
11+
open System.Xml.XPath
12+
open Fake.Core
13+
open Proc.Fs
14+
open Fake.Tools.Git
15+
16+
type Paths =
17+
static member Root =
18+
let mutable dir = DirectoryInfo(".")
19+
let mutable rooted = false
20+
while not(rooted) && dir.GetFiles("*.sln").Length = 0 do
21+
match dir.Parent with
22+
| NonNull parent -> dir <- parent
23+
| _ -> rooted <- true
24+
Environment.CurrentDirectory <- dir.FullName
25+
dir
26+
27+
static member RelativePathToRoot path = Path.GetRelativePath(Paths.Root.FullName, path)
28+
29+
static member ArtifactFolder = DirectoryInfo(Path.Combine(Paths.Root.FullName, ".artifacts"))
30+
static member ArtifactPath t = DirectoryInfo(Path.Combine(Paths.ArtifactFolder.FullName, t))
31+
32+
static member private SrcFolder = DirectoryInfo(Path.Combine(Paths.Root.FullName, "src"))
33+
static member SrcPath (t: string list) = DirectoryInfo(Path.Combine([Paths.SrcFolder.FullName] @ t |> List.toArray))
34+
35+
36+
type BuildConfiguration =
37+
static member ValidateAssemblyName = false
38+
static member GenerateApiChanges = false
39+
40+
type Software =
41+
static member Organization = "elastic"
42+
static member Repository = "docs-builder"
43+
static member GithubMoniker = $"%s{Software.Organization}/%s{Software.Repository}"
44+
static member SignKey = "069ca2728db333c1"
45+
46+
static let restore =
47+
Lazy<unit>((fun _ -> exec { run "dotnet" "tool" "restore" }), LazyThreadSafetyMode.ExecutionAndPublication)
48+
49+
static let versionInfo =
50+
Lazy<SemVerInfo>(fun _ ->
51+
let sha = Information.getCurrentSHA1 "."
52+
let output = exec {
53+
binary "dotnet"
54+
arguments "minver" "-p" "canary.0" "-m" "0.1"
55+
find (fun l -> not(l.Error))
56+
}
57+
SemVer.parse <| $"%s{output.Line}+%s{sha}"
58+
, LazyThreadSafetyMode.ExecutionAndPublication)
59+
60+
static member Version = restore.Value; versionInfo.Value
61+
62+
type OS =
63+
| OSX | Windows | Linux
64+
with
65+
static member Current =
66+
match int Environment.OSVersion.Platform with
67+
| 4 | 128 -> Linux
68+
| 6 -> OSX
69+
| _ -> Windows
70+

build/CommandLine.fs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
module CommandLine
6+
7+
open Argu
8+
open Microsoft.FSharp.Reflection
9+
open System
10+
open Bullseye
11+
12+
type Build =
13+
| [<CliPrefix(CliPrefix.None);SubCommand>] Clean
14+
| [<CliPrefix(CliPrefix.None);SubCommand>] Version
15+
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] Compile
16+
| [<CliPrefix(CliPrefix.None);SubCommand>] Build
17+
| [<CliPrefix(CliPrefix.None);SubCommand>] Test
18+
19+
| [<CliPrefix(CliPrefix.None);SubCommand>] Format
20+
21+
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] Lint
22+
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] PristineCheck
23+
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] ValidateLicenses
24+
25+
| [<CliPrefix(CliPrefix.None);SubCommand>] Publish
26+
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] PublishBinaries
27+
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] PublishContainers
28+
29+
| [<CliPrefix(CliPrefix.None);SubCommand>] ReleaseNotes
30+
| [<CliPrefix(CliPrefix.None);SubCommand>] Release
31+
32+
| [<Inherit;AltCommandLine("-s")>] Single_Target
33+
| [<Inherit>] Token of string
34+
| [<Inherit;AltCommandLine("-c")>] Skip_Dirty_Check
35+
with
36+
interface IArgParserTemplate with
37+
member this.Usage =
38+
match this with
39+
// commands
40+
| Clean -> "clean known output locations"
41+
| Version -> "print version information"
42+
| Build -> "Run build"
43+
44+
| Test -> "runs a clean build and then runs all the tests "
45+
| Release -> "runs build, tests, and create and validates the packages shy of publishing them"
46+
| Publish -> "Publishes artifacts"
47+
| Format -> "runs dotnet format"
48+
49+
// steps
50+
| Lint
51+
| PristineCheck
52+
| PublishBinaries
53+
| PublishContainers
54+
| ValidateLicenses
55+
| ReleaseNotes
56+
| Compile
57+
58+
// flags
59+
| Single_Target -> "Runs the provided sub command without running their dependencies"
60+
| Token _ -> "Token to be used to authenticate with github"
61+
| Skip_Dirty_Check -> "Skip the clean checkout check that guards the release/publish targets"
62+
63+
member this.StepName =
64+
match FSharpValue.GetUnionFields(this, typeof<Build>) with
65+
| case, _ -> case.Name.ToLowerInvariant()
66+
67+
static member Targets =
68+
let cases = FSharpType.GetUnionCases(typeof<Build>)
69+
seq {
70+
for c in cases do
71+
if c.GetFields().Length = 0 then
72+
FSharpValue.MakeUnion(c, [| |]) :?> Build
73+
}
74+
75+
static member Ignore (_: Build) _ = ()
76+
77+
static member Step action (target: Build) parsed =
78+
Targets.Target(target.StepName, Action(fun _ -> action(parsed)))
79+
80+
static member Cmd (dependsOn: Build list) (composedOf: Build list) action (target: Build) (parsed: ParseResults<Build>) =
81+
let singleTarget = parsed.TryGetResult Single_Target |> Option.isSome
82+
let dependsOn = if singleTarget then [] else dependsOn
83+
84+
let steps = dependsOn @ composedOf |> List.map _.StepName
85+
Targets.Target(target.StepName, steps, Action(fun _ -> action parsed))

build/Program.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@
1818
await "dotnet test --configuration Release --logger GitHubActions -- RunConfiguration.CollectSourceInformation=true";
1919
});
2020

21-
app.Add("publish", async (Cancel _) =>
22-
{
23-
var source = "src/docs-builder/docs-builder.csproj";
24-
await $"""
25-
dotnet publish {source}
26-
""";
27-
28-
var generatorSource = "src/docs-generator/docs-generator.csproj";
29-
await $"""
30-
dotnet publish {generatorSource}
31-
""";
32-
});
33-
3421
// this is manual for now and quite hacky.
3522
// this ensures we download the actual LICENSE files in the repositories.
3623
// NOT the SPDX html from licenses.nuget.org

build/Program.fs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
module Program
6+
7+
open Argu
8+
open Bullseye
9+
open ProcNet
10+
open CommandLine
11+
12+
[<EntryPoint>]
13+
let main argv =
14+
let argv = if argv.Length = 0 then ["build"] |> Array.ofList else argv
15+
let parser = ArgumentParser.Create<Build>(programName = "./build.sh")
16+
let parsed =
17+
try
18+
let parsed = parser.ParseCommandLine(inputs = argv, raiseOnUsage = true)
19+
Some parsed
20+
with e ->
21+
printfn $"%s{e.Message}"
22+
None
23+
24+
match parsed with
25+
| None -> 2
26+
| Some parsed ->
27+
28+
let target = parsed.GetSubCommand().StepName
29+
Targets.Setup parsed
30+
31+
let swallowTypes = [typeof<ProcExecException>; typeof<ExceptionExiter>]
32+
let shortErrorsFor = (fun e -> swallowTypes |> List.contains (e.GetType()) )
33+
34+
async {
35+
do! Async.SwitchToThreadPool ()
36+
return! Targets.RunTargetsAndExitAsync([target], shortErrorsFor, fun _ -> ":") |> Async.AwaitTask
37+
} |> Async.RunSynchronously
38+
39+
0
40+

0 commit comments

Comments
 (0)