@@ -6,7 +6,7 @@ open System.Linq
6
6
open System.Diagnostics
7
7
8
8
#if ! LEGACY_ FRAMEWORK
9
- #r " nuget: Fsdk, Version=0.6.0--date20230818-1152 .git-83d671b "
9
+ #r " nuget: Fsdk, Version=0.6.0--date20240306-1035 .git-a0a5c67 "
10
10
#else
11
11
#r " System.Configuration"
12
12
open System.Configuration
@@ -30,6 +30,8 @@ let GTK_FRONTEND_APP = sprintf "%s.Frontend.XF.Gtk" PASCALCASE_NAME
30
30
let CONSOLE_FRONTEND_APP = sprintf " %s .Frontend.ConsoleApp" PASCALCASE_ NAME
31
31
let BACKEND_LIB = sprintf " %s .Backend" PASCALCASE_ NAME
32
32
33
+ let version = ( Misc.GetCurrentVersion FsxHelper.RootDir) .ToString()
34
+
33
35
type FrontendProject =
34
36
| XF
35
37
| Gtk
@@ -403,6 +405,7 @@ let GetPathToFrontend (frontend: FrontendApp) (binaryConfig: BinaryConfig): Dire
403
405
404
406
let GetPathToBackend () =
405
407
Path.Combine ( FsxHelper.RootDir.FullName, " src" , BACKEND_ LIB)
408
+ |> DirectoryInfo
406
409
407
410
let MakeAll ( maybeConstant : Option < string >) =
408
411
#if LEGACY_ FRAMEWORK
@@ -463,8 +466,6 @@ match maybeTarget with
463
466
let zipCommand = " zip"
464
467
MakeCheckCommand zipCommand
465
468
466
- let version = ( Misc.GetCurrentVersion FsxHelper.RootDir) .ToString()
467
-
468
469
let release = BinaryConfig.Release
469
470
let frontend , script = JustBuild release None
470
471
let binDir = " bin"
@@ -623,7 +624,7 @@ match maybeTarget with
623
624
624
625
| Some " update-servers" ->
625
626
let _ , buildConfig = MakeAll None
626
- Directory.SetCurrentDirectory ( GetPathToBackend())
627
+ Directory.SetCurrentDirectory ( GetPathToBackend() .FullName )
627
628
let proc1 = RunFrontend FrontendApp.Console buildConfig ( Some " --update-servers-file" )
628
629
if proc1.ExitCode <> 0 then
629
630
Environment.Exit proc1.ExitCode
@@ -663,6 +664,94 @@ match maybeTarget with
663
664
Echo.All
664
665
) .UnwrapDefault() |> ignore< string>
665
666
667
+ | Some " push" ->
668
+ #if LEGACY_ FRAMEWORK
669
+ Console.Error.WriteLine " Pushing a nuget package is not supported with .NET legacy or Mono"
670
+ Environment.Exit 1
671
+ #else
672
+ let githubRef = Environment.GetEnvironmentVariable " GITHUB_REF"
673
+ if isNull githubRef then
674
+ Console.Error.WriteLine " Pushing a nuget package is only meant for GitHub CI jobs"
675
+ Environment.Exit 1
676
+
677
+ let tagPrefix = " refs/tags/"
678
+ let masterBranchRef = " refs/heads/master"
679
+ let isTag =
680
+ githubRef.StartsWith tagPrefix
681
+
682
+ let nugetVersion =
683
+ if isTag then
684
+ githubRef.Substring tagPrefix.Length
685
+ else
686
+ Network.GetNugetPrereleaseVersionFromBaseVersion version
687
+ let backendDir = GetPathToBackend()
688
+ let backendProj = Path.Combine( backendDir.FullName, BACKEND_ LIB + " .fsproj" )
689
+
690
+ Process.Execute(
691
+ {
692
+ Command = " dotnet"
693
+ Arguments = sprintf " pack -property:Version=%s %s " nugetVersion backendProj
694
+ },
695
+ Echo.All
696
+ ) .UnwrapDefault() |> ignore< string>
697
+
698
+ let maybeNupkg =
699
+ Directory.GetFiles( backendDir.FullName, " *.nupkg" , SearchOption.AllDirectories)
700
+ |> Seq.tryExactlyOne
701
+
702
+ let nugetApiKey = Environment.GetEnvironmentVariable " NUGET_API_KEY"
703
+ if String.IsNullOrEmpty nugetApiKey then
704
+ Console.WriteLine " NUGET_API_KEY not found, skipping push"
705
+ Environment.Exit 0
706
+
707
+ match maybeNupkg with
708
+ | None -> failwith " File *.nupkg not found, did `dotnet pack` work properly?"
709
+ | Some nupkg ->
710
+ let push () =
711
+ Process.Execute(
712
+ {
713
+ Command = " dotnet"
714
+ Arguments = sprintf " nuget push --api-key %s %s " nugetApiKey nupkg
715
+ },
716
+ Echo.All
717
+ ) .UnwrapDefault() |> ignore< string>
718
+
719
+ let eventName = Environment.GetEnvironmentVariable " GITHUB_EVENT_NAME"
720
+ if isNull eventName then
721
+ failwith " Env var 'GITHUB_EVENT_NAME' not set; not running as GitHubActions job?"
722
+ if eventName <> " push" then
723
+ Console.WriteLine " GitHubActions event not 'push', skipping..."
724
+ Environment.Exit 0
725
+
726
+ if isTag then
727
+ push()
728
+ else
729
+ if githubRef <> masterBranchRef then
730
+ Console.WriteLine " Pushed to non-master branch, skipping..."
731
+ Environment.Exit 0
732
+
733
+ let commitHash = Environment.GetEnvironmentVariable " GITHUB_SHA"
734
+ if isNull commitHash then
735
+ failwith " Env var 'GITHUB_SHA' not set; not running as GitHubActions job?"
736
+ let gitArgs = sprintf " describe --exact-match --tags %s " commitHash
737
+ let gitProcRes =
738
+ Process.Execute(
739
+ {
740
+ Command = " git"
741
+ Arguments = gitArgs
742
+ },
743
+ Echo.All
744
+ ) .Result
745
+ match gitProcRes with
746
+ | ProcessResultState.Success _ ->
747
+ Console.WriteLine " Commit mapped to a tag, skipping pushing prerelease..."
748
+ Environment.Exit 0
749
+ | ProcessResultState.Error _ ->
750
+ push()
751
+ | _ ->
752
+ failwith " warning from git command?"
753
+ #endif
754
+
666
755
| Some( someOtherTarget) ->
667
756
Console.Error.WriteLine( " Unrecognized target: " + someOtherTarget)
668
757
Environment.Exit 2
0 commit comments