From 986c70a286cdc3980feb4523d7fe580dc4d0c4be 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. For example, the following warning: ``` /usr/lib/dotnet/sdk/6.0.127/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets(221,5): error NU5104: A stable release of a package should not have a prerelease dependency. Either modify the version spec of dependency "Fsdk [0.6.0--date20230530-1155.git-3bb8d08, )" or update the version field in the nuspec. [/__w/geewallet/geewallet/src/GWallet.Backend/GWallet.Backend.fsproj] ``` So let's enable 'warnaserror' in the 'dotnet pack' command if the version to pack is even (e.g. 0.8) and ignore the warning for now if it's odd (e.g. 0.7) like it currently happens. --- scripts/make.fsx | 70 +++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/scripts/make.fsx b/scripts/make.fsx index 0c9bb7db0..a00c63b6c 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 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.ToString()) let zipName = sprintf "%s.zip" zipNameWithoutExtension let pathToZip = Path.Combine(binDir, zipName) if (File.Exists (pathToZip)) then @@ -685,41 +685,55 @@ 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 + let maybeWarnAsError = + if currentVersion.Minor % 2 = 0 then + "-warnaserror" + else + String.Empty + Process.Execute( + { + Command = "dotnet" + Arguments = sprintf "pack %s %s %s" maybeWarnAsError 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.ToString()) + 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.ToString()) + 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 +770,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?"