Skip to content

Commit

Permalink
WIP: native-segwit snap
Browse files Browse the repository at this point in the history
  • Loading branch information
aarani committed Oct 31, 2023
1 parent f17d251 commit a8f8e91
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 10 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,48 @@ 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: 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_beta.sh || ./scripts/snap_build_beta.sh || ./scripts/snap_build_beta.sh || ./scripts/snap_build_beta.sh
- 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
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 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 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/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ let GetOrExplain key map =
let prefix = buildConfigContents |> GetOrExplain "Prefix"
let libPrefixDir = DirectoryInfo (Path.Combine (prefix, "lib", UNIX_NAME))
let binPrefixDir = DirectoryInfo (Path.Combine (prefix, "bin"))

let wrapperScript = """#!/usr/bin/env bash
set -eo pipefail
Expand Down
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
15 changes: 15 additions & 0 deletions scripts/snap_build_beta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euxo pipefail

# this is the equivalent of using the 'build-packages' (not stage-packages) section in snapcraft
# but as we're not using the 'make' plugin, we need to this manually now
DEBIAN_FRONTEND=noninteractive sudo apt install -y fsharp build-essential pkg-config cli-common-dev mono-devel libgtk2.0-cil-dev dotnet6

# just in case this is a retry-run, we want to clean artifacts from previous try
rm -rf ./staging

./configure.sh --native-segwit --prefix=./staging
make
make install

snapcraft --destructive-mode
13 changes: 11 additions & 2 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 @@ -150,10 +150,19 @@ Console.WriteLine "Login successfull. Upload starting..."

// the 'stable' and 'candidate' channels require 'stable' grade in the yaml
let snapPush =
let channel =
match Misc.FsxOnlyArguments() with
| [ channel ] ->
channel
| [] ->
"stable"
| _ ->
failwith "Invalid arguments"

Process.Execute(
{
Command = "snapcraft"
Arguments = sprintf "upload %s --release=stable" snapFile.FullName
Arguments = sprintf "upload %s --release=%s" snapFile.FullName channel
}, Echo.All
)

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 a8f8e91

Please sign in to comment.