Skip to content

Commit

Permalink
Release version 3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Mangel committed Jun 24, 2019
1 parent 76328cf commit 14006fd
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 76 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 3.3.0 - 2019-06-24
### Changed

* Fix #19: Stop using first person when reporting an error (by @jeremyabbott)

## 3.2.0 - 2019-06-05
### Fixed
* Fix auto coders with recursive types (by @alfonsogarciacaro)
Expand Down
109 changes: 82 additions & 27 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.IO.FileSystemOperators
open Fake.Tools.Git
open Fake.Tools
open Fake.Api
open Fake.JavaScript

let versionFromGlobalJson : DotNet.CliInstallOptions -> DotNet.CliInstallOptions = (fun o ->
Expand All @@ -31,9 +32,13 @@ let inline dtntWorkDir wd =
let inline yarnWorkDir (ws : string) (yarnParams : Yarn.YarnParams) =
{ yarnParams with WorkingDirectory = ws }

let root = __SOURCE_DIRECTORY__
let projectFile = "./src/Thoth.Json.fsproj"
let testsFile = "./tests/Thoth.Tests.fsproj"

let gitOwner = "thoth-org"
let repoName = "Thoth.Json"

module Util =

let visitFile (visitor: string -> string) (fileName : string) =
Expand Down Expand Up @@ -122,22 +127,22 @@ let needsPublishing (versionRegex: Regex) (newVersion: string) projFile =
let pushNuget (newVersion: string) (projFile: string) =
let versionRegex = Regex("<Version>(.*?)</Version>", RegexOptions.IgnoreCase)

if needsPublishing versionRegex newVersion projFile then
let projDir = Path.GetDirectoryName(projFile)
let nugetKey =
match Environment.environVarOrNone "NUGET_KEY" with
| Some nugetKey -> nugetKey
| None -> failwith "The Nuget API key must be set in a NUGET_KEY environmental variable"
let projDir = Path.GetDirectoryName(projFile)
let nugetKey =
match Environment.environVarOrNone "NUGET_KEY" with
| Some nugetKey -> nugetKey
| None -> failwith "The Nuget API key must be set in a NUGET_KEY environmental variable"

(versionRegex, projFile) ||> Util.replaceLines (fun line _ ->
versionRegex.Replace(line, "<Version>" + newVersion + "</Version>") |> Some)
(versionRegex, projFile) ||> Util.replaceLines (fun line _ ->
versionRegex.Replace(line, "<Version>" + newVersion + "</Version>") |> Some)

DotNet.pack (fun p ->
{ p with
Configuration = DotNet.Release
Common = { p.Common with DotNetCliPath = "dotnet" } } )
projFile
DotNet.pack (fun p ->
{ p with
Configuration = DotNet.Release
Common = { p.Common with DotNetCliPath = "dotnet" } } )
projFile

if needsPublishing versionRegex newVersion projFile then
let files =
Directory.GetFiles(projDir </> "bin" </> "Release", "*.nupkg")
|> Array.find (fun nupkg -> nupkg.Contains(newVersion))
Expand All @@ -149,26 +154,76 @@ let pushNuget (newVersion: string) (projFile: string) =
WorkingDir = __SOURCE_DIRECTORY__ })
files

let versionRegex = Regex("^## ?\\[?v?([\\w\\d.-]+\\.[\\w\\d.-]+[a-zA-Z0-9])\\]?", RegexOptions.IgnoreCase)

let getLastVersion () =
File.ReadLines("CHANGELOG.md")
|> Seq.tryPick (fun line ->
let m = versionRegex.Match(line)
if m.Success then Some m else None)
|> function
| None -> failwith "Couldn't find version in changelog file"
| Some m ->
m.Groups.[1].Value

let isPreRelease (version : string) =
let regex = Regex(".*(alpha|beta|rc).*", RegexOptions.IgnoreCase)
regex.IsMatch(version)

let getNotes (version : string) =
File.ReadLines("CHANGELOG.md")
|> Seq.skipWhile(fun line ->
let m = versionRegex.Match(line)

if m.Success then
not (m.Groups.[1].Value = version)
else
true
)
// Remove the version line
|> Seq.skip 1
// Take all until the next version line
|> Seq.takeWhile (fun line ->
let m = versionRegex.Match(line)
not m.Success
)

Target.create "Publish" (fun _ ->
let versionRegex = Regex("^## ?\\[?v?([\\w\\d.-]+\\.[\\w\\d.-]+[a-zA-Z0-9])\\]?", RegexOptions.IgnoreCase)

let newVersion =
File.ReadLines("CHANGELOG.md")
|> Seq.tryPick (fun line ->
let m = versionRegex.Match(line)
if m.Success then Some m else None)
|> function
| None -> failwith "Couldn't find version in changelog file"
| Some m ->
m.Groups.[1].Value

pushNuget newVersion projectFile
let version = getLastVersion()
pushNuget version projectFile
)

Target.create "Release" (fun _ ->
let version = getLastVersion()

Git.Staging.stageAll root
let commitMsg = sprintf "Release version %s" version
Git.Commit.exec root commitMsg
Git.Branches.push root

let token =
match Environment.environVarOrDefault "GITHUB_TOKEN" "" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> failwith "The Github token must be set in a GITHUB_TOKEN environmental variable"

let nupkg =
let projDir = Path.GetDirectoryName(projectFile)

Directory.GetFiles(projDir </> "bin" </> "Release", "*.nupkg")
|> Array.find (fun nupkg -> nupkg.Contains(version))

GitHub.createClientWithToken token
|> GitHub.draftNewRelease gitOwner repoName version (isPreRelease version) (getNotes version)
// |> GitHub.uploadFile nupkg
|> GitHub.publishDraft
|> Async.RunSynchronously
)

"Clean"
==> "YarnInstall"
==> "DotnetRestore"
==> "MochaTest"
==> "Publish"
==> "Release"

Target.runOrDefault "MochaTest"
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ group netcorebuild
nuget Fake.IO.FileSystem
nuget Fake.Tools.Git
nuget Fake.JavaScript.Yarn
nuget Fake.Api.GitHub
Loading

0 comments on commit 14006fd

Please sign in to comment.