From 7b4424a29d18493825b99b043d523c1eb0440194 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Thu, 9 Sep 2021 10:34:26 -0400 Subject: [PATCH] Moves main build script to use dotnet as runner instead of fake-cli --- .config/dotnet-tools.json | 24 +++--- MiniScaffold.sln | 14 ++++ build.cmd | 2 +- build.sh | 2 +- build.fsx => build/build.fs | 142 +++++++++++++++++++----------------- build/build.fsproj | 14 ++++ build/paket.references | 17 +++++ 7 files changed, 130 insertions(+), 85 deletions(-) rename build.fsx => build/build.fs (84%) create mode 100644 build/build.fsproj create mode 100644 build/paket.references diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index bb83d856..5ea9ecd2 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -1,18 +1,12 @@ { - "version": 1, - "isRoot": true, - "tools": { - "fake-cli": { - "version": "5.20.4-alpha.1642", - "commands": [ - "fake" - ] - }, - "paket": { - "version": "6.0.0-beta8", - "commands": [ - "paket" - ] + "version": 1, + "isRoot": true, + "tools": { + "paket": { + "version": "6.0.0-beta8", + "commands": [ + "paket" + ] + } } - } } diff --git a/MiniScaffold.sln b/MiniScaffold.sln index f1f3b8ac..a3b376e2 100644 --- a/MiniScaffold.sln +++ b/MiniScaffold.sln @@ -9,6 +9,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MiniScaffold.Tests", "tests EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "docsTool", "docsTool\docsTool.fsproj", "{361D039E-0F84-4D82-97E1-E4111B1C54DA}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "build", "build\build.fsproj", "{B89375C3-9F6B-4C83-8ECE-733799D01470}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -46,6 +48,18 @@ Global {361D039E-0F84-4D82-97E1-E4111B1C54DA}.Release|x64.Build.0 = Release|Any CPU {361D039E-0F84-4D82-97E1-E4111B1C54DA}.Release|x86.ActiveCfg = Release|Any CPU {361D039E-0F84-4D82-97E1-E4111B1C54DA}.Release|x86.Build.0 = Release|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Debug|x64.ActiveCfg = Debug|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Debug|x64.Build.0 = Debug|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Debug|x86.ActiveCfg = Debug|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Debug|x86.Build.0 = Debug|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Release|Any CPU.Build.0 = Release|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Release|x64.ActiveCfg = Release|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Release|x64.Build.0 = Release|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Release|x86.ActiveCfg = Release|Any CPU + {B89375C3-9F6B-4C83-8ECE-733799D01470}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {03550157-2E00-4662-A76E-9E7ED8CB0E7C} = {099ABA3C-C2CE-4465-AB6D-795AB722A2A8} diff --git a/build.cmd b/build.cmd index 8a0f008f..9da3b7a4 100644 --- a/build.cmd +++ b/build.cmd @@ -1,4 +1,4 @@ echo Restoring dotnet tools... dotnet tool restore -dotnet fake build -t %* +dotnet run -p ./build/build.fsproj -- -t %* diff --git a/build.sh b/build.sh index 9a855ac9..da4d2aae 100755 --- a/build.sh +++ b/build.sh @@ -6,4 +6,4 @@ set -o pipefail echo "Restoring dotnet tools..." dotnet tool restore -FAKE_DETAILED_ERRORS=true dotnet fake build -t "$@" +FAKE_DETAILED_ERRORS=true dotnet run -p ./build/build.fsproj -- -t "$@" diff --git a/build.fsx b/build/build.fs similarity index 84% rename from build.fsx rename to build/build.fs index 0c58fe03..f2c9ef6d 100644 --- a/build.fsx +++ b/build/build.fs @@ -1,13 +1,4 @@ -#load ".fake/build.fsx/intellisense.fsx" -#load "docsTool/CLI.fs" -#if !FAKE -#r "Facades/netstandard" -#r "netstandard" -#endif -#nowarn "52" - open System -open Fake.SystemHelper open Fake.Core open Fake.DotNet open Fake.Tools @@ -22,31 +13,29 @@ open Fake.BuildServer // Metadata and Configuration //----------------------------------------------------------------------------- -BuildServer.install [ - GitHubActions.Installer -] let srcGlob = "*.csproj" -let testsGlob = __SOURCE_DIRECTORY__ @@ "tests/**/*.??proj" +let testsGlob = __SOURCE_DIRECTORY__ ".." "tests/**/*.??proj" -let distDir = __SOURCE_DIRECTORY__ @@ "dist" -let distGlob = distDir @@ "*.nupkg" +let distDir = __SOURCE_DIRECTORY__ ".." "dist" +let distGlob = distDir "*.nupkg" -let docsDir = __SOURCE_DIRECTORY__ @@ "docs" -let docsSrcDir = __SOURCE_DIRECTORY__ @@ "docsSrc" -let docsToolDir = __SOURCE_DIRECTORY__ @@ "docsTool" -let docsToolProj = docsToolDir @@ "docsTool.fsproj" -let docsSrcGlob = docsSrcDir @@ "**/*.fsx" +let docsDir = __SOURCE_DIRECTORY__ ".." "docs" +let docsSrcDir = __SOURCE_DIRECTORY__ ".." "docsSrc" +let docsToolDir = __SOURCE_DIRECTORY__ ".." "docsTool" +let docsToolProj = docsToolDir "docsTool.fsproj" +let docsSrcGlob = docsSrcDir "**/*.fsx" let gitOwner = "TheAngryByrd" let gitRepoName = "MiniScaffold" -let contentDir = __SOURCE_DIRECTORY__ @@ "Content" +let contentDir = __SOURCE_DIRECTORY__ ".." "Content" + let tagFromVersionNumber versionNumber = sprintf "%s" versionNumber -let changelogFilename = "CHANGELOG.md" +let changelogFilename = __SOURCE_DIRECTORY__ ".." "CHANGELOG.md" let changelog = Fake.Core.Changelog.load changelogFilename let mutable latestEntry = if Seq.isEmpty changelog.Entries @@ -61,13 +50,8 @@ let docsSiteBaseUrl = "https://www.jimmybyrd.me/MiniScaffold" let isCI = Environment.environVarAsBool "CI" - let githubToken = Environment.environVarOrNone "GITHUB_TOKEN" -Option.iter(TraceSecrets.register "" ) - - let nugetToken = Environment.environVarOrNone "NUGET_TOKEN" -Option.iter(TraceSecrets.register "") //----------------------------------------------------------------------------- // Helpers @@ -453,53 +437,75 @@ let ``release docs`` ctx = // If we're calling "Release" target, we'll let the "GitRelease" target do the git push Git.Branches.push "" +let initTargets () = + BuildServer.install [ + GitHubActions.Installer + ] + /// Defines a dependency - y is dependent on x + let (==>!) x y = x ==> y |> ignore + /// Defines a soft dependency. x must run before y, if it is present, but y does not require x to be run. + let (?=>!) x y = x ?=> y |> ignore //----------------------------------------------------------------------------- -// Target Declaration +// Hide Secrets in Logger //----------------------------------------------------------------------------- - -Target.create "Clean" clean -Target.create "DotnetRestore" ``dotnet restore`` -Target.create "UpdateChangelog" ``update changelog`` -Target.createBuildFailure "RevertChangelog" ``revert changelog`` // Do NOT put this in the dependency chain -Target.createFinal "DeleteChangelogBackupFile" ``delete changelogBackupFile`` // Do NOT put this in the dependency chain -Target.create "DotnetPack" ``dotnet pack`` -Target.create "IntegrationTests" ``integration tests`` -Target.create "PublishToNuGet" publish -Target.create "GitRelease" ``git release`` -Target.create "GitHubRelease" ``github release`` -Target.create "Release" ignore -Target.create "BuildDocs" ``build docs`` -Target.create "WatchDocs" ``watch docs`` -Target.create "ReleaseDocs" ``release docs`` - + Option.iter(TraceSecrets.register "" ) githubToken + Option.iter(TraceSecrets.register "") nugetToken //----------------------------------------------------------------------------- -// Target Dependencies +// Target Declaration //----------------------------------------------------------------------------- -"DotnetPack" ==> "BuildDocs" -"BuildDocs" ==> "ReleaseDocs" -"BuildDocs" ?=> "PublishToNuGet" -"IntegrationTests" ?=> "ReleaseDocs" -"ReleaseDocs" ?=> "GitRelease" -"ReleaseDocs" ==> "Release" - -// Only call UpdateChangelog if Publish was in the call chain -// Ensure UpdateChangelog is called after DotnetRestore and before GenerateAssemblyInfo -"DotnetRestore" ?=> "UpdateChangelog" -"UpdateChangelog" ?=> "DotnetPack" -"UpdateChangelog" ==> "PublishToNuGet" - -"Clean" - ==> "DotnetRestore" - ==> "DotnetPack" -//https://github.com/dotnet/templating/issues/1736#issuecomment-464847242 - =?> ("IntegrationTests", isCI) - ==> "PublishToNuGet" - ==> "GitRelease" - ==> "GithubRelease" - ==> "Release" + Target.create "Clean" clean + Target.create "DotnetRestore" ``dotnet restore`` + Target.create "UpdateChangelog" ``update changelog`` + Target.createBuildFailure "RevertChangelog" ``revert changelog`` // Do NOT put this in the dependency chain + Target.createFinal "DeleteChangelogBackupFile" ``delete changelogBackupFile`` // Do NOT put this in the dependency chain + Target.create "DotnetPack" ``dotnet pack`` + Target.create "IntegrationTests" ``integration tests`` + Target.create "PublishToNuGet" publish + Target.create "GitRelease" ``git release`` + Target.create "GitHubRelease" ``github release`` + Target.create "Release" ignore + Target.create "BuildDocs" ``build docs`` + Target.create "WatchDocs" ``watch docs`` + Target.create "ReleaseDocs" ``release docs`` + + //----------------------------------------------------------------------------- + // Target Dependencies + //----------------------------------------------------------------------------- + "DotnetPack" ==>! "BuildDocs" + "BuildDocs" ==>! "ReleaseDocs" + "BuildDocs" ?=>! "PublishToNuGet" + "IntegrationTests" ?=>! "ReleaseDocs" + "ReleaseDocs" ?=>! "GitRelease" + "ReleaseDocs" ==>! "Release" + + // Only call UpdateChangelog if Publish was in the call chain + // Ensure UpdateChangelog is called after DotnetRestore and before GenerateAssemblyInfo + "DotnetRestore" ?=>! "UpdateChangelog" + "UpdateChangelog" ?=>! "DotnetPack" + "UpdateChangelog" ==>! "PublishToNuGet" + + "Clean" + ==> "DotnetRestore" + ==> "DotnetPack" + =?> ("IntegrationTests", isCI) + ==> "PublishToNuGet" + ==> "GitRelease" + ==> "GithubRelease" + ==>! "Release" //----------------------------------------------------------------------------- // Target Start //----------------------------------------------------------------------------- -Target.runOrDefaultWithArguments (if isCI then "IntegrationTests" else "DotnetPack") + +[] +let main argv = + argv + |> Array.toList + |> Context.FakeExecutionContext.Create false "build.fsx" + |> Context.RuntimeContext.Fake + |> Context.setExecutionContext + initTargets () + Target.runOrDefaultWithArguments (if isCI then "IntegrationTests" else "DotnetPack") + + 0 // return an integer exit code diff --git a/build/build.fsproj b/build/build.fsproj new file mode 100644 index 00000000..44d3df83 --- /dev/null +++ b/build/build.fsproj @@ -0,0 +1,14 @@ + + + + Exe + net5.0 + 3390;$(WarnOn) + + + + + + + + diff --git a/build/paket.references b/build/paket.references new file mode 100644 index 00000000..3c5f5230 --- /dev/null +++ b/build/paket.references @@ -0,0 +1,17 @@ +group Build +FSharp.Core +YoloDev.Expecto.TestSdk +Microsoft.NET.Test.Sdk +Fake.IO.FileSystem +Fake.Core.Target +Fake.Core.ReleaseNotes +FAKE.Core.Environment +Fake.DotNet.Cli +FAKE.Core.Process +Fake.DotNet.AssemblyInfoFile +Fake.Tools.Git +Fake.DotNet.Paket +Fake.Api.GitHub +Fake.BuildServer.GitHubActions +Argu +Octokit