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
2 changes: 1 addition & 1 deletion .github/workflows/on-push-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Build Self
run: |
echo "# Self Build" >> $GITHUB_STEP_SUMMARY
make self config=Release terrabuild=$PWD/.out/dotnet/terrabuild
make self config=Release

- name: Self Integration Tests
run: make smoke-tests terrabuild=$PWD/.out/dotnet/terrabuild
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ docs:
dotnet run --project tools/DocGen -- src/Terrabuild.Extensions/bin/$(config)/net9.0/Terrabuild.Extensions.xml ../terrabuild.io/content/docs/extensions

self: clean publish
$(terrabuild) run build test dist --configuration $(config) --retry --debug --log --local-only
$(PWD)/.out/dotnet/terrabuild run build test dist --configuration $(config) --debug --log --retry --local-only

self-logs:
$(terrabuild) logs build test dist --configuration $(config) --debug --log --local-only
$(PWD)/.out/dotnet/terrabuild logs build test dist --configuration $(config) --debug --log --local-only

logs:
$(terrabuild) logs build test dist --configuration $(config) --debug --log --local-only
Expand Down
4 changes: 4 additions & 0 deletions src/Terrabuild.Configuration.Tests/Project.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,22 @@ let parseProject() =
TargetBlock.Rebuild = None
TargetBlock.Outputs = None
TargetBlock.Cache = None
TargetBlock.Managed = None
TargetBlock.Steps = [ { Extension = "@dotnet"; Command = "build"; Parameters = Map.empty } ] }
let targetDist =
{ TargetBlock.DependsOn = None
TargetBlock.Rebuild = None
TargetBlock.Outputs = None
TargetBlock.Cache = None
TargetBlock.Managed = Expr.False |> Some
TargetBlock.Steps = [ { Extension = "@dotnet"; Command = "build"; Parameters = Map.empty }
{ Extension = "@dotnet"; Command = "publish"; Parameters = Map.empty } ] }
let targetDocker =
{ TargetBlock.DependsOn = None
TargetBlock.Rebuild = Some (Expr.Bool false)
TargetBlock.Outputs = None
TargetBlock.Cache = "always" |> Expr.String |> Some
TargetBlock.Managed = None
TargetBlock.Steps = [ { Extension = "@shell"; Command = "echo"
Parameters = Map [ "arguments", Expr.Function (Function.Trim,
[ Expr.Function (Function.Plus,
Expand Down Expand Up @@ -115,6 +118,7 @@ let parseProject2() =
Expr.String ".dll" ])] |> Some
TargetBlock.DependsOn = None
TargetBlock.Cache = None
TargetBlock.Managed = None
TargetBlock.Steps = [ { Extension = "@dotnet"; Command = "build"; Parameters = Map.empty } ] }

let locals =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ target build {
}

target dist {
managed = false
@dotnet build { }
@dotnet publish { }
}
Expand Down
1 change: 1 addition & 0 deletions src/Terrabuild.Configuration/AST/Project.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type TargetBlock =
Outputs: Expr option
DependsOn: Set<string> option
Cache: Expr option
Managed: Expr option
Steps: Step list }

[<RequireQualifiedAccess>]
Expand Down
6 changes: 4 additions & 2 deletions src/Terrabuild.Configuration/Transpiler/Project.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let toProject (block: Block) =

let toTarget (block: Block) =
block
|> checkAllowedAttributes ["rebuild"; "outputs"; "depends_on"; "cache"]
|> checkAllowedAttributes ["rebuild"; "outputs"; "depends_on"; "cache"; "managed"]
|> ignore

let rebuild = block |> tryFindAttribute "rebuild"
Expand All @@ -85,6 +85,7 @@ let toTarget (block: Block) =
| String.Regex "^target\.(.*)$" [targetIdentifier] -> targetIdentifier
| _ -> raiseInvalidArg $"Invalid target dependency '{dependency}'"))
let cache = block |> tryFindAttribute "cache"
let managed = block |> tryFindAttribute "managed"
let steps =
block.Blocks
|> List.map (fun step ->
Expand All @@ -110,7 +111,8 @@ let toTarget (block: Block) =
TargetBlock.Outputs = outputs
TargetBlock.DependsOn = dependsOn
TargetBlock.Cache = cache
TargetBlock.Steps = steps }
TargetBlock.Steps = steps
TargetBlock.Managed = managed }



