From 6498d0acee277aefbfbdadca41fea32530dde67f Mon Sep 17 00:00:00 2001 From: Afshin Arani Date: Tue, 31 Oct 2023 13:23:42 +0330 Subject: [PATCH] CI: create snap beta for native segwit by default This commit aims to create beta snap packages to allow testing experimental features like native segwit. This commit also updates Fsdk inside our scripts because the `GatherOrGetDefaultPrefix` function in the previous version did not allow additional arguments beside --prefix. A flag called --auto was also added for bypassing the "press any key" in bump.fsx. Co-authored-by: Mehrshad --- .github/workflows/CI.yml | 50 +++++++++++++++++++++++++++++++++++ ReadMe.md | 2 +- scripts/bump.fsx | 22 ++++++++++----- scripts/configure.fsx | 26 ++++++++++++++++-- scripts/find.fsx | 2 +- scripts/fsx | 2 +- scripts/sanitycheck.fsx | 2 +- scripts/snap_build.sh | 2 +- scripts/snap_bump.fsx | 33 +++++++++++++++++++++++ scripts/snap_release.fsx | 13 ++++++--- src/GWallet.Backend/Config.fs | 7 ++++- 11 files changed, 143 insertions(+), 18 deletions(-) create mode 100644 scripts/snap_bump.fsx diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index fba5af706..aaf81ed89 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -534,3 +534,53 @@ jobs: run: | sudo apt update ./scripts/snap_release.sh + + snap_pkg_beta: + + needs: + - conventions + + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v1 + - name: Install snap tools + run: | + sudo apt update + ./scripts/install_snapcraft.sh + + # hack to disable msbuild detection + # NOTE: you might think an easier way to do this would be use container:\nimage: ubuntu22.04 and then not install msbuild, + # but that doesn't work because we get the following error when trying to install snapcraft via `snap install --classic`: + # > error: cannot communicate with server: Post "http://localhost/v2/snaps/snapcraft": dial unix /run/snapd.socket: connect: no such file or directory + - name: HACK to emulate msbuild uninstall + run: sudo rm `which msbuild` + + - 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 + + - name: Generate snap package + run: | + # retry 3 times because of flakey nuget; TODO: remove retry when we migrate to .NET6 (removing LEGACY_FRAMEWORK support) + ./scripts/snap_build.sh --native-segwit || ./scripts/snap_build.sh --native-segwit || ./scripts/snap_build.sh --native-segwit || ./scripts/snap_build.sh --native-segwit + + - name: Install snap + # dangerous because it's a local snap (not one from the SnapStore) + run: sudo snap install --dangerous *.snap + + - name: Test snap + run: geewallet --version + + - uses: actions/upload-artifact@v3 + name: Upload snap package as artifact + with: + name: snap_beta + path: ./*.snap + + - name: Upload snap package to Snap Store + env: + SNAPCRAFT_LOGIN: ${{ secrets.SNAPCRAFT_LOGIN }} + run: | + sudo apt update + ./scripts/snap_release.sh beta diff --git a/ReadMe.md b/ReadMe.md index ae8fe90fc..d72f96ec8 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -63,7 +63,7 @@ In the development side of things, we advocate for simplicity: This list is the (intended) order of preference for new features: - Migration from Xamarin.Forms to MAUI (in progress, see the PR#199 or its successor). -- Switch from SegWit to native-SegWit (Bech32): PR#211. +- Make native-SegWit (Bech32) be default for bitcoin (right now this is the case for the beta version of our snap package). - Support for payment-channels & state-channels (in BTC/LTC via lightning, see 'lightning' branch; and in ETH/ETC/DAI via Connext?). - Explore better stablecoin approach than L1-DAI because DAI is not 100% decentralized (e.g. LUSD better?) and because L1 is too high fees (e.g. sDAI better? see https://twitter.com/koeppelmann/status/1736766570825654630 ). - Automatic reminders for Seed/password checks to make sure user has not forgotten them (see https://twitter.com/takinbo/status/1201529679519330305 ). diff --git a/scripts/bump.fsx b/scripts/bump.fsx index 405da8ffc..101b2ba5a 100755 --- a/scripts/bump.fsx +++ b/scripts/bump.fsx @@ -4,7 +4,7 @@ open System open System.IO #if !LEGACY_FRAMEWORK -#r "nuget: Fsdk, Version=0.6.0--date20230812-0646.git-2268d50" +#r "nuget: Fsdk, Version=0.6.0--date20231031-0834.git-2737eea" #else #r "System.Configuration" open System.Configuration @@ -21,15 +21,18 @@ let IsStable miniVersion = (int miniVersion % 2) = 0 let args = Misc.FsxOnlyArguments() + +let isAuto = List.contains "--auto" args + let suppliedVersion = if args.Length > 0 then - if args.Length > 1 then - Console.Error.WriteLine "Only one argument supported, not more" + if args.Length > 2 then + Console.Error.WriteLine "Only two argument supported, not more" Environment.Exit 1 failwith "Unreachable" else let full = Version(args.Head) - if not (IsStable full.Build) then + if (not isAuto) && not (IsStable full.Build) then Console.Error.WriteLine "Mini-version (previous-to-last number, e.g. 2 in 0.1.2.3) should be an even (stable) number" Environment.Exit 2 failwith "Unreachable" @@ -263,14 +266,19 @@ if not replaceScript.Exists then GitDiff() Console.WriteLine "Bumping..." -RunUpdateServers() +if not isAuto then + RunUpdateServers() let fullUnstableVersion,newFullStableVersion = Bump true -GitCommit fullUnstableVersion newFullStableVersion -GitTag newFullStableVersion +if not isAuto then + GitCommit fullUnstableVersion newFullStableVersion + GitTag newFullStableVersion Console.WriteLine (sprintf "Version bumped to %s." (newFullStableVersion.ToString())) +if isAuto then + Environment.Exit 0 + if isReleaseManual then Console.WriteLine "Release binaries now and press any key when you finish." Console.ReadKey true |> ignore diff --git a/scripts/configure.fsx b/scripts/configure.fsx index 28c0ebcec..b3638aabd 100644 --- a/scripts/configure.fsx +++ b/scripts/configure.fsx @@ -4,7 +4,7 @@ open System open System.IO #if !LEGACY_FRAMEWORK -#r "nuget: Fsdk, Version=0.6.0--date20230812-0646.git-2268d50" +#r "nuget: Fsdk, Version=0.6.0--date20231031-0834.git-2737eea" #else #r "System.Configuration" open System.Configuration @@ -187,6 +187,18 @@ let fsxRunner = fsxRunnerBinText buildConfigFile.Name +let AddToDefinedConstants (constant: string) (configMap: Map) = + let configKey = "DefineConstants" + + match configMap.TryFind configKey with + | None -> + configMap + |> Map.add configKey constant + | Some previousConstants -> + configMap + |> Map.add configKey (sprintf "%s;%s" previousConstants constant) + + let configFileToBeWritten = let initialConfigFile = Map.empty.Add("Prefix", prefix.FullName) @@ -195,11 +207,21 @@ let configFileToBeWritten = | Some theTool -> initialConfigFile.Add("LegacyBuildTool", theTool) | None -> initialConfigFile - let finalConfigFile = + let configFileStageThree = match buildTool with | Some theTool -> configFileStageTwo.Add("BuildTool", theTool) | None -> configFileStageTwo + let finalConfigFile = + let nativeSegwitEnabled = + Misc.FsxOnlyArguments() + |> List.contains "--native-segwit" + if nativeSegwitEnabled then + configFileStageThree + |> AddToDefinedConstants "NATIVE_SEGWIT" + else + configFileStageThree + finalConfigFile let lines = diff --git a/scripts/find.fsx b/scripts/find.fsx index f39abb2a6..16a16b4ec 100755 --- a/scripts/find.fsx +++ b/scripts/find.fsx @@ -5,7 +5,7 @@ open System.IO open System.Linq #if !LEGACY_FRAMEWORK -#r "nuget: Fsdk, Version=0.6.0--date20230812-0646.git-2268d50" +#r "nuget: Fsdk, Version=0.6.0--date20231031-0834.git-2737eea" #else #r "System.Configuration" #load "fsx/Fsdk/Misc.fs" diff --git a/scripts/fsx b/scripts/fsx index 5488853b1..2737eea87 160000 --- a/scripts/fsx +++ b/scripts/fsx @@ -1 +1 @@ -Subproject commit 5488853b17fedb44707e8459480297b618cffad0 +Subproject commit 2737eea87f6bd4becda5c172c208314af044184a diff --git a/scripts/sanitycheck.fsx b/scripts/sanitycheck.fsx index 6d83643af..3506ba182 100755 --- a/scripts/sanitycheck.fsx +++ b/scripts/sanitycheck.fsx @@ -14,7 +14,7 @@ open System.Xml.Linq open System.Xml.XPath #if !LEGACY_FRAMEWORK -#r "nuget: Fsdk, Version=0.6.0--date20230812-0646.git-2268d50" +#r "nuget: Fsdk, Version=0.6.0--date20231031-0834.git-2737eea" #else #r "System.Configuration" open System.Configuration diff --git a/scripts/snap_build.sh b/scripts/snap_build.sh index 2a6c07e3a..3196aa8db 100755 --- a/scripts/snap_build.sh +++ b/scripts/snap_build.sh @@ -8,7 +8,7 @@ DEBIAN_FRONTEND=noninteractive sudo apt install -y fsharp build-essential pkg-co # just in case this is a retry-run, we want to clean artifacts from previous try rm -rf ./staging -./configure.sh --prefix=./staging +./configure.sh --prefix=./staging "$@" make make install diff --git a/scripts/snap_bump.fsx b/scripts/snap_bump.fsx new file mode 100644 index 000000000..6be82a814 --- /dev/null +++ b/scripts/snap_bump.fsx @@ -0,0 +1,33 @@ +#!/usr/bin/env fsharpi + +open System +open System.IO + +#if !LEGACY_FRAMEWORK +#r "nuget: Fsdk, Version=0.6.0--date20231031-0834.git-2737eea" +#else +#r "System.Configuration" +open System.Configuration + +#load "fsx/Fsdk/Misc.fs" +#load "fsx/Fsdk/Process.fs" +#load "fsx/Fsdk/Git.fs" +#endif +open Fsdk +open Fsdk.Process + +#load "fsxHelper.fs" +open GWallet.Scripting + +let currentVersion = Misc.GetCurrentVersion(FsxHelper.RootDir) + +let newVersion = + // e.g. to bump from 0.7.x.y to 0.9.x.y + Version(currentVersion.Major, currentVersion.Minor + 2, currentVersion.Build, currentVersion.Revision).ToString() + +Process.Execute( + { + Command = "dotnet" + Arguments = sprintf "fsi %s %s --auto" (Path.Combine(FsxHelper.ScriptsDir.FullName, "bump.fsx")) newVersion + }, Echo.All +).UnwrapDefault() |> ignore diff --git a/scripts/snap_release.fsx b/scripts/snap_release.fsx index b8cf74b5e..06cfa08b0 100755 --- a/scripts/snap_release.fsx +++ b/scripts/snap_release.fsx @@ -15,7 +15,7 @@ open System.Xml.Linq open System.Xml.XPath #if !LEGACY_FRAMEWORK -#r "nuget: Fsdk, Version=0.6.0--date20230812-0646.git-2268d50" +#r "nuget: Fsdk, Version=0.6.0--date20231031-0834.git-2737eea" #else #r "System.Configuration" open System.Configuration @@ -149,8 +149,15 @@ Process.Execute({ Command = "snapcraft"; Arguments = "login --with snapcraft.log Console.WriteLine "Login successfull. Upload starting..." let snapPush = - // the 'stable' and 'candidate' channels require 'stable' grade in the yaml - let channel = "stable" + let channel = + match Misc.FsxOnlyArguments() with + | [ channel ] -> + channel + | [] -> + // the 'stable' and 'candidate' channels require 'stable' grade in the yaml + "stable" + | _ -> + failwith "Invalid arguments" Process.Execute( { diff --git a/src/GWallet.Backend/Config.fs b/src/GWallet.Backend/Config.fs index 50668dcc5..17c213bd9 100644 --- a/src/GWallet.Backend/Config.fs +++ b/src/GWallet.Backend/Config.fs @@ -34,7 +34,12 @@ module Config = // balances, so you might find discrepancies (e.g. the donut-chart-view) let internal NoNetworkBalanceForDebuggingPurposes = false - let internal UseNativeSegwit = false + let internal UseNativeSegwit = +#if NATIVE_SEGWIT + true +#else + false +#endif let IsWindowsPlatform() = RuntimeInformation.IsOSPlatform OSPlatform.Windows