Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts,GitHubCI,Backend: add .NET6 snap #207

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ 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:
snap_pkg_mono:

needs:
- conventions
Expand Down Expand Up @@ -576,7 +576,37 @@ jobs:
- uses: actions/upload-artifact@v3
name: Upload snap package as artifact
with:
name: snap
name: snap-mono
path: ./*.snap

snap_pkg_dotnet:

needs:
- conventions

runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Install snap tools
run: |
sudo apt update
./scripts/install_snapcraft.sh

- name: Generate snap package
run: |
./scripts/snap_build.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: gwallet --version

- uses: actions/upload-artifact@v3
name: Upload snap package as artifact
with:
name: snap-dotnet
path: ./*.snap

- name: Upload snap package to Snap Store
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ check:

release:
@./scripts/make.sh release

publish:
@./scripts/make.sh publish

zip:
@./scripts/make.sh zip
Expand Down
62 changes: 61 additions & 1 deletion scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open System.IO
open System.Linq
open System.Diagnostics

open System.Runtime.InteropServices
open System.Text
open System.Text.RegularExpressions
#r "System.Core.dll"
Expand Down Expand Up @@ -102,6 +103,16 @@ let mainBinariesDir binaryConfig =
binaryConfig.ToString())
|> DirectoryInfo

let GetRuntimeId () =
let osName =
match Misc.GuessPlatform() with
| Misc.Platform.Linux -> "linux"
| Misc.Platform.Windows -> "win"
| Misc.Platform.Mac -> "osx"
let archName = RuntimeInformation.ProcessArchitecture.ToString().ToLower()
sprintf "%s-%s" osName archName

#if LEGACY_FRAMEWORK
let wrapperScript = """#!/usr/bin/env bash
set -eo pipefail

Expand All @@ -118,6 +129,19 @@ DIR_OF_THIS_SCRIPT=$(dirname "$(realpath "$0")")
FRONTEND_PATH="$DIR_OF_THIS_SCRIPT/../lib/$UNIX_NAME/$GWALLET_PROJECT.exe"
exec mono "$FRONTEND_PATH" "$@"
"""
#else
let wrapperScript = """#!/usr/bin/env bash
set -eo pipefail
DIR_OF_THIS_SCRIPT=$(dirname "$(realpath "$0")")
FRONTEND_PATH="$DIR_OF_THIS_SCRIPT/../lib/$UNIX_NAME/$GWALLET_PROJECT"
webwarrior-ws marked this conversation as resolved.
Show resolved Hide resolved
arch=$(uname -i)
if [ "$arch" != 'x86_64' ]; then
echo "$arch not supported (only x86_64 is supported for now), please file a bug"
exit 1
fi
exec "$FRONTEND_PATH" "$@"
"""
#endif

#if LEGACY_FRAMEWORK
let PrintNugetVersion () =
Expand Down Expand Up @@ -436,6 +460,31 @@ match maybeTarget with
Process.Execute(runnerCommand, Echo.All).UnwrapDefault()
|> ignore<string>

| Some "publish" ->
#if LEGACY_FRAMEWORK
failwith "Legacy frameworks don't support publish command"
#else
let projectFile =
Path.Combine (
FsxHelper.RootDir.FullName,
"src",
DEFAULT_FRONTEND,
DEFAULT_FRONTEND + ".fsproj")
webwarrior-ws marked this conversation as resolved.
Show resolved Hide resolved
|> FileInfo
let runtimeId = GetRuntimeId()
let publishCommand =
{
Command = "dotnet"
Arguments =
sprintf
"publish --configuration Release -property:PublishSingleFile=true --self-contained true --runtime %s %s"
webwarrior-ws marked this conversation as resolved.
Show resolved Hide resolved
runtimeId
projectFile.FullName
}
Process.Execute(publishCommand, Echo.All).UnwrapDefault()
|> ignore<string>
#endif

| Some("install") ->
let buildConfig = BinaryConfig.Release
JustBuild buildConfig None
Expand All @@ -455,7 +504,18 @@ match maybeTarget with

Console.WriteLine "Installing..."
Console.WriteLine ()
Misc.CopyDirectoryRecursively (mainBinariesDir buildConfig, libDestDir, [])

let publishDir =
Path.Combine ((mainBinariesDir buildConfig).FullName, "net6.0", GetRuntimeId(), "publish")
|> DirectoryInfo
if publishDir.Exists then
// single-file app
let executable = Path.Combine(publishDir.FullName, DEFAULT_FRONTEND) |> FileInfo
if not libDestDir.Exists then
libDestDir.Create()
executable.CopyTo(Path.Combine(libDestDir.FullName, DEFAULT_FRONTEND), true) |> ignore
else
Misc.CopyDirectoryRecursively (mainBinariesDir buildConfig, libDestDir, List.Empty)

let finalLauncherScriptInDestDir = Path.Combine(binDestDir.FullName, launcherScriptFile.Name) |> FileInfo
if not (Directory.Exists(finalLauncherScriptInDestDir.Directory.FullName)) then
Expand Down
4 changes: 4 additions & 0 deletions scripts/snap_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ DEBIAN_FRONTEND=noninteractive sudo apt install -y fsharp build-essential pkg-co

./configure.sh --prefix=./staging
make
if [ `which dotnet` ]
then
make publish
fi
make install

#this below is to prevent the possible error "Failed to reuse files from previous run: The 'pull' step of 'gwallet' is out of date: The source has changed on disk."
Expand Down
9 changes: 8 additions & 1 deletion src/GWallet.Backend/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ module Config =
let internal NUMBER_OF_RETRIES_TO_SAME_SERVERS = 3u

let internal GetConfigDirForThisProgram() =
let configPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
let configPath =
match Environment.GetEnvironmentVariable "SNAP" with
| snapVar when not (String.IsNullOrEmpty snapVar) ->
match Environment.GetEnvironmentVariable "HOME" with
| homeVar when not (String.IsNullOrEmpty homeVar) ->
homeVar + snapVar + ".config"
| _ -> failwith "$HOME environment variable is absent or empty"
| _ -> Environment.GetFolderPath Environment.SpecialFolder.ApplicationData
let configDir = DirectoryInfo(Path.Combine(configPath, "gwallet"))
if not configDir.Exists then
configDir.Create()
Expand Down
1 change: 1 addition & 0 deletions src/GWallet.Backend/GWallet.Backend.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\GWallet.Backend\Properties\CommonAssemblyInfo.fs">
Expand Down