|
| 1 | +module Build.AutomatedRelease |
| 2 | + |
| 3 | +open System |
| 4 | +open System.IO |
| 5 | +open Build.Workspace |
| 6 | +open SimpleExec |
| 7 | +open BlackFox.CommandLine |
| 8 | +open EasyBuild.Tools.Git |
| 9 | +open Build.FableLibrary |
| 10 | +open EasyBuild.Tools.DotNet |
| 11 | +open EasyBuild.Tools.Changelog |
| 12 | +open EasyBuild.Tools.PackageJson |
| 13 | +open EasyBuild.Tools.Npm |
| 14 | + |
| 15 | +let private createGithubRelease (version: LastVersionFinder.Version) = |
| 16 | + |
| 17 | + let struct (lastestTag, _) = |
| 18 | + Command.ReadAsync("git", "describe --abbrev=0 --tags") |
| 19 | + |> Async.AwaitTask |
| 20 | + |> Async.RunSynchronously |
| 21 | + |
| 22 | + let versionText = version.Version.ToString() |
| 23 | + |
| 24 | + // Only create a Github release if the tag doesn't exist |
| 25 | + // It can happens that we trigger a release where Fable.Cli |
| 26 | + // is already up to date. |
| 27 | + if lastestTag.Trim() <> versionText then |
| 28 | + Command.Run( |
| 29 | + "gh", |
| 30 | + CmdLine.empty |
| 31 | + |> CmdLine.appendRaw "release" |
| 32 | + |> CmdLine.appendRaw "create" |
| 33 | + |> CmdLine.appendRaw versionText |
| 34 | + |> CmdLine.appendPrefix "--title" versionText |
| 35 | + |> CmdLine.appendPrefix "--notes" version.Body |
| 36 | + |> CmdLine.appendIf version.Version.IsPrerelease "--prerelease" |
| 37 | + |> CmdLine.toString |
| 38 | + ) |
| 39 | + |
| 40 | +let private createReleaseCommitAndPush (version: LastVersionFinder.Version) = |
| 41 | + let versionText = version.Version.ToString() |
| 42 | + |
| 43 | + Git.addAll () |
| 44 | + Git.commit ($"Release %s{versionText}") |
| 45 | + Git.push () |
| 46 | + |
| 47 | +let handle (args: string list) = |
| 48 | + let struct (currentBranch, _) = |
| 49 | + Command.ReadAsync("git", "rev-parse --abbrev-ref HEAD") |
| 50 | + |> Async.AwaitTask |
| 51 | + |> Async.RunSynchronously |
| 52 | + |
| 53 | + if currentBranch.Trim() <> "main" then |
| 54 | + failwith "You must be on the main branch to release" |
| 55 | + |
| 56 | + // let prepareOnly = args |> List.contains "--prepare-only" |
| 57 | + |
| 58 | + |
| 59 | + // Build all the fable-libraries |
| 60 | + // Force rebuld of fable-libraries to make sure they are generated with the latest |
| 61 | + // version of the compiler |
| 62 | + BuildFableLibraryBeam().Run(true) |
| 63 | + BuildFableLibraryDart().Run(true) |
| 64 | + BuildFableLibraryJavaScript().Run(true) |
| 65 | + BuildFableLibraryPython().Run(true) |
| 66 | + BuildFableLibraryRust().Run(true) |
| 67 | + BuildFableLibraryTypeScript().Run(true) |
| 68 | + |
| 69 | + // Handle the NPM packages |
| 70 | + |
| 71 | + // We also want to update the original package.json if needed |
| 72 | + // This is to keep the versions consistent across the project |
| 73 | + PackageJson.replaceVersion (PackageJson.fableLibraryTs, Changelog.fableLibraryTs |> Changelog.findLastVersion) |
| 74 | + |
| 75 | +// publishNpm ProjectDir.fable_metadata |
| 76 | + |
| 77 | +// // Update embedded version (both compiler and libraries) |
| 78 | +// let compilerVersion = |
| 79 | +// Path.Combine(ProjectDir.fableCli, "CHANGELOG.md") |
| 80 | +// |> FileInfo |
| 81 | +// |> Changelog.findLastVersion |
| 82 | + |
| 83 | +// updateLibraryVersionInFableTransforms |
| 84 | +// compilerVersion |
| 85 | +// {| |
| 86 | +// JavaScript = PackageJson.tempFableLibraryJs |> PackageJson.getVersion |
| 87 | +// TypeScript = PackageJson.tempFableLibraryTs |> PackageJson.getVersion |
| 88 | +// |} |
| 89 | + |
| 90 | +// publishNuget ProjectDir.fableAst false |
| 91 | +// publishNuget ProjectDir.fableCore false |
| 92 | +// publishNuget ProjectDir.fableCompiler true |
| 93 | +// publishNuget ProjectDir.fableCli false |
| 94 | +// publishNuget ProjectDir.fablePublishUtils false |
| 95 | + |
| 96 | +// // Release fable-compiler-js and fable-standalone after Fable.Cli |
| 97 | +// // otherwise the reported version for Fable will be wrong |
| 98 | + |
| 99 | +// // Trigger fable-compiler-js target to make sure everything is ready for publish |
| 100 | +// // Note: fable-standalone is built as part of fable-compiler-js |
| 101 | +// // so no need to build it separately |
| 102 | +// // Note 2: We already built fable-library, it will be skipped thanks to incremental build |
| 103 | +// CompilerJs.handle [] |
| 104 | + |
| 105 | +// publishNpm ProjectDir.fable_standalone |
| 106 | +// publishNpm ProjectDir.fable_compiler_js |
0 commit comments