Skip to content

Commit

Permalink
Tools,Fsdk: move prerelease version gen to Fsdk
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Dec 13, 2023
1 parent 2737eea commit b809f01
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Fsdk/Fsdk-legacy.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
<Compile Include="Misc.fs" />
<Compile Include="Process.fs" />
<Compile Include="Unix.fs" />
<Compile Include="Network.fs" />
<Compile Include="Git.fs" />
<Compile Include="Network.fs" />
<Compile Include="Taiga.fs" />
</ItemGroup>
<Import Project="..\CommonBuildProps-legacy.proj" />
Expand Down
26 changes: 26 additions & 0 deletions Fsdk/Network.fs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,32 @@ module Network =
GetPrivateIpOfThisServer()
)

// this is a translation of doing this in unix (assuming initialVersion="0.1.0"):
// 0.1.0--date`date +%Y%m%d-%H%M`.git-`git rev-parse --short=7 HEAD`
let GetNugetPrereleaseVersionFromBaseVersion(baseVersion: string) =
let initialVersion =
let versionSplit = baseVersion.Split '.'

if versionSplit.Length = 4 && versionSplit.[3] = "0" then
String.Join(".", versionSplit.Take 3)
else
baseVersion

let dateSegment =
sprintf "date%s" (DateTime.UtcNow.ToString "yyyyMMdd-hhmm")

let gitHash = Git.GetLastCommit()

if isNull gitHash then
Console.Error.WriteLine "Not in a git repository?"
Environment.Exit 2

let gitHashDefaultShortLength = 7
let gitShortHash = gitHash.Substring(0, gitHashDefaultShortLength)
let gitSegment = sprintf "git-%s" gitShortHash
let finalVersion = sprintf "%s--%s.%s" initialVersion dateSegment gitSegment
finalVersion

let NugetDownloadUrl =
"https://dist.nuget.org/win-x86-commandline/v5.4.0/nuget.exe"

Expand Down
34 changes: 4 additions & 30 deletions Tools/nugetPush.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ open System.Configuration

#load "../Fsdk/Misc.fs"
#load "../Fsdk/Process.fs"
#load "../Fsdk/Network.fs"
#load "../Fsdk/Git.fs"
#load "../Fsdk/Network.fs"

open Fsdk
open Fsdk.Process
Expand All @@ -31,32 +31,6 @@ if args.Length > 2 && args.[0] <> "--output-version" then

let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo

// this is a translation of doing this in unix (assuming initialVersion="0.1.0"):
// 0.1.0--date`date +%Y%m%d-%H%M`.git-`git rev-parse --short=7 HEAD`
let GetIdealNugetVersion(inputVersion: string) =
let initialVersion =
let versionSplit = inputVersion.Split '.'

if versionSplit.Length = 4 && versionSplit.[3] = "0" then
String.Join(".", versionSplit.Take 3)
else
inputVersion

let dateSegment =
sprintf "date%s" (DateTime.UtcNow.ToString "yyyyMMdd-hhmm")

let gitHash = Git.GetLastCommit()

if null = gitHash then
Console.Error.WriteLine "Not in a git repository?"
Environment.Exit 2

let gitHashDefaultShortLength = 7
let gitShortHash = gitHash.Substring(0, gitHashDefaultShortLength)
let gitSegment = sprintf "git-%s" gitShortHash
let finalVersion = sprintf "%s--%s.%s" initialVersion dateSegment gitSegment
finalVersion

let IsDotNetSdkInstalled() =
try
let dotnetVersionCmd =
Expand Down Expand Up @@ -115,7 +89,7 @@ let FindOrGenerateNugetPackages() : seq<FileInfo> =
let packageName =
Path.GetFileNameWithoutExtension nuspecFile.FullName

let nugetVersion = GetIdealNugetVersion baseVersion
let nugetVersion = Network.GetPrereleaseNugetVersionFromBaseVersion baseVersion

// we need to download nuget.exe here because `dotnet pack` doesn't support using standalone (i.e.
// without a project association) .nuspec files, see https://github.com/NuGet/Home/issues/4254
Expand Down Expand Up @@ -150,7 +124,7 @@ let FindOrGenerateNugetPackages() : seq<FileInfo> =
Environment.Exit 1

