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.

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. Because even numbers map to "stableness" and odd
numbers to the opposite.
  • Loading branch information
knocte committed Mar 10, 2024
1 parent 4488d66 commit c781bee
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 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

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.ToString())
let zipName = sprintf "%s.zip" zipNameWithoutExtension
let pathToZip = Path.Combine(binDir, zipName)
if (File.Exists (pathToZip)) then
Expand Down Expand Up @@ -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<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
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<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.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(
{
Expand Down

0 comments on commit c781bee

Please sign in to comment.