Skip to content
This repository has been archived by the owner on Jun 17, 2019. It is now read-only.

Commit

Permalink
A bunch of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
StanleyGoldman committed Oct 30, 2018
1 parent 4706e3b commit 852e7ad
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 37 deletions.
113 changes: 107 additions & 6 deletions Build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
1 change: 0 additions & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
next-version: 1.0.0
branches: {}
ignore:
sha: []
32 changes: 2 additions & 30 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
fake run Build.fsx -p 3
test: off
2 changes: 2 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/BCC.Submission.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 852e7ad

Please sign in to comment.