let baseVersion = args.First()
let nugetVersion = GetIdealNugetVersion baseVersion
let nugetVersion = Network.GetPrereleaseNugetVersionFromBaseVersion baseVersion

if IsDotNetSdkInstalled() then
let dotnetPackCmd =
Expand Down Expand Up @@ -218,7 +192,7 @@ if args.Length > 0 && args.[0] = "--output-version" then
Environment.Exit 4

let baseVersion = args.[1]
Console.WriteLine(GetIdealNugetVersion baseVersion)
Console.WriteLine(Network.GetPrereleaseNugetVersionFromBaseVersion baseVersion)
Environment.Exit 0

let nugetPkgs = FindOrGenerateNugetPackages() |> List.ofSeq
Expand Down
1 change: 1 addition & 0 deletions Tools/safeRun.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open System.Configuration
#load "../Fsdk/Misc.fs"
#load "../Fsdk/Process.fs"
#load "../Fsdk/Unix.fs"
#load "../Fsdk/Git.fs"
#load "../Fsdk/Network.fs"

open Fsdk
Expand Down
3 changes: 3 additions & 0 deletions fsx/fsx-legacy.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<Compile Include="..\Fsdk\Process.fs">
<Link>..\Fsdk\Process.fs</Link>
</Compile>
<Compile Include="..\Fsdk\Git.fs">
<Link>..\Fsdk\Git.fs</Link>
</Compile>
<Compile Include="..\Fsdk\Network.fs">
<Link>..\Fsdk\Network.fs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions fsx/fsx.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<Compile Include="..\Fsdk\Process.fs">
<Link>..\Fsdk\Process.fs</Link>
</Compile>
<Compile Include="..\Fsdk\Git.fs">
<Link>..\Fsdk\Git.fs</Link>
</Compile>
<Compile Include="..\Fsdk\Network.fs">
<Link>..\Fsdk\Network.fs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions fsxc/fsxc-legacy.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<Compile Include="..\Fsdk\Process.fs">
<Link>Fsdk\Process.fs</Link>
</Compile>
<Compile Include="..\Fsdk\Git.fs">
<Link>Fsdk\Git.fs</Link>
</Compile>
<Compile Include="..\Fsdk\Network.fs">
<Link>Fsdk\Network.fs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions fsxc/fsxc.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<Compile Include="..\Fsdk\Process.fs">
<Link>Fsdk\Process.fs</Link>
</Compile>
<Compile Include="..\Fsdk\Git.fs">
<Link>Fsdk\Git.fs</Link>
</Compile>
<Compile Include="..\Fsdk\Network.fs">
<Link>Fsdk\Network.fs</Link>
</Compile>
Expand Down
2 changes: 1 addition & 1 deletion scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ open System.Configuration

#load "../Fsdk/Misc.fs"
#load "../Fsdk/Process.fs"
#load "../Fsdk/Network.fs"
#load "../Fsdk/Git.fs"
#load "../Fsdk/Network.fs"

open Fsdk
open Fsdk.Process
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ open System.Configuration

#load "../Fsdk/Misc.fs"
#load "../Fsdk/Process.fs"
#load "../Fsdk/Network.fs"
#load "../Fsdk/Git.fs"
#load "../Fsdk/Network.fs"

open Fsdk
open Fsdk.Process
Expand Down
2 changes: 1 addition & 1 deletion scripts/runTests.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ open System.Configuration

#load "../Fsdk/Misc.fs"
#load "../Fsdk/Process.fs"
#load "../Fsdk/Network.fs"
#load "../Fsdk/Git.fs"
#load "../Fsdk/Network.fs"

open Fsdk
open Fsdk.Process
Expand Down
2 changes: 1 addition & 1 deletion scripts/runUnitTests.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ open System.Configuration

#load "../Fsdk/Misc.fs"
#load "../Fsdk/Process.fs"
#load "../Fsdk/Network.fs"
#load "../Fsdk/Git.fs"
#load "../Fsdk/Network.fs"

open Fsdk
open Fsdk.Process
Expand Down

0 comments on commit b809f01

Please sign in to comment.