Skip to content

Commit

Permalink
Moves main build script to use dotnet as runner instead of fake-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Sep 9, 2021
1 parent 969c1f7 commit 7b4424a
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 85 deletions.
24 changes: 9 additions & 15 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
}
14 changes: 14 additions & 0 deletions MiniScaffold.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion build.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
echo Restoring dotnet tools...
dotnet tool restore

dotnet fake build -t %*
dotnet run -p ./build/build.fsproj -- -t %*
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
142 changes: 74 additions & 68 deletions build.fsx → build/build.fs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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 "<GITHUB_TOKEN>" )


let nugetToken = Environment.environVarOrNone "NUGET_TOKEN"
Option.iter(TraceSecrets.register "<NUGET_TOKEN>")

//-----------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -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 "<GITHUB_TOKEN>" ) githubToken
Option.iter(TraceSecrets.register "<NUGET_TOKEN>") 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")

[<EntryPoint>]
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
14 changes: 14 additions & 0 deletions build/build.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<WarnOn>3390;$(WarnOn)</WarnOn>
</PropertyGroup>
<ItemGroup>

<Compile Include="../docsTool/CLI.fs" Link="CLI.fs" />
<Compile Include="build.fs" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
17 changes: 17 additions & 0 deletions build/paket.references
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7b4424a

Please sign in to comment.