diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index aaf81ed89..ebe5556f2 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -490,11 +490,39 @@ jobs: if: github.event_name == 'pull_request' run: ./conventions/commitlint.sh --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose - snap_pkg: - + nuget_pkg_beta: needs: - conventions + runs-on: ubuntu-22.04 + container: + image: "ubuntu:22.04" + + env: + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + + steps: + - uses: actions/checkout@v1 + - name: install sudo + run: apt update && apt install --yes sudo + - name: install all dependencies + run: sudo DEBIAN_FRONTEND=noninteractive apt install --yes git make dotnet6 + # workaround for https://github.com/actions/runner/issues/2033 + - name: ownership workaround + run: git config --global --add safe.directory '*' + - name: configure + run: ./configure.sh --native-segwit + - name: Bump version to beta (because segwit) + run: | + ./scripts/populate_gitsubmodules.sh + dotnet fsi ./scripts/beta_bump.fsx + - name: pack&push + run: make push + + snap_pkg: + needs: + - nuget_pkg_beta + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v1 @@ -538,7 +566,7 @@ jobs: snap_pkg_beta: needs: - - conventions + - nuget_pkg_beta runs-on: ubuntu-22.04 steps: @@ -557,8 +585,8 @@ jobs: - name: Bump snap version run: | - git submodule foreach git fetch --all && git submodule sync --recursive && git submodule update --init --recursive - dotnet fsi ./scripts/snap_bump.fsx + ./scripts/populate_gitsubmodules.sh + dotnet fsi ./scripts/beta_bump.fsx - name: Generate snap package run: | diff --git a/Makefile b/Makefile index 45cf347b2..f142dd7c1 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ update-servers: nuget: @./scripts/make.sh nuget +push: + @./scripts/make.sh push + sanitycheck: @./scripts/make.sh sanitycheck diff --git a/NuGet.config b/NuGet.config index a7bdafbdc..49b5c3d98 100644 --- a/NuGet.config +++ b/NuGet.config @@ -3,5 +3,7 @@ + + diff --git a/configure.sh b/configure.sh index 47ae0674a..a252d5b86 100755 --- a/configure.sh +++ b/configure.sh @@ -14,16 +14,7 @@ else cp NuGet-legacy.config NuGet.config - if [ ! -f scripts/fsx/configure.sh ]; then - if ! which git >/dev/null 2>&1; then - echo "checking for git... not found" $'\n' - - echo "$0" $'failed, please install "git" (to populate submodule) first' - exit 1 - fi - echo "Populating sub-fsx module..." - git submodule sync --recursive && git submodule update --init --recursive - fi + ./scripts/populate_gitsubmodules.sh FSX_CHECK_MSG="checking for fsx..." if ! which fsharpi >/dev/null 2>&1; then diff --git a/scripts/snap_bump.fsx b/scripts/beta_bump.fsx similarity index 100% rename from scripts/snap_bump.fsx rename to scripts/beta_bump.fsx diff --git a/scripts/bump.fsx b/scripts/bump.fsx index 73159c347..d43c53e1e 100755 --- a/scripts/bump.fsx +++ b/scripts/bump.fsx @@ -260,7 +260,7 @@ let RunUpdateServers () = if not replaceScript.Exists then - Console.Error.WriteLine "Script replace.fsx not found, 'fsx' submodule not populated? Please run `git submodule foreach git fetch --all && git submodule sync --recursive && git submodule update --init --recursive`" + Console.Error.WriteLine "Script replace.fsx not found, 'fsx' submodule not populated? Please run `populate_gitsubmodules.sh`" Environment.Exit 1 GitDiff() diff --git a/scripts/make.fsx b/scripts/make.fsx index 02bbcf50b..afa24745e 100644 --- a/scripts/make.fsx +++ b/scripts/make.fsx @@ -6,7 +6,7 @@ open System.Linq open System.Diagnostics #if !LEGACY_FRAMEWORK -#r "nuget: Fsdk, Version=0.6.0--date20230818-1152.git-83d671b" +#r "nuget: Fsdk, Version=0.6.0--date20240306-1035.git-a0a5c67" #else #r "System.Configuration" open System.Configuration @@ -30,6 +30,8 @@ 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 currentVersion = Misc.GetCurrentVersion FsxHelper.RootDir + type FrontendProject = | XF | Gtk @@ -172,19 +174,7 @@ let PrintNugetVersion () = Console.Out.Flush() failwith "nuget process' output contained errors ^" -let BuildSolutionOrProject - (buildToolAndBuildArg: string*string) - (file: FileInfo) - (binaryConfig: BinaryConfig) - (maybeConstant: Option) - (extraOptions: string) - = -#if LEGACY_FRAMEWORK - NugetRestore file -#endif - - let buildTool,buildArg = buildToolAndBuildArg - +let GetBuildFlags (buildTool: string) (binaryConfig) (maybeConstant: Option) = let configOption = if buildTool.StartsWith "dotnet" then sprintf "--configuration %s" (binaryConfig.ToString()) @@ -233,6 +223,24 @@ let BuildSolutionOrProject sprintf "%s -property:DefineConstants=\\\"%s\\\"" configOption (String.Join(semiColon, defineConstants)) else configOption + + configOptions + +let BuildSolutionOrProject + (buildToolAndBuildArg: string*string) + (file: FileInfo) + (binaryConfig: BinaryConfig) + (maybeConstant: Option) + (extraOptions: string) + = +#if LEGACY_FRAMEWORK + NugetRestore file +#endif + + let buildTool,buildArg = buildToolAndBuildArg + + let configOptions = GetBuildFlags buildTool binaryConfig maybeConstant + let buildArgs = sprintf "%s %s %s %s" buildArg file.FullName @@ -403,6 +411,7 @@ let GetPathToFrontend (frontend: FrontendApp) (binaryConfig: BinaryConfig): Dire let GetPathToBackend () = Path.Combine (FsxHelper.RootDir.FullName, "src", BACKEND_LIB) + |> DirectoryInfo let MakeAll (maybeConstant: Option) = #if LEGACY_FRAMEWORK @@ -463,14 +472,12 @@ match maybeTarget with let zipCommand = "zip" MakeCheckCommand zipCommand - let version = (Misc.GetCurrentVersion FsxHelper.RootDir).ToString() - let release = BinaryConfig.Release let frontend,script = JustBuild release None 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 @@ -623,7 +630,7 @@ match maybeTarget with | Some "update-servers" -> let _,buildConfig = MakeAll None - Directory.SetCurrentDirectory (GetPathToBackend()) + Directory.SetCurrentDirectory (GetPathToBackend().FullName) let proc1 = RunFrontend FrontendApp.Console buildConfig (Some "--update-servers-file") if proc1.ExitCode <> 0 then Environment.Exit proc1.ExitCode @@ -663,6 +670,115 @@ match maybeTarget with Echo.All ).UnwrapDefault() |> ignore +| Some "push" -> +#if LEGACY_FRAMEWORK + Console.Error.WriteLine "Pushing a nuget package is not supported with .NET legacy or Mono" + Environment.Exit 1 +#else + let githubRef = Environment.GetEnvironmentVariable "GITHUB_REF" + if isNull githubRef then + Console.Error.WriteLine "Pushing a nuget package is only meant for GitHub CI jobs" + Environment.Exit 1 + + let tagPrefix = "refs/tags/" + let masterBranchRef = "refs/heads/master" + let isTag = + githubRef.StartsWith tagPrefix + + let backendDir = GetPathToBackend() + let backendProj = Path.Combine(backendDir.FullName, BACKEND_LIB + ".fsproj") + + 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 + + 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 + else + let push() = + Process.Execute( + { + Command = "dotnet" + Arguments = sprintf "nuget push --api-key %s %s" nugetApiKey nupkg + }, + Echo.All + ).UnwrapDefault() |> ignore + + let eventName = Environment.GetEnvironmentVariable "GITHUB_EVENT_NAME" + if isNull eventName then + failwith "Env var 'GITHUB_EVENT_NAME' not set; not running as GitHubActions job?" + if eventName <> "push" then + Console.WriteLine "GitHubActions event not 'push', skipping..." + Environment.Exit 0 + + if isTag then + push() + else + if githubRef <> masterBranchRef then + Console.WriteLine "Pushed to non-master branch, skipping..." + Environment.Exit 0 + + let commitHash = Environment.GetEnvironmentVariable "GITHUB_SHA" + if isNull commitHash then + failwith "Env var 'GITHUB_SHA' not set; not running as GitHubActions job?" + let gitArgs = sprintf "describe --exact-match --tags %s" commitHash + let gitProcRes = + Process.Execute( + { + Command = "git" + Arguments = gitArgs + }, + Echo.All + ).Result + match gitProcRes with + | ProcessResultState.Success _ -> + Console.WriteLine "Commit mapped to a tag, skipping pushing prerelease..." + Environment.Exit 0 + | ProcessResultState.Error _ -> + push() + | _ -> + failwith "warning from git command?" +#endif + | Some(someOtherTarget) -> Console.Error.WriteLine("Unrecognized target: " + someOtherTarget) Environment.Exit 2 diff --git a/scripts/populate_gitsubmodules.sh b/scripts/populate_gitsubmodules.sh new file mode 100755 index 000000000..ca1bc672c --- /dev/null +++ b/scripts/populate_gitsubmodules.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +if ! which git >/dev/null 2>&1; then + echo "checking for git... not found" $'\n' + + echo "$0" $'failed, please install "git" (to populate submodules) first' + exit 1 +fi +echo "Populating git submodules..." + +git submodule foreach git fetch --all && git submodule sync --recursive && git submodule update --init --recursive