Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sourcelink Tests and many cleanups #69

Merged
merged 9 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Make sure the following **requirements** are installed in your system:
$ ./build.sh // on unix
```

#### Environment Variables

* `CONFIGURATION` will set the [configuration](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build?tabs=netcore2x#options) of the dotnet commands. If not set it will default to Release.

`CONFIGURATION=Debug ./build.sh` will result in things like `dotnet build -c Debug`


### Watch Tests

Expand Down
89 changes: 56 additions & 33 deletions Content/build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ open Fake.ReleaseNotesHelper
open Fake.UserInputHelper
open System




let release = LoadReleaseNotes "RELEASE_NOTES.md"
let productName = "MyLib"
let sln = "MyLib.sln"
let srcGlob = "src/**/*.fsproj"
let testsGlob = "tests/**/*.fsproj"
let srcGlob =__SOURCE_DIRECTORY__ @@ "src/**/*.??proj"
let testsGlob = __SOURCE_DIRECTORY__ @@ "tests/**/*.??proj"
let distDir = __SOURCE_DIRECTORY__ @@ "dist"
let distGlob = distDir @@ "*.nupkg"
let toolsDir = __SOURCE_DIRECTORY__ @@ "tools"

let configuration =
EnvironmentHelper.environVarOrDefault "CONFIGURATION" "Release"


let isRelease () =
Fake.TargetHelper.CurrentTargetOrder
|> Seq.collect id
|> Seq.exists ((=)"Release")

Target "Clean" (fun _ ->
["bin"; "temp" ;"dist"]
["bin"; "temp" ; distDir]
|> CleanDirs

!! srcGlob
Expand All @@ -31,21 +40,26 @@ Target "Clean" (fun _ ->
)

Target "DotnetRestore" (fun _ ->
DotNetCli.Restore (fun c ->
{ c with
Project = sln
//This makes sure that Proj2 references the correct version of Proj1
AdditionalArgs = [sprintf "/p:PackageVersion=%s" release.NugetVersion]
}))
[sln ; toolsDir]
|> Seq.iter(fun dir ->
DotNetCli.Restore (fun c ->
{ c with
Project = dir
//This makes sure that Proj2 references the correct version of Proj1
AdditionalArgs = [sprintf "/p:PackageVersion=%s" release.NugetVersion]
}))
)

Target "DotnetBuild" (fun _ ->
DotNetCli.Build (fun c ->
{ c with
Project = sln
Configuration = configuration
//This makes sure that Proj2 references the correct version of Proj1
AdditionalArgs =
[
sprintf "/p:PackageVersion=%s" release.NugetVersion
sprintf "/p:SourceLinkCreate=%b" (isRelease ())
"--no-restore"
]
}))
Expand Down Expand Up @@ -74,12 +88,12 @@ let getTargetFrameworksFromProjectFile (projFile : string)=
|> Seq.toList

let selectRunnerForFramework tf =
let runMono = sprintf "mono -f %s -c Release --loggerlevel Warn"
let runCore = sprintf "run -f %s -c Release"
let runMono = sprintf "mono -f %s -c %s --loggerlevel Warn"
let runCore = sprintf "run -f %s -c %s"
match tf with
| Full t when isMono-> runMono t
| Full t -> runCore t
| Core t -> runCore t
| Full t when isMono-> runMono t configuration
| Full t -> runCore t configuration
| Core t -> runCore t configuration

let addLogNameParamToArgs tf args =
let frameworkName =
Expand Down Expand Up @@ -145,7 +159,6 @@ Target "AssemblyInfo" (fun _ ->
let getAssemblyInfoAttributes projectName =
[ Attribute.Title (projectName)
Attribute.Product productName
// Attribute.Description summary
Attribute.Version release.AssemblyVersion
Attribute.Metadata("ReleaseDate", release.Date.Value.ToString("o"))
Attribute.FileVersion release.AssemblyVersion
Expand All @@ -162,8 +175,8 @@ Target "AssemblyInfo" (fun _ ->
(getAssemblyInfoAttributes projectName)
)

!! "src/**/*.??proj"
++ "tests/**/*.??proj"
!! srcGlob
++ testsGlob
|> Seq.map getProjectDetails
|> Seq.iter (fun (projFileName, projectName, folderName, attributes) ->
match projFileName with
Expand All @@ -175,32 +188,39 @@ Target "AssemblyInfo" (fun _ ->
)

Target "DotnetPack" (fun _ ->
// https://github.com/ctaggart/SourceLink relies on a some git depedencies.
// Checks if there's a remote.origin.url and the last git hash.
let remoteOriginOk, remoteMessages, _ = Git.CommandHelper.runGitCommand "." "config --get remote.origin.url"
let sha1Ok, sha1Message, _ = Git.CommandHelper.runGitCommand "." "rev-parse HEAD"
let canSourceLink =
remoteOriginOk && (remoteMessages |> Seq.length > 0)
&& sha1Ok && (sha1Message |> Seq.length > 0)

!! srcGlob
|> Seq.iter (fun proj ->
DotNetCli.Pack (fun c ->
{ c with
Project = proj
Configuration = "Release"
OutputPath = IO.Directory.GetCurrentDirectory() @@ "dist"
Configuration = configuration
OutputPath = distDir
AdditionalArgs =
[
sprintf "/p:PackageVersion=%s" release.NugetVersion
sprintf "/p:PackageReleaseNotes=\"%s\"" (String.Join("\n",release.Notes))
sprintf "/p:SourceLinkCreate=%b" canSourceLink
sprintf "/p:SourceLinkCreate=%b" (isRelease ())
]
})
)
)

Target "SourcelinkTest" (fun _ ->
!! distGlob
|> Seq.iter (fun nupkg ->
DotNetCli.RunCommand
(fun p -> { p with WorkingDir = toolsDir} )
(sprintf "sourcelink test %s" nupkg)
)
)

let isReleaseBranchCheck () =
let releaseBranch = "master"
if Git.Information.getBranchName "" <> releaseBranch then failwithf "Not on %s. If you want to release please switch to this branch." releaseBranch

Target "Publish" (fun _ ->
isReleaseBranchCheck ()

Paket.Push(fun c ->
{ c with
PublishUrl = "https://www.nuget.org"
Expand All @@ -209,8 +229,8 @@ Target "Publish" (fun _ ->
)
)

Target "Release" (fun _ ->
if Git.Information.getBranchName "" <> "master" then failwith "Not on master"
Target "GitRelease" (fun _ ->
isReleaseBranchCheck ()

let releaseNotesGitCommitFormat = ("",release.Notes |> Seq.map(sprintf "* %s\n")) |> String.Join

Expand All @@ -222,6 +242,7 @@ Target "Release" (fun _ ->
Branches.pushTag "" "origin" release.NugetVersion
)

Target "Release" DoNothing


// Only call Clean if DotnetPack was in the call chain
Expand All @@ -239,7 +260,9 @@ Target "Release" (fun _ ->
==> "DotnetBuild"
==> "DotnetTest"
==> "DotnetPack"
==> "SourcelinkTest"
==> "Publish"
==> "GitRelease"
==> "Release"

"DotnetRestore"
Expand Down
4 changes: 3 additions & 1 deletion Content/paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ source https://www.nuget.org/api/v2
storage: none
clitool dotnet-mono 0.5.1
clitool Microsoft.DotNet.Watcher.Tools 1.0.0
clitool dotnet-sourcelink 2.8.0
nuget Argu 3.7
nuget FSharp.Core 4.3.3
nuget Expecto 6.0.0
nuget SourceLink.Create.CommandLine 2.7.2 copy_local: true
nuget SourceLink.Create.CommandLine 2.8.0 copy_local: true


group Build
source https://www.nuget.org/api/v2
Expand Down
Loading