|
| 1 | +open Octokit |
1 | 2 | // include Fake libs |
2 | 3 | #r "./packages/build/FAKE/tools/FakeLib.dll" |
3 | 4 | #r "System.IO.Compression.FileSystem" |
| 5 | +#load "paket-files/build/fsharp/FAKE/modules/Octokit/Octokit.fsx" |
| 6 | +#load "paket-files/build/fable-compiler/fake-helpers/Fable.FakeHelpers.fs" |
4 | 7 |
|
5 | | -open System |
6 | | -open System.IO |
7 | | -open System.Text.RegularExpressions |
8 | 8 | open Fake |
9 | | -open Fake.NpmHelper |
10 | | -open Fake.ReleaseNotesHelper |
11 | | -open Fake.Git |
12 | | -open Fake.YarnHelper |
| 9 | +open Fable.FakeHelpers |
13 | 10 |
|
14 | | -module Util = |
| 11 | +#if MONO |
| 12 | +// prevent incorrect output encoding (e.g. https://github.com/fsharp/FAKE/issues/1196) |
| 13 | +System.Console.OutputEncoding <- System.Text.Encoding.UTF8 |
| 14 | +#endif |
15 | 15 |
|
16 | | - let visitFile (visitor: string->string) (fileName : string) = |
17 | | - File.ReadAllLines(fileName) |
18 | | - |> Array.map (visitor) |
19 | | - |> fun lines -> File.WriteAllLines(fileName, lines) |
| 16 | +let project = "fable-react" |
| 17 | +let gitOwner = "fable-compiler" |
20 | 18 |
|
21 | | - let replaceLines (replacer: string->Match->string option) (reg: Regex) (fileName: string) = |
22 | | - fileName |> visitFile (fun line -> |
23 | | - let m = reg.Match(line) |
24 | | - if not m.Success |
25 | | - then line |
26 | | - else |
27 | | - match replacer line m with |
28 | | - | None -> line |
29 | | - | Some newLine -> newLine) |
| 19 | +let dotnetcliVersion = "2.0.3" |
| 20 | +let mutable dotnetExePath = environVarOrDefault "DOTNET" "dotnet" |
30 | 21 |
|
31 | | -let mutable dotnetExePath = "dotnet" |
32 | | - |
33 | | -let runDotnet dir = |
34 | | - DotNetCli.RunCommand (fun p -> { p with ToolPath = dotnetExePath |
35 | | - WorkingDir = dir |
36 | | - TimeOut = TimeSpan.FromHours 12. } ) |
37 | | - // Extra timeout allow us to run watch mode |
38 | | - // Otherwise, the process is stopped every 30 minutes by default |
39 | | - |
40 | | -Target "Clean" (fun _ -> |
41 | | - !! "src/**/bin" |
42 | | - ++ "src/**/obj" |
43 | | - |> Seq.iter(CleanDir) |
44 | | -) |
45 | | - |
46 | | -Target "Restore" (fun _ -> |
47 | | - !! "src/**/*.fsproj" |
48 | | - |> Seq.iter (fun s -> |
49 | | - let dir = IO.Path.GetDirectoryName s |
50 | | - runDotnet dir "restore") |
| 22 | +// Clean and install dotnet SDK |
| 23 | +Target "Bootstrap" (fun () -> |
| 24 | + !! "src/**/bin" ++ "src/**/obj" |> CleanDirs |
| 25 | + dotnetExePath <- DotNetCli.InstallDotNetSDK dotnetcliVersion |
51 | 26 | ) |
52 | 27 |
|
53 | | -Target "Build" (fun _ -> |
54 | | - !! "src/**/*.fsproj" |
55 | | - |> Seq.iter (fun s -> |
56 | | - let dir = IO.Path.GetDirectoryName s |
57 | | - runDotnet dir "build") |
| 28 | +Target "PublishPackages" (fun () -> |
| 29 | + [ "src/Fable.React/Fable.React.fsproj" |
| 30 | + "src/Fable.ReactLeaflet/Fable.ReactLeaflet.fsproj"] |
| 31 | + |> publishPackages __SOURCE_DIRECTORY__ dotnetExePath |
58 | 32 | ) |
59 | 33 |
|
60 | | -// -------------------------------------------------------------------------------------- |
61 | | -// Build a NuGet package |
62 | | -let needsPublishing (versionRegex: Regex) (releaseNotes: ReleaseNotes) projFile = |
63 | | - printfn "Project: %s" projFile |
64 | | - if releaseNotes.NugetVersion.ToUpper().EndsWith("NEXT") |
65 | | - then |
66 | | - printfn "Version in Release Notes ends with NEXT, don't publish yet." |
67 | | - false |
68 | | - else |
69 | | - File.ReadLines(projFile) |
70 | | - |> Seq.tryPick (fun line -> |
71 | | - let m = versionRegex.Match(line) |
72 | | - if m.Success then Some m else None) |
73 | | - |> function |
74 | | - | None -> failwith "Couldn't find version in project file" |
75 | | - | Some m -> |
76 | | - let sameVersion = m.Groups.[1].Value = releaseNotes.NugetVersion |
77 | | - if sameVersion then |
78 | | - printfn "Already version %s, no need to publish." releaseNotes.NugetVersion |
79 | | - not sameVersion |
80 | | - |
81 | | -let toPackageReleaseNotes (notes: string list) = |
82 | | - "* " + String.Join("\n * ", notes) |
83 | | - |> (fun txt -> txt.Replace("\"", "\\\"")) |
84 | | - |
85 | | -let pushNuget (releaseNotes: ReleaseNotes) (projFile: string) = |
86 | | - let versionRegex = Regex("<Version>(.*?)</Version>", RegexOptions.IgnoreCase) |
87 | | - |
88 | | - if needsPublishing versionRegex releaseNotes projFile then |
89 | | - let projDir = Path.GetDirectoryName(projFile) |
90 | | - let nugetKey = |
91 | | - match environVarOrNone "NUGET_KEY" with |
92 | | - | Some nugetKey -> nugetKey |
93 | | - | None -> failwith "The Nuget API key must be set in a NUGET_KEY environmental variable" |
94 | | - runDotnet projDir (sprintf "pack -c Release /p:Version=%s /p:PackageReleaseNotes=\"%s\"" releaseNotes.NugetVersion (toPackageReleaseNotes releaseNotes.Notes)) |
95 | | - Directory.GetFiles(projDir </> "bin" </> "Release", "*.nupkg") |
96 | | - |> Array.find (fun nupkg -> nupkg.Contains(releaseNotes.NugetVersion)) |
97 | | - |> (fun nupkg -> |
98 | | - (Path.GetFullPath nupkg, nugetKey) |
99 | | - ||> sprintf "nuget push %s -s nuget.org -k %s" |
100 | | - |> DotNetCli.RunCommand id) |
101 | | - // After successful publishing, update the project file |
102 | | - (versionRegex, projFile) |
103 | | - ||> Util.replaceLines (fun line _ -> |
104 | | - versionRegex.Replace(line, "<Version>"+releaseNotes.NugetVersion+"</Version>") |> Some) |
105 | | - |
106 | | -Target "PublishNugets" (fun _ -> |
107 | | - !! "src/Fable.React/Fable.React.fsproj" |
108 | | - ++ "src/Fable.ReactLeaflet/Fable.ReactLeaflet.fsproj" |
109 | | - |> Seq.iter(fun s -> |
110 | | - let projFile = s |
111 | | - let projDir = IO.Path.GetDirectoryName(projFile) |
112 | | - let release = projDir </> "RELEASE_NOTES.md" |> ReleaseNotesHelper.LoadReleaseNotes |
113 | | - pushNuget release projFile |
| 34 | +Target "GitHubRelease" (fun () -> |
| 35 | + let releasePath = __SOURCE_DIRECTORY__ </> "src/Fable.React/RELEASE_NOTES.md" |
| 36 | + githubRelease releasePath gitOwner project (fun user pw release -> |
| 37 | + createClient user pw |
| 38 | + |> createDraft gitOwner project release.NugetVersion |
| 39 | + (release.SemVer.PreRelease <> None) release.Notes |
| 40 | + |> releaseDraft |
| 41 | + |> Async.RunSynchronously |
114 | 42 | ) |
115 | 43 | ) |
116 | 44 |
|
117 | | -// Build order |
118 | | -"Clean" |
119 | | - ==> "Restore" |
120 | | - ==> "Build" |
121 | | - ==> "PublishNugets" |
| 45 | +"Bootstrap" |
| 46 | +==> "PublishPackages" |
| 47 | +==> "GitHubRelease" |
122 | 48 |
|
123 | | -// start build |
124 | | -RunTargetOrDefault "Build" |
| 49 | +RunTargetOrDefault "Bootstrap" |
0 commit comments