From 25715da15575e049db6b2ae65f9f937f141f1b59 Mon Sep 17 00:00:00 2001 From: Naveen Date: Thu, 8 Oct 2015 21:05:45 -0400 Subject: [PATCH 1/2] Bump version to 0.17.0 --- Octokit.fsx | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ deploy.cmd | 13 +++++++++ deploy.fsx | 57 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 Octokit.fsx create mode 100644 deploy.cmd create mode 100644 deploy.fsx diff --git a/Octokit.fsx b/Octokit.fsx new file mode 100644 index 0000000000..bc6719a458 --- /dev/null +++ b/Octokit.fsx @@ -0,0 +1,80 @@ +#I __SOURCE_DIRECTORY__ +#r "./Octokit/bin/Release/Net45/Octokit.dll" + +open Octokit +open System +open System.IO + +type Draft = + { Client : GitHubClient + Owner : string + Project : string + DraftRelease : Release } + +let private isRunningOnMono = System.Type.GetType ("Mono.Runtime") <> null + +let rec private retry count asyncF = + // This retry logic causes an exception on Mono: + // https://github.com/fsharp/fsharp/issues/440 + if isRunningOnMono then + asyncF + else + async { + try + return! asyncF + with _ when count > 0 -> return! retry (count - 1) asyncF + } + +let createClient user password = + async { + let github = new GitHubClient(new ProductHeaderValue("Octokit")) + github.Credentials <- Credentials(user, password) + return github + } + +let createClientWithToken token = + async { + let github = new GitHubClient(new ProductHeaderValue("Octokit")) + github.Credentials <- Credentials(token) + return github + } + +let private makeRelease draft owner project version prerelease (notes:seq) (client : Async) = + async { + let data = new NewRelease(version) + data.Name <- version + data.Body <- String.Join(Environment.NewLine, notes) + data.Draft <- draft + data.Prerelease <- prerelease + let! client' = client + let! draft = Async.AwaitTask <| client'.Release.Create(owner, project, data) + let draftWord = if data.Draft then " draft" else "" + printfn "Created%s release id %d" draftWord draft.Id + return { Client = client' + Owner = owner + Project = project + DraftRelease = draft } + } |> retry 5 + +let createDraft owner project version prerelease notes client = makeRelease true owner project version prerelease notes client +let createRelease owner project version prerelease notes client = makeRelease false owner project version prerelease notes client + +let uploadFile fileName (draft : Async) = + async { + let fi = FileInfo(fileName) + let archiveContents = File.OpenRead(fi.FullName) + let assetUpload = new ReleaseAssetUpload(fi.Name,"application/octet-stream",archiveContents,Nullable()) + let! draft' = draft + let! asset = Async.AwaitTask <| draft'.Client.Release.UploadAsset(draft'.DraftRelease, assetUpload) + printfn "Uploaded %s" asset.Name + return draft' + } |> retry 5 + +let releaseDraft (draft : Async) = + async { + let! draft' = draft + let update = draft'.DraftRelease.ToUpdate() + update.Draft <- Nullable(false) + let! released = Async.AwaitTask <| draft'.Client.Release.Edit(draft'.Owner, draft'.Project, draft'.DraftRelease.Id, update) + printfn "Released %d on github" released.Id + } |> retry 5 diff --git a/deploy.cmd b/deploy.cmd new file mode 100644 index 0000000000..f203d8d970 --- /dev/null +++ b/deploy.cmd @@ -0,0 +1,13 @@ +@echo off + +"tools\nuget\nuget.exe" "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-version" "4.4.2" + +:Build +cls + +SET TARGET="ReleaseGitHub" + +"tools\FAKE.Core\tools\Fake.exe" "deploy.fsx" "target=%TARGET%" "buildMode=%BUILDMODE%" + +:Quit +exit /b %errorlevel% diff --git a/deploy.fsx b/deploy.fsx new file mode 100644 index 0000000000..aabd27e427 --- /dev/null +++ b/deploy.fsx @@ -0,0 +1,57 @@ +#r @"tools/FAKE.Core/tools/FakeLib.dll" +#load "Octokit.fsx" +open Fake +open Fake.Git +open System +open Octokit + +let authors = ["GitHub"] + +// project name +let gitOwner = "naveensrinivasan" +let gitHome = "https://github.com/" + gitOwner +let projectName = "Octokit" + +// The name of the project on GitHub +let gitName = "octokit.net" + +// directories +let packagingRoot = "./packaging/" + +let releaseNotes = + ReadFile "ReleaseNotes.md" + |> ReleaseNotesHelper.parseReleaseNotes + + +Target "ReleaseGitHub" (fun _ -> + let user = + match getBuildParam "github-user" with + | s when not (String.IsNullOrWhiteSpace s) -> s + | _ -> getUserInput "Username: " + let pw = + match getBuildParam "github-pw" with + | s when not (String.IsNullOrWhiteSpace s) -> s + | _ -> getUserPassword "Password: " + let remote = + Git.CommandHelper.getGitResult "" "remote -v" + |> Seq.filter (fun (s: string) -> s.EndsWith("(push)")) + |> Seq.tryFind (fun (s: string) -> s.Contains(gitOwner + "/" + gitName)) + |> function None -> gitHome + "/" + gitName | Some (s: string) -> s.Split().[0] + + StageAll "" + Git.Commit.Commit "" (sprintf "Bump version to %s" releaseNotes.NugetVersion) + Branches.pushBranch "" remote (Information.getBranchName "") + + Branches.tag "" releaseNotes.NugetVersion + Branches.pushTag "" remote releaseNotes.NugetVersion + + // release on github + createClient user pw + |> createDraft gitOwner gitName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes + |> uploadFile (sprintf "./packaging/Octokit.%s.nupkg" releaseNotes.AssemblyVersion) + |> uploadFile (sprintf "./packaging/Octokit.Reactive.%s.nupkg" releaseNotes.AssemblyVersion) + |> releaseDraft + |> Async.RunSynchronously +) + +RunTargetOrDefault "ReleaseGitHub" From 14a299af81945339558d07e2a29a456e2f7b0b98 Mon Sep 17 00:00:00 2001 From: Naveen Date: Thu, 8 Oct 2015 21:30:56 -0400 Subject: [PATCH 2/2] Eating your own dog food #905 Deploying octokit using octokit #905 --- Octokit.fsx | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ deploy.cmd | 15 ++++++++++ deploy.fsx | 55 ++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 Octokit.fsx create mode 100644 deploy.cmd create mode 100644 deploy.fsx diff --git a/Octokit.fsx b/Octokit.fsx new file mode 100644 index 0000000000..bc6719a458 --- /dev/null +++ b/Octokit.fsx @@ -0,0 +1,80 @@ +#I __SOURCE_DIRECTORY__ +#r "./Octokit/bin/Release/Net45/Octokit.dll" + +open Octokit +open System +open System.IO + +type Draft = + { Client : GitHubClient + Owner : string + Project : string + DraftRelease : Release } + +let private isRunningOnMono = System.Type.GetType ("Mono.Runtime") <> null + +let rec private retry count asyncF = + // This retry logic causes an exception on Mono: + // https://github.com/fsharp/fsharp/issues/440 + if isRunningOnMono then + asyncF + else + async { + try + return! asyncF + with _ when count > 0 -> return! retry (count - 1) asyncF + } + +let createClient user password = + async { + let github = new GitHubClient(new ProductHeaderValue("Octokit")) + github.Credentials <- Credentials(user, password) + return github + } + +let createClientWithToken token = + async { + let github = new GitHubClient(new ProductHeaderValue("Octokit")) + github.Credentials <- Credentials(token) + return github + } + +let private makeRelease draft owner project version prerelease (notes:seq) (client : Async) = + async { + let data = new NewRelease(version) + data.Name <- version + data.Body <- String.Join(Environment.NewLine, notes) + data.Draft <- draft + data.Prerelease <- prerelease + let! client' = client + let! draft = Async.AwaitTask <| client'.Release.Create(owner, project, data) + let draftWord = if data.Draft then " draft" else "" + printfn "Created%s release id %d" draftWord draft.Id + return { Client = client' + Owner = owner + Project = project + DraftRelease = draft } + } |> retry 5 + +let createDraft owner project version prerelease notes client = makeRelease true owner project version prerelease notes client +let createRelease owner project version prerelease notes client = makeRelease false owner project version prerelease notes client + +let uploadFile fileName (draft : Async) = + async { + let fi = FileInfo(fileName) + let archiveContents = File.OpenRead(fi.FullName) + let assetUpload = new ReleaseAssetUpload(fi.Name,"application/octet-stream",archiveContents,Nullable()) + let! draft' = draft + let! asset = Async.AwaitTask <| draft'.Client.Release.UploadAsset(draft'.DraftRelease, assetUpload) + printfn "Uploaded %s" asset.Name + return draft' + } |> retry 5 + +let releaseDraft (draft : Async) = + async { + let! draft' = draft + let update = draft'.DraftRelease.ToUpdate() + update.Draft <- Nullable(false) + let! released = Async.AwaitTask <| draft'.Client.Release.Edit(draft'.Owner, draft'.Project, draft'.DraftRelease.Id, update) + printfn "Released %d on github" released.Id + } |> retry 5 diff --git a/deploy.cmd b/deploy.cmd new file mode 100644 index 0000000000..9958d0220d --- /dev/null +++ b/deploy.cmd @@ -0,0 +1,15 @@ +@echo off + +"tools\nuget\nuget.exe" "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-version" "4.4.2" + +:Build +cls + +SET TARGET="ReleaseGitHub" +SET GITOWNER="octokit" +IF NOT [%1]==[] (set GITOWNER="%1") + +"tools\FAKE.Core\tools\Fake.exe" "deploy.fsx" "target=%TARGET%" "gitOwner=%GITOWNER%" + +:Quit +exit /b %errorlevel% diff --git a/deploy.fsx b/deploy.fsx new file mode 100644 index 0000000000..7f267654d8 --- /dev/null +++ b/deploy.fsx @@ -0,0 +1,55 @@ +#r @"tools/FAKE.Core/tools/FakeLib.dll" +#load "Octokit.fsx" +open Fake +open Fake.Git +open System +open Octokit + +let authors = ["GitHub"] + +// project name +let gitOwner = getBuildParam "gitOwner" +let gitHome = "https://github.com/" + gitOwner +let projectName = "Octokit" + +// The name of the project on GitHub +let gitName = "octokit.net" + +// directories +let packagingRoot = "./packaging/" + +let releaseNotes = + ReadFile "ReleaseNotes.md" + |> ReleaseNotesHelper.parseReleaseNotes + + +Target "ReleaseGitHub" (fun _ -> + let user = getBuildParam "gitOwner" + traceFAKE "The git owner is %s" user + let pw = + match getBuildParam "github-pw" with + | s when not (String.IsNullOrWhiteSpace s) -> s + | _ -> getUserPassword "Password: " + let remote = + Git.CommandHelper.getGitResult "" "remote -v" + |> Seq.filter (fun (s: string) -> s.EndsWith("(push)")) + |> Seq.tryFind (fun (s: string) -> s.Contains(gitOwner + "/" + gitName)) + |> function None -> gitHome + "/" + gitName | Some (s: string) -> s.Split().[0] + + StageAll "" + Git.Commit.Commit "" (sprintf "Bump version to %s" releaseNotes.NugetVersion) + Branches.pushBranch "" remote (Information.getBranchName "") + + Branches.tag "" releaseNotes.NugetVersion + Branches.pushTag "" remote releaseNotes.NugetVersion + + // release on github + createClient user pw + |> createDraft gitOwner gitName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes + |> uploadFile (sprintf "./packaging/Octokit.%s.nupkg" releaseNotes.AssemblyVersion) + |> uploadFile (sprintf "./packaging/Octokit.Reactive.%s.nupkg" releaseNotes.AssemblyVersion) + |> releaseDraft + |> Async.RunSynchronously +) + +RunTargetOrDefault "ReleaseGitHub"