Skip to content

Commit

Permalink
experiment: explicit Fun.Build cmd and env args
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissimon-au committed Nov 22, 2023
1 parent b6f9650 commit 9c2aebc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/contextive-languageserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@ jobs:
matrix:
include:
- dotnet_runtime: win-x64
vsce_platform: win32-x64
# vsce_platform: win32-x64
os: windows-latest
- dotnet_runtime: linux-x64
vsce_platform: linux-x64
# vsce_platform: linux-x64
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- uses: ./.github/actions/init-dotnet
- name: Map Matrix Variables to Env Variables
run: |
echo "${{ toJson(matrix) }}"
echo "DOTNET_RUNTIME=${{ matrix.dotnet_runtime }}" >> "$GITHUB_ENV"
echo "VSCE_PLATFORM=${{ matrix.vsce_platform }}" >> "$GITHUB_ENV"

- name: Build
run: dotnet fsi language-server/build.fsx
run: dotnet fsi language-server/build.fsx -- -r ${{ matrix.dotnet_runtime }}
working-directory: src

- name: Upload Language Server Test Results
Expand Down
55 changes: 42 additions & 13 deletions src/language-server/build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ open Fun.Build

type Component = { Name: string; Path: string }

let args =
{| runtime =
CmdArg.Create(
"-r",
"--runtime",
"Dotnet Runtime for Publishing, see https://learn.microsoft.com/en-us/dotnet/core/rid-catalog#known-rids",
isOptional = true
)
dotnetVersion =
EnvArg.Create(
"DOTNET_VERSION",
"Version of the DotNet SDK",
isOptional = true

)
os = EnvArg.Create("RUNNER_OS", "Operating System", isOptional = true)
event = EnvArg.Create("GITHUB_EVENT_NAME", isOptional = true)
ref = EnvArg.Create("GITHUB_REF", isOptional = true)
repo = EnvArg.Create("GITHUB_REPOSITORY", isOptional = true) |}

let core =
{ Name = "Contextive.Core"
Path = "core/Contextive.Core" }
Expand All @@ -12,18 +32,20 @@ let languageServer =
{ Name = "Contextive.LanguageServer"
Path = "language-server/Contextive.LanguageServer" }

let env key =
System.Environment.GetEnvironmentVariable(key)
let env (envArg: EnvArg) =
System.Environment.GetEnvironmentVariable(envArg.Name)

let toolInstall tool =
stage $"Install {tool}" { run $"dotnet tool install {tool} --global" }

let dotnetTest app =
stage $"Test {app.Name}" {
workingDir $"{app.Path}.Tests"
whenEnvVar args.dotnetVersion
whenEnvVar args.os

run
$"""dotnet test --logger "trx;LogFileName=TestResults.{app.Name}-{env "DOTNET_VERSION"}-{env "RUNNER_OS"}.xml" -- Expecto.fail-on-focused-tests=true Expecto.no-spinner=true Expecto.summary=true"""
$"""dotnet test --logger "trx;LogFileName=TestResults.{app.Name}-{env args.dotnetVersion}-{env args.os}.xml" -- Expecto.fail-on-focused-tests=true Expecto.no-spinner=true Expecto.summary=true"""
}

let logGroup (s: Internal.StageContext) =
Expand All @@ -34,14 +56,17 @@ let logGroup (s: Internal.StageContext) =
}

let dotnetPublish app =
let runTime =
match (env "DOTNET_RUNTIME") with
| r when r <> null -> $" -r {r}"
| _ -> ""

stage $"Publish {app.Name}" {
workingDir app.Path
run $"""dotnet publish -c RELEASE {runTime} -o publish"""
whenCmdArg args.runtime

run (fun ctx ->
let runTimeFlag =
match ctx.GetCmdArg(args.runtime) with
| r when not <| System.String.IsNullOrEmpty(r) -> $"-r {r}"
| _ -> ""

$"""dotnet publish -c RELEASE {runTimeFlag} -o publish""")
}

pipeline languageServer.Name {
Expand All @@ -51,12 +76,16 @@ pipeline languageServer.Name {
logGroup
<| stage "Log Environment" {
run "dotnet --version"
whenEnvVar args.event
whenEnvVar args.os
whenEnvVar args.ref
whenEnvVar args.repo

echo
$"""\
πŸŽ‰ The job was automatically triggered by a {env "GITHUB_EVENT_NAME"} event.
🐧 This job is now running on a {env "RUNNER_OS"} server hosted by GitHub!
πŸ”Ž The name of your branch is {env "GITHUB_REF"} and your repository is {env "GITHUB_REPOSITORY"}."""
$"""
πŸŽ‰ The job was automatically triggered by a {env args.event} event.
🐧 This job is now running on a {env args.os} server hosted by GitHub!
πŸ”Ž The name of your branch is {env args.ref} and your repository is {env args.repo}."""
}

logGroup
Expand Down

0 comments on commit 9c2aebc

Please sign in to comment.