Skip to content

Commit

Permalink
CI: create snap beta for native segwit by default
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
2 people authored and knocte committed Jan 19, 2024
1 parent 99a29b4 commit 6498d0a
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 18 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ).
Expand Down
22 changes: 15 additions & 7 deletions scripts/bump.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions scripts/configure.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,6 +187,18 @@ let fsxRunner =
fsxRunnerBinText
buildConfigFile.Name

let AddToDefinedConstants (constant: string) (configMap: Map<string, string>) =
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)

Expand All @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion scripts/find.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion scripts/fsx
2 changes: 1 addition & 1 deletion scripts/sanitycheck.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/snap_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions scripts/snap_bump.fsx
Original file line number Diff line number Diff line change
@@ -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<string>
13 changes: 10 additions & 3 deletions scripts/snap_release.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
{
Expand Down
7 changes: 6 additions & 1 deletion src/GWallet.Backend/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6498d0a

Please sign in to comment.