From 63008937e8275bea6a8bed60bb7ac6bb220fe47a Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sat, 9 Mar 2024 14:56:37 +0100 Subject: [PATCH] scripts/make.fsx: gen normal nupkg & prerelease This way we catch potential issues with the non-prerelease nuget package before the git tag is pushed. --- scripts/make.fsx | 65 +++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/scripts/make.fsx b/scripts/make.fsx index 0c9bb7db0..574c570b0 100644 --- a/scripts/make.fsx +++ b/scripts/make.fsx @@ -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 @@ -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 @@ -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 + 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 - 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( { @@ -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?"