From 015f6f5a4ecbe498fdb4be04eb586a2e682f8801 Mon Sep 17 00:00:00 2001 From: "Angel D. Munoz" Date: Mon, 4 Nov 2024 07:00:58 -0600 Subject: [PATCH] chore: update build --- .github/workflows/docs.yml | 10 +--- .github/workflows/library.yml | 6 +-- .github/workflows/sample.yml | 3 +- README.md | 4 ++ build.fsx | 97 +++++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 build.fsx diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bf533cd..50d8dec 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -25,14 +25,8 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 # Restore the local tools - - name: Restore tools - run: dotnet tool restore - # Build the code for the API documentation - - name: Build code - run: dotnet build -c Release Threads.Lib/Threads.Lib.fsproj - # Generate the documentation files - - name: Generate the documentation' - run: dotnet fsdocs build --properties Configuration=Release + - name: Build Docs + run: dotnet fsi build.fsx -- -p ci:docs # Upload the static files - name: Upload documentation uses: actions/upload-pages-artifact@v3 diff --git a/.github/workflows/library.yml b/.github/workflows/library.yml index f38e6fd..e19aa79 100644 --- a/.github/workflows/library.yml +++ b/.github/workflows/library.yml @@ -17,13 +17,11 @@ on: jobs: build: runs-on: ubuntu-latest - name: Build dotnet 8.0 + name: Build Library steps: - uses: actions/checkout@v4 - name: Setup dotnet uses: actions/setup-dotnet@v4 with: dotnet-version: "8.0.x" - - run: dotnet restore - - run: dotnet build Threads.Lib -f net8.0 --configuration Release --no-restore - - run: dotnet test Threads.Lib.Tests -f net8.0 --no-restore + - run: dotnet fsi build.fsx -- -p ci:library diff --git a/.github/workflows/sample.yml b/.github/workflows/sample.yml index 976a008..4af5258 100644 --- a/.github/workflows/sample.yml +++ b/.github/workflows/sample.yml @@ -25,5 +25,4 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: "8.0.x" - - run: dotnet restore Sample/Sample.fsproj - - run: dotnet build Sample/Sample.fsproj -f net8.0 --configuration Release --no-restore + - run: dotnet fsi build.fsx -- -p ci:sample diff --git a/README.md b/README.md index 345af42..a8a24e3 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,7 @@ async { - `dotnet run script.fsx` should print the profile response. For more information, check out the docs at https://angelmunoz.github.io/Threads.Lib/ + +# Build locally + +`dotnet fsi build.fsx -- -p build diff --git a/build.fsx b/build.fsx new file mode 100644 index 0000000..2d5b048 --- /dev/null +++ b/build.fsx @@ -0,0 +1,97 @@ +#r "nuget: Fun.Build, 1.1.14" +#r "nuget: Fun.Result, 2.1.0" + +open System.IO +open Fun.Build + +let restore name = stage $"Restoring {name}" { run $"dotnet restore {name}" } + +let build name = stage $"Building {name}" { + run $"dotnet build {name} -f net8.0 --no-restore -c Release" +} + +let test name = stage $"Testing {name}" { + run $"dotnet test {name} -f net8.0 --no-restore" +} + +let pack name = stage $"Packing {name}" { + run $"dotnet pack {name} --no-build --no-restore -o dist" +} + +let pushNugets = stage $"Push to NuGet" { + + run(fun ctx -> async { + + let nugetApiKey = ctx.GetEnvVar "NUGET_DEPLOY_KEY" + let nugets = Directory.GetFiles(__SOURCE_DIRECTORY__ + "/dist", "*.nupkg") + + for nuget in nugets do + printfn "Pushing %s" nuget + + let! res = + ctx.RunSensitiveCommand + $"dotnet nuget push {nuget} --skip-duplicate -s https://api.nuget.org/v3/index.json -k {nugetApiKey}" + + match res with + | Ok _ -> return () + | Error err -> failwith err + }) +} + + +pipeline "release" { + let project = "Threads.Lib" + restore project + build project + pack project + pushNugets + runIfOnlySpecified true +} + +pipeline "release:local" { + let project = "Threads.Lib" + restore project + build project + pack project + runIfOnlySpecified true +} + +pipeline "ci:library" { + let project = "Threads.Lib" + restore project + build project + test project + runIfOnlySpecified true +} + +pipeline "ci:docs" { + stage "Restoring Tools" { run "dotnet tool restore" } + restore "Threads.Lib" + build "Threads.Lib" + + stage "Fsdocs build" { + run "dotnet fsdocs build --properties Condfiguration=Release" + } + + runIfOnlySpecified true +} + + +pipeline "ci:sample" { + let project = "Sample/Sample.fsproj" + restore project + build project + + runIfOnlySpecified true +} + +pipeline "build" { + stage "Restoring Tools" { run "dotnet tool restore" } + stage "Restore Solution" { run "dotnet restore" } + stage "Build Solution" { run "dotnet build -f net8.0 --no-restore -tl" } + stage "Test Solution" { run "dotnet test -f net8.0 --no-restore" } + + runIfOnlySpecified true +} + +tryPrintPipelineCommandHelp()