From 261f79a62ee305c3077180702ef873577932ff73 Mon Sep 17 00:00:00 2001 From: Alex <15199219+muskit@users.noreply.github.com> Date: Mon, 1 Sep 2025 21:42:27 -0700 Subject: [PATCH] add workflows, app versioning --- .github/workflows/build.yml | 35 +++++++++++++++++++++++++++++ src/Assets/version | 1 + src/Data/Database.cs | 2 +- src/UI/Views/Export/Export.axaml.cs | 9 ++++---- src/Utility/Utils.cs | 26 +++++++++++++++++++-- 5 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 src/Assets/version diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..51ef31f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,35 @@ +name: Build and publish application + +on: workflow_run + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Get Application Version + run: | + echo "PKG_PREPEND=MercuryConverter-v$(cat src/Assets/version)" >> $GITHUB_ENV + + - name: Setup dotnet 9.0.x + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 9.0.x + + - name: Build for Linux + run: | + dotnet publish src --runtime linux-x64 -o "./builds/${{ env.PKG_PREPEND }}-linux-x64" + zip -r "${{ env.PKG_PREPEND }}-linux-x64.zip" "./builds/${{ env.PKG_PREPEND }}-linux-x64" + + - name: Build for Windows + run: | + dotnet publish src --runtime win-x64 -o "./builds/${{ env.PKG_PREPEND }}-windows-x64" + zip -r "${{ env.PKG_PREPEND }}-windows-x64.zip" "./builds/${{ env.PKG_PREPEND }}-windows-x64" + + - name: Create Release + uses: ncipollo/release-action@v1.19.1 + with: + allowUpdates: true + commit: main + artifacts: "${{ env.PKG_PREPEND }}-linux-x64.zip, ${{ env.PKG_PREPEND }}-windows-x64.zip" \ No newline at end of file diff --git a/src/Assets/version b/src/Assets/version new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/src/Assets/version @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/src/Data/Database.cs b/src/Data/Database.cs index fee4772..4d24e6a 100644 --- a/src/Data/Database.cs +++ b/src/Data/Database.cs @@ -39,7 +39,7 @@ public static class Database { AudioPaths.Clear(); - using (var reader = new StreamReader(Utils.AssetPath("awb.csv"))) + using (var reader = new StreamReader(Utils.GetAsset("awb.csv"))) { string? line; while ((line = reader.ReadLine()) != null) diff --git a/src/UI/Views/Export/Export.axaml.cs b/src/UI/Views/Export/Export.axaml.cs index 1e35d2c..ab1f929 100644 --- a/src/UI/Views/Export/Export.axaml.cs +++ b/src/UI/Views/Export/Export.axaml.cs @@ -27,10 +27,10 @@ public partial class ExportRow : ObservableObject { private static Dictionary StatusImgs = new() { - { ExportStatus.Working, new Bitmap(Utils.AssetPath("imgs/status/indeterminate_spinner.png")) }, - { ExportStatus.Error, new Bitmap(Utils.AssetPath("imgs/status/task_error.png")) }, - { ExportStatus.Finished, new Bitmap(Utils.AssetPath("imgs/status/task_complete.png")) }, - { ExportStatus.FinishedWithMessages, new Bitmap(Utils.AssetPath("imgs/status/task_alert.png")) }, + { ExportStatus.Working, new Bitmap(Utils.GetAsset("imgs/status/indeterminate_spinner.png")) }, + { ExportStatus.Error, new Bitmap(Utils.GetAsset("imgs/status/task_error.png")) }, + { ExportStatus.Finished, new Bitmap(Utils.GetAsset("imgs/status/task_complete.png")) }, + { ExportStatus.FinishedWithMessages, new Bitmap(Utils.GetAsset("imgs/status/task_alert.png")) }, }; [ObservableProperty] @@ -111,7 +111,6 @@ public partial class Export : Panel { if (Exporting) return; - Console.WriteLine("Updating rows!"); Rows.Clear(); if ((bool)RadioExportAll.IsChecked!) diff --git a/src/Utility/Utils.cs b/src/Utility/Utils.cs index 9db9116..3ddb6f3 100644 --- a/src/Utility/Utils.cs +++ b/src/Utility/Utils.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Platform; @@ -49,7 +50,7 @@ public static class Utils /// /// Forward-slash (/)-separated path to asset. /// - public static Stream AssetPath(string path) => AssetLoader.Open(new Uri("avares://MercuryConverter/Assets/" + path)); + public static Stream GetAsset(string path) => AssetLoader.Open(new Uri(Path.Combine("avares://MercuryConverter/Assets/", path))); public static string IIDToMusicFilePath(uint id) { @@ -82,10 +83,14 @@ public static class Utils Console.WriteLine($"Could not find FFmpeg on PATH!"); _ffmpegAvailable = false; } + catch (Exception ex) + { + Console.WriteLine($"Something's wrong with FFmpeg!\n{ex.Message}"); + _ffmpegAvailable = false; + } Console.WriteLine($"FFmpeg available: {_ffmpegAvailable}"); } - return (bool)_ffmpegAvailable!; } } @@ -94,4 +99,21 @@ public static class Utils { return string.Concat(filename.Split(['/', '\\', '\"', '\''])); } + + private static string? _version = null; + public static string VERSION + { + get + { + if (_version == null) + { + using (StreamReader reader = new(GetAsset("version"))) + { + _version = reader.ReadToEnd(); + } + _version = _version.Trim(); + } + return _version!; + } + } } \ No newline at end of file