Expand Down
8 changes: 5 additions & 3 deletions src/Terrabuild.Extensibility/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ type ShellOperations = ShellOperation list
type ActionExecutionRequest = {
Cache: Cacheability
Operations: ShellOperations
SideEffect: bool
}


let shellOp cmd args =
let shellOp(cmd, args) =
{ ShellOperation.Command = cmd
ShellOperation.Arguments = args }

let execRequest cache ops =
let execRequest(cache, ops, sideEffect) =
{ ActionExecutionRequest.Cache = cache
ActionExecutionRequest.Operations = ops }
ActionExecutionRequest.Operations = ops
ActionExecutionRequest.SideEffect = sideEffect }
12 changes: 6 additions & 6 deletions src/Terrabuild.Extensions/Cargo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type Cargo() =
let arguments = arguments |> Option.defaultValue ""
let arguments = $"{context.Command} {arguments}"

let ops = [ shellOp "cargo" arguments ]
execRequest Cacheability.Always ops
let ops = [ shellOp("cargo", arguments) ]
execRequest(Cacheability.Always, ops, false)


/// <summary title="Build project.">
Expand All @@ -60,8 +60,8 @@ type Cargo() =
let profile = profile |> Option.defaultValue "dev"
let arguments = arguments |> Option.defaultValue ""

let ops = [ shellOp "cargo" $"build --profile {profile} {arguments}" ]
execRequest Cacheability.Always ops
let ops = [ shellOp("cargo", $"build --profile {profile} {arguments}") ]
execRequest(Cacheability.Always, ops, false)


/// <summary>
Expand All @@ -73,5 +73,5 @@ type Cargo() =
let profile = profile |> Option.defaultValue "dev"
let arguments = arguments |> Option.defaultValue ""

let ops = [ shellOp "cargo" $"test --profile {profile} {arguments}" ]
execRequest Cacheability.Always ops
let ops = [ shellOp("cargo", $"test --profile {profile} {arguments}") ]
execRequest(Cacheability.Always, ops, false)
16 changes: 8 additions & 8 deletions src/Terrabuild.Extensions/Docker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type Docker() =
let arguments = arguments |> Option.defaultValue ""
let arguments = $"{context.Command} {arguments}"

let ops = [ shellOp "docker" arguments ]
execRequest Cacheability.Always ops
let ops = [ shellOp("docker", arguments) ]
execRequest(Cacheability.Always, ops, true)


/// <summary>
Expand All @@ -42,15 +42,15 @@ type Docker() =
let ops =
[
let buildArgs = $"build --file {dockerfile} --tag {image}:{context.Hash}{args}{platformArgs} ."
shellOp "docker" buildArgs
if context.CI then shellOp "docker" $"push {image}:{context.Hash}"
shellOp("docker", buildArgs)
if context.CI then shellOp("docker", $"push {image}:{context.Hash}")
]

let cacheability =
if context.CI then Cacheability.Remote
else Cacheability.Local

execRequest cacheability ops
execRequest(cacheability, ops, true)


/// <summary>
Expand All @@ -62,13 +62,13 @@ type Docker() =
let ops =
[
if context.CI then
shellOp "docker" $"buildx imagetools create -t {image}:{tag} {image}:{context.Hash}"
shellOp("docker", $"buildx imagetools create -t {image}:{tag} {image}:{context.Hash}")
else
shellOp "docker" $"tag {image}:{context.Hash} {image}:{tag}"
shellOp("docker", $"tag {image}:{context.Hash} {image}:{tag}")
]

