Skip to content

Commit

Permalink
scripts/make.fsx: gen normal nupkg & prerelease
Browse files Browse the repository at this point in the history
This way we catch potential issues with the non-prerelease nuget
package before the git tag is pushed.
  • Loading branch information
knocte committed Mar 9, 2024
1 parent 4488d66 commit 6300893
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let GTK_FRONTEND_APP = sprintf "%s.Frontend.XF.Gtk" PASCALCASE_NAME
let CONSOLE_FRONTEND_APP = sprintf "%s.Frontend.ConsoleApp" PASCALCASE_NAME
let BACKEND_LIB = sprintf "%s.Backend" PASCALCASE_NAME

let version = (Misc.GetCurrentVersion FsxHelper.RootDir).ToString()
let currentVersion = (Misc.GetCurrentVersion FsxHelper.RootDir).ToString()

type FrontendProject =
| XF
Expand Down Expand Up @@ -477,7 +477,7 @@ match maybeTarget with
let binDir = "bin"
Directory.CreateDirectory(binDir) |> ignore

let zipNameWithoutExtension = sprintf "%s-v%s" script.Name version
let zipNameWithoutExtension = sprintf "%s-v%s" script.Name currentVersion
let zipName = sprintf "%s.zip" zipNameWithoutExtension
let pathToZip = Path.Combine(binDir, zipName)
if (File.Exists (pathToZip)) then
Expand Down Expand Up @@ -685,41 +685,50 @@ match maybeTarget with
let isTag =
githubRef.StartsWith tagPrefix

let nugetVersion =
if isTag then
githubRef.Substring tagPrefix.Length
else
Network.GetNugetPrereleaseVersionFromBaseVersion version
let backendDir = GetPathToBackend()
let backendProj = Path.Combine(backendDir.FullName, BACKEND_LIB + ".fsproj")

let binaryConfig =
if isTag then
BinaryConfig.Release
else
BinaryConfig.Debug
let buildFlags = GetBuildFlags "dotnet" binaryConfig None
let allBuildFlags = sprintf "%s -property:Version=%s" buildFlags nugetVersion
Process.Execute(
{
Command = "dotnet"
Arguments = sprintf "pack %s %s" allBuildFlags backendProj
},
Echo.All
).UnwrapDefault() |> ignore<string>
let createNugetPackageFile versionToPack =
let binaryConfig =
if isTag then
BinaryConfig.Release
else
BinaryConfig.Debug
let buildFlags = GetBuildFlags "dotnet" binaryConfig None
let allBuildFlags = sprintf "%s -property:Version=%s" buildFlags versionToPack
Process.Execute(
{
Command = "dotnet"
Arguments = sprintf "pack -warnaserror %s %s" allBuildFlags backendProj
},
Echo.All
).UnwrapDefault() |> ignore<string>

let maybeNupkg =
Directory.GetFiles(backendDir.FullName, "*.nupkg", SearchOption.AllDirectories)
|> Seq.tryExactlyOne

// try first to create a non-prerelease package (as we want to fail fast instead of just fail at git tag push)
let maybeNupkg = createNugetPackageFile currentVersion
let nupkg =
match maybeNupkg with
| None -> failwith "File *.nupkg not found, did `dotnet pack` work properly?"
| Some nupkg ->
if isTag then
nupkg
else
File.Delete nupkg
let nugetVersion = Network.GetNugetPrereleaseVersionFromBaseVersion currentVersion
match createNugetPackageFile nugetVersion with
| None ->
failwith "File *.nupkg not found (prerelease), did `dotnet pack` work properly?"
| Some nupkg ->
nupkg

let nugetApiKey = Environment.GetEnvironmentVariable "NUGET_API_KEY"
if String.IsNullOrEmpty nugetApiKey then
Console.WriteLine "NUGET_API_KEY not found, skipping push"
Environment.Exit 0

match maybeNupkg with
| None -> failwith "File *.nupkg not found, did `dotnet pack` work properly?"
| Some nupkg ->
else
let push() =
Process.Execute(
{
Expand Down Expand Up @@ -756,10 +765,10 @@ match maybeTarget with
Echo.All
).Result
match gitProcRes with
| ProcessResultState.Success _ ->
| Success _ ->
Console.WriteLine "Commit mapped to a tag, skipping pushing prerelease..."
Environment.Exit 0
| ProcessResultState.Error _ ->
| Error _ ->
push()
| _ ->
failwith "warning from git command?"
Expand Down

0 comments on commit 6300893

Please sign in to comment.