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 #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -516,7 +516,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 @@ -551,7 +551,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
66 changes: 65 additions & 1 deletion scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ open System
open System.IO
open System.Linq
open System.Diagnostics
open System.Runtime.InteropServices


#if !LEGACY_FRAMEWORK
#r "nuget: Fsdk, Version=0.6.0--date20230818-1152.git-83d671b"
Expand Down Expand Up @@ -117,6 +119,17 @@ let prefix = buildConfigContents |> GetOrExplain "Prefix"
let libPrefixDir = DirectoryInfo (Path.Combine (prefix, "lib", UNIX_NAME))
let binPrefixDir = DirectoryInfo (Path.Combine (prefix, "bin"))


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 @@ -133,6 +146,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"
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

let NugetRestore (projectOrSolution: FileInfo) =
let nugetArgs =
Expand Down Expand Up @@ -581,6 +607,33 @@ match maybeTarget with
| _ ->
()
#endif
| Some "publish" ->
#if LEGACY_FRAMEWORK
failwith "Legacy frameworks don't support publish command"
#else
let buildConfig = BinaryConfig.Release
let frontend,_ = JustBuild buildConfig None

let projectFile =
Path.Combine (
FsxHelper.RootDir.FullName,
"src",
frontend.GetProjectName(),
frontend.GetProjectName() + ".fsproj")
|> FileInfo
let runtimeId = GetRuntimeId()
let publishCommand =
{
Command = "dotnet"
Arguments =
sprintf
"publish --configuration Release -property:PublishSingleFile=true --self-contained true --runtime %s %s"
runtimeId
projectFile.FullName
}
Process.Execute(publishCommand, Echo.All).UnwrapDefault()
|> ignore<string>
#endif

| Some("install") ->
let buildConfig = BinaryConfig.Release
Expand Down Expand Up @@ -608,7 +661,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, frontend.GetProjectName()) |> FileInfo
if not libDestDir.Exists then
libDestDir.Create()
executable.CopyTo(Path.Combine(libDestDir.FullName, frontend.GetProjectName()), 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 @@ -10,6 +10,10 @@ rm -rf ./staging

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

snapcraft --destructive-mode
22 changes: 13 additions & 9 deletions src/GWallet.Backend/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ module Config =

let internal GetConfigDirForThisProgram() =
let configPath =
(* NOTE: we used to support UWP via the Xamarin.Essentials code below, but MAUI is a higher priority than resurrecting UWP now:
if (not isWindows) || Xamarin.Essentials.DeviceInfo.Platform <> Xamarin.Essentials.DevicePlatform.UWP then
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
else //UWP
Xamarin.Essentials.FileSystem.AppDataDirectory
*)
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

// TODO: rename to "geewallet", following a similar approach as DAI->SAI rename
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"
(* NOTE: we used to support UWP via the Xamarin.Essentials code below, but MAUI is a higher priority than resurrecting UWP now:
if (not isWindows) || Xamarin.Essentials.DeviceInfo.Platform <> Xamarin.Essentials.DevicePlatform.UWP then
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
else //UWP
Xamarin.Essentials.FileSystem.AppDataDirectory
*)
| _ -> 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>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\GWallet.Backend\Properties\CommonAssemblyInfo.fs">
Expand Down
Loading