Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ permissions:
contents: read
packages: write

env:
BASE_IMAGE: mcr.microsoft.com/dotnet/nightly/runtime-deps:8.0-jammy-chiseled-aot
BASE_IMAGE_SINGLE: mcr.microsoft.com/dotnet/nightly/runtime-deps:8.0-jammy-chiseled
DOCKER_TAG: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && 'latest;edge' || 'edge' }}

jobs:
deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -70,24 +65,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Publish docs-generator
run: |
dotnet publish "src/docs-generator/docs-generator.csproj" \
/t:PublishContainer \
-p DebugType=none \
-p ContainerUser=1001:1001 \
-p ContainerBaseImage=${{ env.BASE_IMAGE_SINGLE }} \
-p ContainerRegistry=ghcr.io \
-p ContainerImageTags='"${{ env.DOCKER_TAG }};${{ steps.bootstrap.outputs.full-version }}"' \
-p ContainerRepository=elastic/docs-generator \
- name: Publish Containers
run: ./build.sh publishcontainers
13 changes: 8 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ jobs:
- name: Bootstrap Action Workspace
id: bootstrap
uses: ./.github/actions/bootstrap
- name: build

- name: Build
run: ./build.sh

- name: publish AOT
run: ./build.sh publish

- name: Test
run: ./build.sh test

- name: Publish AOT
run: ./build.sh publishbinaries

70 changes: 70 additions & 0 deletions build/BuildInformation.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 System.Xml.Linq
open System.Xml.XPath
open Fake.Core
open Proc.Fs
open Fake.Tools.Git

type Paths =
static member Root =
let mutable dir = DirectoryInfo(".")
let mutable rooted = false
while not(rooted) && dir.GetFiles("*.sln").Length = 0 do
match dir.Parent with
| NonNull parent -> dir <- parent
| _ -> rooted <- true
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))

static member private SrcFolder = DirectoryInfo(Path.Combine(Paths.Root.FullName, "src"))
static member SrcPath (t: string list) = DirectoryInfo(Path.Combine([Paths.SrcFolder.FullName] @ t |> List.toArray))


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

type Software =
static member Organization = "elastic"
static member Repository = "docs-builder"
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 OS =
| OSX | Windows | Linux
with
static member Current =
match int Environment.OSVersion.Platform with
| 4 | 128 -> Linux
| 6 -> OSX
| _ -> Windows

85 changes: 85 additions & 0 deletions build/CommandLine.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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 CommandLine

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

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

| [<CliPrefix(CliPrefix.None);SubCommand>] Format

| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] Lint
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] PristineCheck
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] ValidateLicenses

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

| [<CliPrefix(CliPrefix.None);SubCommand>] ReleaseNotes
| [<CliPrefix(CliPrefix.None);SubCommand>] Release

| [<Inherit;AltCommandLine("-s")>] Single_Target
| [<Inherit>] Token of string
| [<Inherit;AltCommandLine("-c")>] Skip_Dirty_Check
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 a clean build and then runs all the tests "
| Release -> "runs build, tests, and create and validates the packages shy of publishing them"
| Publish -> "Publishes artifacts"
| Format -> "runs dotnet format"

// steps
| Lint
| PristineCheck
| PublishBinaries
| PublishContainers
| ValidateLicenses
| ReleaseNotes
| Compile

// flags
| Single_Target -> "Runs the provided sub command without running their dependencies"
| Token _ -> "Token to be used to authenticate with github"
| Skip_Dirty_Check -> "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 Single_Target |> 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))
13 changes: 0 additions & 13 deletions build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@
await "dotnet test --configuration Release --logger GitHubActions -- RunConfiguration.CollectSourceInformation=true";
});

app.Add("publish", async (Cancel _) =>
{
var source = "src/docs-builder/docs-builder.csproj";
await $"""
dotnet publish {source}
""";

var generatorSource = "src/docs-generator/docs-generator.csproj";
await $"""
dotnet publish {generatorSource}
""";
});

// this is manual for now and quite hacky.
// this ensures we download the actual LICENSE files in the repositories.
// NOT the SPDX html from licenses.nuget.org
Expand Down
40 changes: 40 additions & 0 deletions build/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 Program

open Argu
open Bullseye
open ProcNet
open CommandLine

[<EntryPoint>]
let main argv =
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)
Some parsed
with e ->
printfn $"%s{e.Message}"
None

match parsed with
| None -> 2
| Some parsed ->

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

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

0

Loading
Loading