Skip to content

Commit

Permalink
add build project
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jul 21, 2023
1 parent 971aa55 commit fbcc358
Show file tree
Hide file tree
Showing 14 changed files with 491 additions and 11 deletions.
45 changes: 35 additions & 10 deletions FsOboParser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,53 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsOboParser", "src\FsOboParser\FsOboParser.fsproj", "{7812F4E0-128E-437C-92CF-84C9F621C459}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BC99056C-0431-4FBE-8396-DAB1FFFF2A8F}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsOboParser.Tests", "tests\FsOboParser.Tests\FsOboParser.Tests.fsproj", "{AADEED8F-ABA6-4401-978E-B80CBC9589BC}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{A989E8E9-BC2B-4E53-97EC-FE0E9ED342F9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{5FA53C60-C472-4A99-A3F7-8098B4606CBE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{13CB1D92-20F8-4489-9C1A-F06DDFCF3C37}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
global.json = global.json
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "build", "build\build.fsproj", "{4A02631E-8D3F-4130-8545-C0B7A7424B90}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FsOboParser", "src\FsOboParser\FsOboParser.fsproj", "{9B04A234-E7AC-4960-99A2-3E1B7B05F32A}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FsOboParser.Tests", "tests\FsOboParser.Tests\FsOboParser.Tests.fsproj", "{0A4EF63F-C659-4AB6-AF88-CB444A98C434}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7812F4E0-128E-437C-92CF-84C9F621C459}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7812F4E0-128E-437C-92CF-84C9F621C459}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7812F4E0-128E-437C-92CF-84C9F621C459}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7812F4E0-128E-437C-92CF-84C9F621C459}.Release|Any CPU.Build.0 = Release|Any CPU
{AADEED8F-ABA6-4401-978E-B80CBC9589BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AADEED8F-ABA6-4401-978E-B80CBC9589BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AADEED8F-ABA6-4401-978E-B80CBC9589BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AADEED8F-ABA6-4401-978E-B80CBC9589BC}.Release|Any CPU.Build.0 = Release|Any CPU
{4A02631E-8D3F-4130-8545-C0B7A7424B90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A02631E-8D3F-4130-8545-C0B7A7424B90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A02631E-8D3F-4130-8545-C0B7A7424B90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A02631E-8D3F-4130-8545-C0B7A7424B90}.Release|Any CPU.Build.0 = Release|Any CPU
{9B04A234-E7AC-4960-99A2-3E1B7B05F32A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B04A234-E7AC-4960-99A2-3E1B7B05F32A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B04A234-E7AC-4960-99A2-3E1B7B05F32A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B04A234-E7AC-4960-99A2-3E1B7B05F32A}.Release|Any CPU.Build.0 = Release|Any CPU
{0A4EF63F-C659-4AB6-AF88-CB444A98C434}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A4EF63F-C659-4AB6-AF88-CB444A98C434}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A4EF63F-C659-4AB6-AF88-CB444A98C434}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A4EF63F-C659-4AB6-AF88-CB444A98C434}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4A02631E-8D3F-4130-8545-C0B7A7424B90} = {5FA53C60-C472-4A99-A3F7-8098B4606CBE}
{9B04A234-E7AC-4960-99A2-3E1B7B05F32A} = {BC99056C-0431-4FBE-8396-DAB1FFFF2A8F}
{0A4EF63F-C659-4AB6-AF88-CB444A98C434} = {A989E8E9-BC2B-4E53-97EC-FE0E9ED342F9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {54B9E6DB-7B93-4B11-AF6D-F46EF21F9781}
EndGlobalSection
Expand Down
30 changes: 30 additions & 0 deletions build/BasicTasks.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module BasicTasks

open BlackFox.Fake
open Fake.IO
open Fake.DotNet
open Fake.IO.Globbing.Operators

open ProjectInfo

let setPrereleaseTag = BuildTask.create "SetPrereleaseTag" [] {
printfn "Please enter pre-release package suffix"
let suffix = System.Console.ReadLine()
prereleaseSuffix <- suffix
prereleaseTag <- (sprintf "%s-%s" release.NugetVersion suffix)
isPrerelease <- true
}

let clean = BuildTask.create "Clean" [] {
!! "src/**/bin"
++ "src/**/obj"
++ "tests/**/bin"
++ "tests/**/obj"
++ "pkg"
|> Shell.cleanDirs
}

let build = BuildTask.create "Build" [clean] {
solutionFile
|> DotNet.build id
}
46 changes: 46 additions & 0 deletions build/Build.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
open BlackFox.Fake
open System.IO
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Tools

open Helpers

initializeContext()

open BasicTasks
open TestTasks
open PackageTasks
open DocumentationTasks
open ReleaseTasks

/// Full release of nuget package, git tag, and documentation for the stable version.
let _release =
BuildTask.createEmpty
"Release"
[clean; build; runTests; pack; buildDocs; createTag; publishNuget; releaseDocs]

/// Full release of nuget package, git tag, and documentation for the prerelease version.
let _preRelease =
BuildTask.createEmpty
"PreRelease"
[setPrereleaseTag; clean; build; runTests; packPrerelease; buildDocsPrerelease; createPrereleaseTag; publishNugetPrerelease; prereleaseDocs]

/// Full release of nuget package for the prerelease version.
let _releaseNoDocs =
BuildTask.createEmpty
"ReleaseNoDocs"
[clean; build; runTests; pack; createTag; publishNuget;]

/// Full release of nuget package for the prerelease version.
let _preReleaseNoDocs =
BuildTask.createEmpty
"PreReleaseNoDocs"
[setPrereleaseTag; clean; build; runTests; packPrerelease; createPrereleaseTag; publishNugetPrerelease]

[<EntryPoint>]
let main args =
runOrDefault build args
35 changes: 35 additions & 0 deletions build/DocumentationTasks.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module DocumentationTasks

open Helpers
open ProjectInfo
open BasicTasks

open BlackFox.Fake

let buildDocs = BuildTask.create "BuildDocs" [build] {
printfn "building docs with stable version %s" stableVersionTag
runDotNet
(sprintf "fsdocs build --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s" stableVersionTag)
"./"
}

let buildDocsPrerelease = BuildTask.create "BuildDocsPrerelease" [setPrereleaseTag; build] {
printfn "building docs with prerelease version %s" prereleaseTag
runDotNet
(sprintf "fsdocs build --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s" prereleaseTag)
"./"
}

let watchDocs = BuildTask.create "WatchDocs" [build] {
printfn "watching docs with stable version %s" stableVersionTag
runDotNet
(sprintf "fsdocs watch --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s" stableVersionTag)
"./"
}

let watchDocsPrerelease = BuildTask.create "WatchDocsPrerelease" [setPrereleaseTag; build] {
printfn "watching docs with prerelease version %s" prereleaseTag
runDotNet
(sprintf "fsdocs watch --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s" prereleaseTag)
"./"
}
28 changes: 28 additions & 0 deletions build/Helpers.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Helpers

open BlackFox.Fake
open Fake.Core
open Fake.DotNet

let initializeContext () =
let execContext = Context.FakeExecutionContext.Create false "build.fsx" [ ]
Context.setExecutionContext (Context.RuntimeContext.Fake execContext)

/// Executes a dotnet command in the given working directory
let runDotNet cmd workingDir =
let result =
DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir

let runOrDefault defaultTarget args =
Trace.trace (sprintf "%A" args)
try
match args with
| [| target |] -> Target.runOrDefault target
| arr when args.Length > 1 ->
Target.run 0 (Array.head arr) ( Array.tail arr |> List.ofArray )
| _ -> BuildTask.runOrDefault defaultTarget
0
with e ->
printfn "%A" e
1
18 changes: 18 additions & 0 deletions build/MessagePrompts.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module MessagePrompts

let prompt (msg:string) =
System.Console.Write(msg)
System.Console.ReadLine().Trim()
|> function | "" -> None | s -> Some s
|> Option.map (fun s -> s.Replace ("\"","\\\""))

let rec promptYesNo msg =
match prompt (sprintf "%s [Yn]: " msg) with
| Some "Y" | Some "y" -> true
| Some "N" | Some "n" -> false
| _ -> System.Console.WriteLine("Sorry, invalid answer"); promptYesNo msg

let releaseMsg = """This will stage all uncommitted changes, push them to the origin and bump the release version to the latest number in the RELEASE_NOTES.md file.
Do you want to continue?"""

let releaseDocsMsg = """This will push the docs to gh-pages. Remember building the docs prior to this. Do you want to continue?"""
64 changes: 64 additions & 0 deletions build/PackageTasks.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module PackageTasks

open ProjectInfo

open MessagePrompts
open BasicTasks
open TestTasks

open BlackFox.Fake
open Fake.Core
open Fake.IO.Globbing.Operators

open System.Text.RegularExpressions

/// https://github.com/Freymaurer/Fake.Extensions.Release#release-notes-in-nuget
let private replaceCommitLink input =
let commitLinkPattern = @"\[\[#[a-z0-9]*\]\(.*\)\] "
Regex.Replace(input,commitLinkPattern,"")

let pack = BuildTask.create "Pack" [clean; build; runTests] {
if promptYesNo (sprintf "creating stable package with version %s OK?" stableVersionTag )
then
!! "src/**/*.*proj"
-- "src/bin/*"
|> Seq.iter (Fake.DotNet.DotNet.pack (fun p ->
let msBuildParams =
{p.MSBuildParams with
Properties = ([
"Version",stableVersionTag
"PackageReleaseNotes", (release.Notes |> List.map replaceCommitLink |> String.concat "\r\n" )
] @ p.MSBuildParams.Properties)
}
{
p with
MSBuildParams = msBuildParams
OutputPath = Some pkgDir
}
))
else failwith "aborted"
}

let packPrerelease = BuildTask.create "PackPrerelease" [setPrereleaseTag; clean; build; runTests] {
if promptYesNo (sprintf "package tag will be %s OK?" prereleaseTag )
then
!! "src/**/*.*proj"
-- "src/bin/*"
|> Seq.iter (Fake.DotNet.DotNet.pack (fun p ->
let msBuildParams =
{p.MSBuildParams with
Properties = ([
"Version", prereleaseTag
"PackageReleaseNotes", (release.Notes |> List.map replaceCommitLink |> String.toLines )
] @ p.MSBuildParams.Properties)
}
{
p with
VersionSuffix = Some prereleaseSuffix
OutputPath = Some pkgDir
MSBuildParams = msBuildParams
}
))
else
failwith "aborted"
}
37 changes: 37 additions & 0 deletions build/ProjectInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module ProjectInfo

open Fake.Core

let project = "FsOboParser"

let testProjects =
[
// add relative paths (from project root) to your testprojects here
]

let solutionFile = $"{project}.sln"

let configuration = "Release"

let gitOwner = "CSBiology"

let gitHome = $"https://github.com/{gitOwner}"

let projectRepo = $"https://github.com/{gitOwner}/{project}"

let pkgDir = "pkg"

// Create RELEASE_NOTES.md if not existing. Or "release" would throw an error.
Fake.Extensions.Release.ReleaseNotes.ensure()

let release = ReleaseNotes.load "RELEASE_NOTES.md"

let stableVersion = SemVer.parse release.NugetVersion

let stableVersionTag = (sprintf "%i.%i.%i" stableVersion.Major stableVersion.Minor stableVersion.Patch )

let mutable prereleaseSuffix = ""

let mutable prereleaseTag = ""

let mutable isPrerelease = false
29 changes: 29 additions & 0 deletions build/ReleaseNotesTasks.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module ReleaseNotesTasks

open Fake.Extensions.Release
open BlackFox.Fake

/// This might not be necessary, mostly useful for apps which want to display current version as it creates an accessible F# version script from RELEASE_NOTES.md
let createAssemblyVersion = BuildTask.create "createvfs" [] {
AssemblyVersion.create ProjectInfo.project
}

// https://github.com/Freymaurer/Fake.Extensions.Release#releaseupdate
let updateReleaseNotes = BuildTask.createFn "ReleaseNotes" [] (fun config ->
ReleaseNotes.update(ProjectInfo.gitOwner, ProjectInfo.project, config)
)


// https://github.com/Freymaurer/Fake.Extensions.Release#githubdraft
let githubDraft = BuildTask.createFn "GithubDraft" [] (fun config ->

let body = "We are ready to go for the first release!"

Github.draft(
ProjectInfo.gitOwner,
ProjectInfo.project,
(Some body),
None,
config
)
)
Loading

0 comments on commit fbcc358

Please sign in to comment.