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.

Co-authored-by: Mehrshad <[email protected]>
  • Loading branch information
aarani and Mersho committed Nov 21, 2023
1 parent 02b80aa commit b926411
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 16 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
24 changes: 18 additions & 6 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,10 +21,17 @@ let IsStable miniVersion =
(int miniVersion % 2) = 0

let args = Misc.FsxOnlyArguments()

let isAuto =
if args |> List.contains "--auto" then
true
else
false

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
Expand Down Expand Up @@ -263,14 +270,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
32 changes: 32 additions & 0 deletions scripts/snap_bump.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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 =
Version(currentVersion.Major, currentVersion.Minor + 2, currentVersion.Build + 1, 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 b926411

Please sign in to comment.