From 852e7ad4b3e23f496857d89ecee03187ff2fade4 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 30 Oct 2018 19:28:20 -0400 Subject: [PATCH] A bunch of stuff --- Build.fsx | 113 ++++++++++++++++++++++++++++++++++++++--- GitVersion.yml | 1 - appveyor.yml | 32 +----------- paket.dependencies | 2 + src/BCC.Submission.sln | 1 + 5 files changed, 112 insertions(+), 37 deletions(-) diff --git a/Build.fsx b/Build.fsx index e8793f9..d116caa 100644 --- a/Build.fsx +++ b/Build.fsx @@ -8,6 +8,8 @@ open Fake.DotNet open Fake.DotNet.NuGet open Fake.Core open Fake.Tools +open Fake.Api +open Fake.Windows BuildServer.install [ AppVeyor.Installer @@ -73,13 +75,8 @@ Target.create "Package" (fun _ -> Shell.copyRecursive "src/BCC.Submission/bin/Release" "nuget/tools" false |> ignore - let version = - match String.isNullOrWhiteSpace gitVersion.PreReleaseLabel with - | false -> sprintf "%s-%s%s" gitVersion.MajorMinorPatch gitVersion.PreReleaseLabel gitVersion.BuildMetaDataPadded - | _ -> sprintf "%s" gitVersion.MajorMinorPatch - NuGet.NuGetPack (fun p -> { p with - Version = version + Version = gitVersion.NuGetVersionV2 OutputPath = "nuget" }) "nuget/Package.nuspec" !! "nuget/*.nupkg" @@ -108,6 +105,104 @@ Target.create "Coverage" (fun _ -> ) ) +Target.create "DeployGitHub" (fun _ -> + let gitHubToken = Environment.environVarOrNone("GITHUB_TOKEN") + if(gitHubToken.IsNone) then + Trace.traceError "GITHUB_TOKEN is not defined" + else + let (gitOwner, gitName) = + AppVeyor.Environment.RepoName.Split('/') + |> Array.pairwise + |> Array.head + + let repoTagName = AppVeyor.Environment.RepoTagName + let projectName = AppVeyor.Environment.ProjectName + + GitHub.createClientWithToken gitHubToken.Value + |> (fun clientAsync -> + async { + let! client = clientAsync + let releaseClient = client.Repository.Release + + let! someRelease = async { + let! exc = Async.Catch(async { + let! str = Async.AwaitTask (releaseClient.Get(gitOwner, gitName, repoTagName)) + return str }) + + match exc with + | Choice1Of2 r -> return Some r + | Choice2Of2 _ -> return None + } + + match someRelease with + | Some release -> Trace.traceErrorfn "Release '%s' @ '%s' already exists" release.Name repoTagName + | _ -> + let isPrerelease = not(String.isNullOrWhiteSpace gitVersion.PreReleaseTag) + let releaseName = sprintf "%s - v%s" projectName gitVersion.SemVer + let releaseBody = sprintf "## %s" releaseName + + let newRelease = new Octokit.NewRelease(repoTagName); + newRelease.Name <- releaseName + newRelease.Body <- releaseBody + newRelease.Draft <- true + newRelease.Prerelease <- isPrerelease + + let! release = releaseClient.Create(gitOwner, gitName, newRelease) |> Async.AwaitTask + + let release : GitHub.Release = { + Client = client; + Owner = gitOwner; + RepoName = gitName; + Release = release + } + + let files = !! "nuget/*.nupkg" + + release + |> async.Return + |> GitHub.uploadFiles files + |> GitHub.publishDraft + |> Async.RunSynchronously + + Trace.traceImportantfn "Created Release: '%s' @ '%s'" releaseName repoTagName + } + ) + |> Async.Catch + |> Async.RunSynchronously + |> ignore +) + +Target.create "DeployNuGet" (fun _ -> + let nugetApiKey = Environment.environVarOrNone("NUGET_API_KEY") + if (nugetApiKey.IsNone) then + Trace.traceError "NUGET_API_KEY is not defined" + else + try + NuGet.NuGetPublish (fun p -> { p with + AccessKey = nugetApiKey.Value + Project = "BCC-Submission" + Version = gitVersion.NuGetVersionV2 + WorkingDir = "nuget" }) + + Trace.traceImportant "Uploaded NuGet Package" + with ex -> + Trace.traceError "Unable to create NuGet Package" + Trace.traceException ex +) + +Target.create "DeployChocolatey" (fun _ -> + let chocoApiKey = Environment.environVarOrNone("CHOCO_API_KEY") + if (chocoApiKey.IsNone) then + Trace.traceError "CHOCO_API_KEY is not defined" + else + try + !! "nuget/*.nupkg" + |> Seq.iter (Choco.push (fun p -> { p with ApiKey = chocoApiKey.Value })) + with ex -> + Trace.traceError "Unable to create Chocolatey Package" + Trace.traceException ex +) + Target.create "Default" (fun _ -> ()) open Fake.Core.TargetOperators @@ -117,5 +212,11 @@ open Fake.Core.TargetOperators "Build" ==> "Test" ==> "Default" "Build" ==> "Coverage" ==> "Default" +let shouldDeploy = isAppveyor && AppVeyor.Environment.RepoTag + +"Package" =?> ("DeployGitHub", (shouldDeploy)) ==> "Default" +"Package" =?> ("DeployNuGet", (shouldDeploy)) ==> "Default" +"Package" =?> ("DeployChocolatey", (shouldDeploy)) ==> "Default" + // start build Target.runOrDefault "Default" diff --git a/GitVersion.yml b/GitVersion.yml index 556ffdf..6f7a2b6 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,4 +1,3 @@ -next-version: 1.0.0 branches: {} ignore: sha: [] diff --git a/appveyor.yml b/appveyor.yml index 48c93cd..4b77a8a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,33 +9,5 @@ before_build: - ps: gitversion /output buildserver build_script: - ps: >- - fake run Build.fsx -test: off -deploy: -- provider: NuGet - artifact: /.*\.nupkg/ - api_key: - secure: dsO76Gkjz0FIjFDUQgSK5k04J5Kx+tBfpUVPA/YNOcvQN8dzfLfuoT+qmu4ezU2c - on: - branch: master - appveyor_repo_tag: true -- provider: NuGet - artifact: /.*\.nupkg/ - server: https://chocolatey.org - api_key: - secure: WZYV1tc0xOaBu8I7KqifSysQu+E9nhtlodRlCwCXCiEGFYELc0evoeUBQc2y4iZq - on: - branch: master - appveyor_repo_tag: true -- provider: GitHub - tag: $(APPVEYOR_REPO_TAG_NAME) - release: BCC-Submission v$(GitVersion_SemVer) - description: 'BCC-Submission v$(GitVersion_SemVer)' - auth_token: - secure: 8wLI8hf2W3L/V5BUk/tdGDs+gWryh9Y8HxCQk9iq48xV/n+hxShodChwuHAm2DsS - artifact: /.*\.nupkg/ - draft: false - prerelease: false - on: - branch: master - appveyor_repo_tag: true \ No newline at end of file + fake run Build.fsx -p 3 +test: off \ No newline at end of file diff --git a/paket.dependencies b/paket.dependencies index 562ec65..ca821c2 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -13,6 +13,8 @@ group FakeBuild nuget Fake.DotNet.NuGet nuget Fake.IO.FileSystem nuget Fake.Tools.GitVersion + nuget Fake.Api.GitHub + nuget Fake.Windows.Chocolatey groupref FakeBuildResources group FakeBuildResources diff --git a/src/BCC.Submission.sln b/src/BCC.Submission.sln index 68878b9..6664a3c 100644 --- a/src/BCC.Submission.sln +++ b/src/BCC.Submission.sln @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{E3F58818 ..\appveyor.yml = ..\appveyor.yml ..\Build.fsx = ..\Build.fsx ..\codecov.yml = ..\codecov.yml + ..\GitVersion.yml = ..\GitVersion.yml ..\nuget\Package.nuspec = ..\nuget\Package.nuspec ..\paket.dependencies = ..\paket.dependencies EndProjectSection