Skip to content

Commit 7eba876

Browse files
committed
CI: job to upload GWallet.Backend to nuget.org
Based on e3c14b3.
1 parent f27a427 commit 7eba876

File tree

4 files changed

+125
-7
lines changed

4 files changed

+125
-7
lines changed

.github/workflows/CI.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,35 @@ jobs:
490490
if: github.event_name == 'pull_request'
491491
run: ./conventions/commitlint.sh --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
492492

493-
snap_pkg:
494-
493+
nuget_pkg:
495494
needs:
496495
- conventions
497496

497+
runs-on: ubuntu-22.04
498+
container:
499+
image: "ubuntu:22.04"
500+
501+
env:
502+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
503+
504+
steps:
505+
- uses: actions/checkout@v1
506+
- name: install sudo
507+
run: apt update && apt install --yes sudo
508+
- name: install all dependencies
509+
run: sudo DEBIAN_FRONTEND=noninteractive apt install --yes git make dotnet6
510+
# workaround for https://github.com/actions/runner/issues/2033
511+
- name: ownership workaround
512+
run: git config --global --add safe.directory '*'
513+
- name: configure
514+
run: ./configure.sh
515+
- name: pack&push
516+
run: make push
517+
518+
snap_pkg:
519+
needs:
520+
- nuget_pkg
521+
498522
runs-on: ubuntu-22.04
499523
steps:
500524
- uses: actions/checkout@v1
@@ -538,7 +562,7 @@ jobs:
538562
snap_pkg_beta:
539563

540564
needs:
541-
- conventions
565+
- nuget_pkg
542566

543567
runs-on: ubuntu-22.04
544568
steps:

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ update-servers:
2222
nuget:
2323
@./scripts/make.sh nuget
2424

25+
push:
26+
@./scripts/make.sh push
27+
2528
sanitycheck:
2629
@./scripts/make.sh sanitycheck
2730

NuGet.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
<config>
44
<!-- TODO: file a VS4Mac bug about this below setting making the tests disappear from the Tests view -->
55
<add key="globalPackagesFolder" value="packages" />
6+
7+
<add key="defaultPushSource" value="https://api.nuget.org/v3/index.json" />
68
</config>
79
</configuration>

scripts/make.fsx

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open System.Linq
66
open System.Diagnostics
77

88
#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"
1010
#else
1111
#r "System.Configuration"
1212
open System.Configuration
@@ -30,6 +30,8 @@ let GTK_FRONTEND_APP = sprintf "%s.Frontend.XF.Gtk" PASCALCASE_NAME
3030
let CONSOLE_FRONTEND_APP = sprintf "%s.Frontend.ConsoleApp" PASCALCASE_NAME
3131
let BACKEND_LIB = sprintf "%s.Backend" PASCALCASE_NAME
3232

33+
let version = (Misc.GetCurrentVersion FsxHelper.RootDir).ToString()
34+
3335
type FrontendProject =
3436
| XF
3537
| Gtk
@@ -403,6 +405,7 @@ let GetPathToFrontend (frontend: FrontendApp) (binaryConfig: BinaryConfig): Dire
403405

404406
let GetPathToBackend () =
405407
Path.Combine (FsxHelper.RootDir.FullName, "src", BACKEND_LIB)
408+
|> DirectoryInfo
406409

407410
let MakeAll (maybeConstant: Option<string>) =
408411
#if LEGACY_FRAMEWORK
@@ -463,8 +466,6 @@ match maybeTarget with
463466
let zipCommand = "zip"
464467
MakeCheckCommand zipCommand
465468

466-
let version = (Misc.GetCurrentVersion FsxHelper.RootDir).ToString()
467-
468469
let release = BinaryConfig.Release
469470
let frontend,script = JustBuild release None
470471
let binDir = "bin"
@@ -623,7 +624,7 @@ match maybeTarget with
623624

624625
| Some "update-servers" ->
625626
let _,buildConfig = MakeAll None
626-
Directory.SetCurrentDirectory (GetPathToBackend())
627+
Directory.SetCurrentDirectory (GetPathToBackend().FullName)
627628
let proc1 = RunFrontend FrontendApp.Console buildConfig (Some "--update-servers-file")
628629
if proc1.ExitCode <> 0 then
629630
Environment.Exit proc1.ExitCode
@@ -663,6 +664,94 @@ match maybeTarget with
663664
Echo.All
664665
).UnwrapDefault() |> ignore<string>
665666

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+
666755
| Some(someOtherTarget) ->
667756
Console.Error.WriteLine("Unrecognized target: " + someOtherTarget)
668757
Environment.Exit 2

0 commit comments

Comments
 (0)