let cacheability =
if context.CI then Cacheability.Remote
else Cacheability.Local

execRequest cacheability ops
execRequest(cacheability, ops, true)
35 changes: 16 additions & 19 deletions src/Terrabuild.Extensions/Dotnet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ module DotnetHelpers =
/// </summary>
type Dotnet() =

static let buildRequest (context: ActionContext) buildOps =
execRequest Cacheability.Always buildOps

/// <summary>
/// Provides default values for project.
/// </summary>
Expand All @@ -85,8 +82,8 @@ type Dotnet() =
let arguments = arguments |> Option.defaultValue ""
let arguments = $"{context.Command} {arguments}"

let ops = [ shellOp "dotnet" arguments ]
execRequest Cacheability.Always ops
let ops = [ shellOp("dotnet", arguments) ]
execRequest(Cacheability.Always, ops, false)


/// <summary title="Build project.">
Expand Down Expand Up @@ -118,11 +115,11 @@ type Dotnet() =

let arguments = arguments |> Option.defaultValue ""

let buildOps = [
shellOp "dotnet" $"build --no-dependencies --configuration {configuration} {logger} {maxcpucount} {version} {arguments}"
let ops = [
shellOp("dotnet", $"build --no-dependencies --configuration {configuration} {logger} {maxcpucount} {version} {arguments}")
]

buildRequest context buildOps
execRequest(Cacheability.Always, ops, false)


/// <summary>
Expand All @@ -136,11 +133,11 @@ type Dotnet() =
let version = version |> Option.defaultValue "0.0.0"
let arguments = arguments |> Option.defaultValue ""

let buildOps = [
shellOp "dotnet" $"pack --no-build --configuration {configuration} /p:Version={version} /p:TargetsForTfmSpecificContentInPackage= {arguments}"
let ops = [
shellOp("dotnet", $"pack --no-build --configuration {configuration} /p:Version={version} /p:TargetsForTfmSpecificContentInPackage= {arguments}")
]

buildRequest context buildOps
execRequest(Cacheability.Always, ops, false)

/// <summary>
/// Publish a project.
Expand All @@ -167,11 +164,11 @@ type Dotnet() =
| _ -> ""
let arguments = arguments |> Option.defaultValue ""

let buildOps = [
shellOp "dotnet" $"publish --no-dependencies --configuration {configuration} {runtime} {trim} {single} {arguments}"
let ops = [
shellOp("dotnet", $"publish --no-dependencies --configuration {configuration} {runtime} {trim} {single} {arguments}")
]

buildRequest context buildOps
execRequest(Cacheability.Always, ops, false)

/// <summary>
/// Restore packages.
Expand All @@ -181,8 +178,8 @@ type Dotnet() =
static member restore (arguments: string option) =
let arguments = arguments |> Option.defaultValue ""

let ops = [ shellOp "dotnet" $"restore {arguments}" ]
execRequest Cacheability.Local ops
let ops = [ shellOp( "dotnet", $"restore {arguments}") ]
execRequest(Cacheability.Local, ops, false)


/// <summary>
Expand All @@ -196,8 +193,8 @@ type Dotnet() =
let filter = filter |> Option.map (fun filter -> $" --filter \"{filter}\"") |> Option.defaultValue ""
let arguments = arguments |> Option.defaultValue ""

let buildOps = [
shellOp "dotnet" $"test --no-build --configuration {configuration} {filter} {arguments}"
let ops = [
shellOp("dotnet", $"test --no-build --configuration {configuration} {filter} {arguments}")
]

buildRequest context buildOps
execRequest(Cacheability.Local, ops, false)
9 changes: 4 additions & 5 deletions src/Terrabuild.Extensions/Gradle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Gradle() =
let arguments = arguments |> Option.defaultValue ""
let arguments = $"{context.Command} {arguments}"

let ops = [ shellOp "gradle" arguments ]
execRequest Cacheability.Always ops
let ops = [ shellOp("gradle", arguments) ]
execRequest(Cacheability.Always, ops, false)


/// <summary>
Expand All @@ -41,6 +41,5 @@ type Gradle() =
static member build (context: ActionContext) (configuration: string option) =
let configuration = configuration |> Option.defaultValue GradleHelpers.defaultConfiguration

let ops = [ shellOp "gradlew" $"assemble{configuration}" ]

execRequest Cacheability.Always ops
let ops = [ shellOp("gradlew", $"assemble{configuration}") ]
execRequest(Cacheability.Always, ops, false)
4 changes: 2 additions & 2 deletions src/Terrabuild.Extensions/Make.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type Make() =
/// <param name="variables" example="{ configuration: &quot;Release&quot; }">Variables to pass to make target.</param>
static member __dispatch__ (context: ActionContext) (variables: Map<string, string>) =
let args = variables |> Seq.fold (fun acc kvp -> $"{acc} {kvp.Key}=\"{kvp.Value}\"") $"{context.Command}"
let ops = [ shellOp "make" args ]
execRequest Cacheability.Always ops
let ops = [ shellOp("make", args) ]
execRequest(Cacheability.Always, ops, false)
24 changes: 12 additions & 12 deletions src/Terrabuild.Extensions/Npm.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ type Npm() =
let arguments = arguments |> Option.defaultValue ""

let ops = [
shellOp "npm" $"{cmd} {arguments}"
shellOp("npm", $"{cmd} {arguments}")
]
execRequest Cacheability.Always ops
execRequest(Cacheability.Always, ops, false)


/// <summary>
/// Install packages using lock file.
/// </summary>
static member install (context: ActionContext) (force: bool option)=
let force = if force = Some true then " --force" else ""
let ops = [ shellOp "npm" $"ci{force}" ]
execRequest Cacheability.Always ops
let ops = [ shellOp("npm", $"ci{force}") ]
execRequest(Cacheability.Always, ops, false)


/// <summary>
Expand All @@ -56,10 +56,10 @@ type Npm() =
let args = arguments |> Option.defaultValue ""

let ops = [
shellOp "npm" "ci"
shellOp "npm" $"run build -- {args}"
shellOp("npm", "ci")
shellOp("npm", $"run build -- {args}")
]
execRequest Cacheability.Always ops
execRequest(Cacheability.Always, ops, false)


/// <summary>
Expand All @@ -70,10 +70,10 @@ type Npm() =
let args = arguments |> Option.defaultValue ""

let ops = [
shellOp "npm" "ci"
shellOp "npm" $"run test -- {args}"
shellOp("npm", "ci")
shellOp("npm", $"run test -- {args}")
]
execRequest Cacheability.Always ops
execRequest(Cacheability.Always, ops, false)

/// <summary>
/// Run `run` script.
Expand All @@ -83,6 +83,6 @@ type Npm() =
let args = arguments |> Option.defaultValue ""

let ops = [
shellOp "npm" $"run {command} -- {args}"
shellOp("npm", $"run {command} -- {args}")
]
execRequest Cacheability.Always ops
execRequest(Cacheability.Always, ops, false)
4 changes: 2 additions & 2 deletions src/Terrabuild.Extensions/OpenApi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ type OpenApi() =
let args = $"generate -i {input} -g {generator} -o {output}"

let ops = [
shellOp "docker-entrypoint.sh" args
shellOp("docker-entrypoint.sh", args)
]
execRequest Cacheability.Always ops
execRequest(Cacheability.Always, ops, false)
4 changes: 2 additions & 2 deletions src/Terrabuild.Extensions/Shell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type Shell() =
/// <param name="arguments" example="&quot;Hello Terrabuild&quot;">Arguments to pass to command.</param>
static member __dispatch__ (context: ActionContext) (arguments: string option) =
let arguments = arguments |> Option.defaultValue ""
let ops = [ shellOp context.Command arguments ]
execRequest Cacheability.Always ops
let ops = [ shellOp(context.Command, arguments) ]
execRequest(Cacheability.Always, ops, false)
Loading