From f7322be6447c946626469aa3185a7dcd88b62b36 Mon Sep 17 00:00:00 2001 From: Summpot Date: Sun, 22 Sep 2024 21:39:03 +0800 Subject: [PATCH] Versioning (#527) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update * Use GitInfo * Update ci * Update * resolve * add v prefix * update * 修复问题 * disable push build --------- Co-authored-by: Poker --- .github/workflows/build.yml | 98 +++++----- .github/workflows/release.yml | 2 +- nuget.config | 4 +- src/Pixeval.Controls/Pixeval.Controls.csproj | 12 +- .../Net/PixivApiHttpMessageHandler.cs | 2 +- .../Pixeval.Utilities.csproj | 2 +- .../Threading/ReenterableAwaiter{T}.cs | 6 +- src/Pixeval/AppManagement/Versioning.cs | 18 +- src/Pixeval/Pages/SuggestionModel.cs | 11 +- src/Pixeval/Pixeval - Backup.csproj | 184 ------------------ src/Pixeval/Pixeval.csproj | 51 +++-- src/Pixeval/Util/UI/UIHelper.cs | 15 +- 12 files changed, 109 insertions(+), 296 deletions(-) delete mode 100644 src/Pixeval/Pixeval - Backup.csproj diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ff095b9..2f650840 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,19 +1,17 @@ -name: Pixeval Build Pipeline +name: Build on: # push: # branches-ignore: - # - 'dependabot**' + # - "dependabot**" # tags-ignore: - # - '**' + # - "**" pull_request: paths-ignore: - - '**.md' - - '.builds/**' - - '.specs/**' - schedule: - - cron: '0 0 * * *' - + - "**.md" + - ".builds/**" + - ".specs/**" + defaults: run: shell: pwsh @@ -26,56 +24,56 @@ jobs: fail-fast: true matrix: configuration: [Release] - platform: ['x64','x86','arm64'] + platform: ["x64", "x86", "arm64"] env: - SOLUTION_NAME: 'Pixeval.sln' - PACKAGE_PROJECT_NAME: 'src/Pixeval/Pixeval.csproj' + SOLUTION_NAME: "Pixeval.sln" + PACKAGE_PROJECT_NAME: "src/Pixeval/Pixeval.csproj" PROJECT_RESTORE_PLATFORM: "x64" CONFIGURATION: ${{ matrix.configuration }} PLATFORM: ${{ matrix.platform }} DEFAULT_DIR: ${{ github.workspace }} # Default: D:\a\Pixeval\Pixeval\ APPX_PACKAGE_DIR: ${{ github.workspace }}\AppxPackages steps: - - name: Checkout the repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup MSBuild - id: setup_msbuild - uses: microsoft/setup-msbuild@v1 + - name: Checkout the repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Setup NuGet - id: setup-nuget - uses: NuGet/setup-nuget@v1.1.1 + - name: Setup MSBuild + id: setup_msbuild + uses: microsoft/setup-msbuild@v1 - - name: Setup .NET 8 - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '8.0.x' - - - name: Restore Files - id: restore_project - shell: pwsh - run: | - msbuild $env:SOLUTION_NAME ` - -t:Restore ` - -p:Platform=$env:PROJECT_RESTORE_PLATFORM ` - -p:Configuration=$env:CONFIGURATION ` - -p:PublishReadyToRun=true ` + - name: Setup NuGet + id: setup-nuget + uses: NuGet/setup-nuget@v1.1.1 - - name: Restore NuGet - id: restore_nuget - shell: pwsh - run: 'nuget restore $env:SOLUTION_NAME' + - name: Setup .NET 8 + uses: actions/setup-dotnet@v3 + with: + dotnet-version: "8.0.x" - - name: Build Files (Release) - id: build_app_with_release - shell: pwsh - run: | - msbuild $env:PACKAGE_PROJECT_NAME ` - -t:Build ` - -p:Platform=$env:PLATFORM ` - -p:Configuration=$env:CONFIGURATION ` - -p:AppxBundle=Never ` + - name: Restore Files + id: restore_project + shell: pwsh + run: | + msbuild $env:SOLUTION_NAME ` + -t:Restore ` + -p:Platform=$env:PROJECT_RESTORE_PLATFORM ` + -p:Configuration=$env:CONFIGURATION ` + -p:PublishReadyToRun=true ` + + - name: Restore NuGet + id: restore_nuget + shell: pwsh + run: "nuget restore $env:SOLUTION_NAME" + + - name: Build Files (Release) + id: build_app_with_release + shell: pwsh + run: | + msbuild $env:PACKAGE_PROJECT_NAME ` + -t:Build ` + -p:Platform=$env:PLATFORM ` + -p:Configuration=$env:CONFIGURATION ` + -p:AppxBundle=Never ` diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a9a9c5a2..557720cd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -88,4 +88,4 @@ jobs: uses: shogo82148/actions-upload-release-asset@v1 with: upload_url: ${{ needs.create_release.outputs.release_upload_url }} - asset_path: ./output/* \ No newline at end of file + asset_path: ./output/* diff --git a/nuget.config b/nuget.config index b635d72d..655bf331 100644 --- a/nuget.config +++ b/nuget.config @@ -1,7 +1,9 @@  + - + \ No newline at end of file diff --git a/src/Pixeval.Controls/Pixeval.Controls.csproj b/src/Pixeval.Controls/Pixeval.Controls.csproj index 729b9e52..6fdaf505 100644 --- a/src/Pixeval.Controls/Pixeval.Controls.csproj +++ b/src/Pixeval.Controls/Pixeval.Controls.csproj @@ -26,12 +26,12 @@ - - - - - - + + + + + + diff --git a/src/Pixeval.CoreApi/Net/PixivApiHttpMessageHandler.cs b/src/Pixeval.CoreApi/Net/PixivApiHttpMessageHandler.cs index af8a2173..eb58e4c6 100644 --- a/src/Pixeval.CoreApi/Net/PixivApiHttpMessageHandler.cs +++ b/src/Pixeval.CoreApi/Net/PixivApiHttpMessageHandler.cs @@ -47,7 +47,7 @@ internal class PixivApiHttpMessageHandler(MakoClient makoClient) : MakoClientSup headers.Authorization = new AuthenticationHeaderValue("Bearer", MakoClient.Session.AccessToken); break; case MakoHttpOptions.WebApiHost: - headers.TryAddWithoutValidation("Cookie", makoClient.Configuration.Cookie); + _ = headers.TryAddWithoutValidation("Cookie", MakoClient.Configuration.Cookie); break; } diff --git a/src/Pixeval.Utilities/Pixeval.Utilities.csproj b/src/Pixeval.Utilities/Pixeval.Utilities.csproj index 2b6b1494..f15139fa 100644 --- a/src/Pixeval.Utilities/Pixeval.Utilities.csproj +++ b/src/Pixeval.Utilities/Pixeval.Utilities.csproj @@ -8,6 +8,6 @@ true - + diff --git a/src/Pixeval.Utilities/Threading/ReenterableAwaiter{T}.cs b/src/Pixeval.Utilities/Threading/ReenterableAwaiter{T}.cs index 1828ff58..3437d7f3 100644 --- a/src/Pixeval.Utilities/Threading/ReenterableAwaiter{T}.cs +++ b/src/Pixeval.Utilities/Threading/ReenterableAwaiter{T}.cs @@ -134,5 +134,9 @@ public class ReenterableAwaiter(bool initialSignal, TResult resultIniti public ReenterableAwaiter GetAwaiter() => this; - public void Dispose() => _semaphoreSlim.Dispose(); + public void Dispose() + { + GC.SuppressFinalize(this); + _semaphoreSlim.Dispose(); + } } diff --git a/src/Pixeval/AppManagement/Versioning.cs b/src/Pixeval/AppManagement/Versioning.cs index 826588ff..49aaeee0 100644 --- a/src/Pixeval/AppManagement/Versioning.cs +++ b/src/Pixeval/AppManagement/Versioning.cs @@ -3,35 +3,37 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Json; +using System.Reflection; using System.Runtime.InteropServices; using System.Text.Json.Serialization; using System.Threading.Tasks; using CommunityToolkit.HighPerformance; +using Semver; namespace Pixeval.AppManagement; public class Versioning { - public Version CurrentVersion { get; } = Version.Parse("4.1.1"/*TODO:GitVersionInformation.AssemblySemVer*/); + public SemVersion CurrentVersion { get; } = SemVersion.Parse(ThisAssembly.Git.Tag, SemVersionStyles.Strict); - public Version? NewestVersion => NewestAppReleaseModel?.Version; + public SemVersion? NewestVersion => NewestAppReleaseModel?.Version; public AppReleaseModel? NewestAppReleaseModel => AppReleaseModels?[0]; public AppReleaseModel? CurrentAppReleaseModel => AppReleaseModels?.FirstOrDefault(t => t.Version == CurrentVersion); - public UpdateState CompareUpdateState(Version currentVersion, Version? newVersion) + public UpdateState CompareUpdateState(SemVersion currentVersion, SemVersion? newVersion) { if (newVersion is null) return UpdateState.Unknown; - return currentVersion.CompareTo(newVersion) switch + return currentVersion.ComparePrecedenceTo(newVersion) switch { > 0 => UpdateState.Insider, 0 => UpdateState.UpToDate, _ => newVersion.Major > currentVersion.Major ? UpdateState.MajorUpdate : newVersion.Minor > currentVersion.Minor ? UpdateState.MinorUpdate : - newVersion.Build > currentVersion.Build ? UpdateState.BuildUpdate : + newVersion.Patch > currentVersion.Patch ? UpdateState.BuildUpdate : UpdateState.SpecifierUpdate }; } @@ -57,7 +59,7 @@ public class Versioning var tag = release.TagName; for (var j = tag.Count('.'); j < 3; ++j) tag += ".0"; - if (Version.TryParse(tag, out var appVersion)) + if (SemVersion.TryParse(tag, SemVersionStyles.Strict, out var appVersion)) { App.AppViewModel.AppSettings.LastCheckedUpdate = DateTimeOffset.Now; var str = release.Assets.FirstOrDefault(t => @@ -88,7 +90,7 @@ public class Versioning } public record AppReleaseModel( - Version Version, + SemVersion Version, string ReleaseNote, Uri? ReleaseUri) : IComparable { @@ -98,7 +100,7 @@ public record AppReleaseModel( return 0; if (other is null) return 1; - return Version.CompareTo(other.Version); + return Version.ComparePrecedenceTo(other.Version); } } diff --git a/src/Pixeval/Pages/SuggestionModel.cs b/src/Pixeval/Pages/SuggestionModel.cs index 1f435605..4cdad339 100644 --- a/src/Pixeval/Pages/SuggestionModel.cs +++ b/src/Pixeval/Pages/SuggestionModel.cs @@ -22,7 +22,6 @@ using Microsoft.UI.Xaml.Controls; using Pixeval.CoreApi.Model; using Pixeval.Database; using Pixeval.Util.UI; -using WinUI3Utilities.Controls; using Symbol = FluentIcons.Common.Symbol; namespace Pixeval.Pages; @@ -45,11 +44,11 @@ public record SuggestionModel(string? Name, string? TranslatedName, SuggestionTy public FontIcon? FontIcon => SuggestionType switch { - SuggestionType.IllustId or SuggestionType.NovelId or SuggestionType.UserId => Symbol.Open.GetSymbolIcon(FontSizeType.Small), - SuggestionType.Tag or SuggestionType.IllustrationTag or SuggestionType.NovelTag => Symbol.Tag.GetSymbolIcon(FontSizeType.Small), - SuggestionType.UserSearch => Symbol.Person.GetSymbolIcon(FontSizeType.Small), - SuggestionType.Settings => SettingsSymbol.GetSymbolIcon(FontSizeType.Small), - SuggestionType.History => Symbol.History.GetSymbolIcon(FontSizeType.Small), + SuggestionType.IllustId or SuggestionType.NovelId or SuggestionType.UserId => Symbol.Open.GetSymbolIcon(true), + SuggestionType.Tag or SuggestionType.IllustrationTag or SuggestionType.NovelTag => Symbol.Tag.GetSymbolIcon(true), + SuggestionType.UserSearch => Symbol.Person.GetSymbolIcon(true), + SuggestionType.Settings => SettingsSymbol.GetSymbolIcon(true), + SuggestionType.History => Symbol.History.GetSymbolIcon(true), _ => null }; diff --git a/src/Pixeval/Pixeval - Backup.csproj b/src/Pixeval/Pixeval - Backup.csproj deleted file mode 100644 index 67e8da71..00000000 --- a/src/Pixeval/Pixeval - Backup.csproj +++ /dev/null @@ -1,184 +0,0 @@ - - - WinExe - net8.0-windows10.0.22621.0 - 10.0.19041.0 - 10.0.22621.38 - Pixeval - x86;x64;ARM64 - win-x86;win-x64;win-arm64 - app.manifest - enable - true - true - false - zh-cn - preview - Debug;Release - true - false - 10.0.22621.38 - win-$(Platform).pubxml - - - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { - @(TextFile->Metadata('Content'), ', - ') -} - - - - - - - - - - - - - Generated\%(RecursiveDir)\TextGenerated.resjson - "$([System.String]::Concat(%(Filename), '"').Replace('_', '/')) : "$([System.IO.File]::ReadAllText(%(FullPath)).Replace('\', '\\').Replace(' -', '\n').Replace('"', '\"'))" - - - Generated\%(RecursiveDir)\TextGenerated.resjson - "$([System.String]::Concat(%(Filename), '"').Replace('_', '/')) : "$([System.IO.File]::ReadAllText(%(FullPath)).Replace('\', '\\').Replace(' -', '\n').Replace('"', '\"'))" - - - - - - true - true - $(GitVersionTargetsBefore);_ValidateWindowsPackageType - False - False - SHA256 - False - True - True - Always - %UserProfile%\Desktop - 0 - True - x64 - - - - - - - - - MSIX - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Pixeval/Pixeval.csproj b/src/Pixeval/Pixeval.csproj index 2240fbc7..9359f944 100644 --- a/src/Pixeval/Pixeval.csproj +++ b/src/Pixeval/Pixeval.csproj @@ -6,7 +6,8 @@ 10.0.22621.38 Pixeval x86;x64;ARM64 - win-x86;win-x64;win-arm64 + win-x86;win-x64;win-arm64 + win10-x86;win10-x64;win10-arm64 app.manifest enable true @@ -19,6 +20,9 @@ false 10.0.22621.38 win-$(Platform).pubxml + true + MSIX + NU1904;$(NoWarn) @@ -26,22 +30,22 @@ - - - - - - - - - - - - + + + + + + + + + + + + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive + + all + runtime; build; native; contentfiles; analyzers; buildtransitive @@ -56,10 +60,11 @@ + - + @@ -102,9 +107,7 @@ - true true - $(GitVersionTargetsBefore);_ValidateWindowsPackageType False False SHA256 @@ -118,16 +121,6 @@ x64 - - - - - - - MSIX - - - diff --git a/src/Pixeval/Util/UI/UIHelper.cs b/src/Pixeval/Util/UI/UIHelper.cs index c2b47cdc..b9d98b51 100644 --- a/src/Pixeval/Util/UI/UIHelper.cs +++ b/src/Pixeval/Util/UI/UIHelper.cs @@ -48,7 +48,6 @@ using Color = Windows.UI.Color; using Image = SixLabors.ImageSharp.Image; using Point = Windows.Foundation.Point; using Pixeval.Controls.Windowing; -using WinUI3Utilities.Controls; using Size = Windows.Foundation.Size; using Symbol = FluentIcons.Common.Symbol; using SymbolIcon = FluentIcons.WinUI.SymbolIcon; @@ -200,20 +199,20 @@ public static partial class UiHelper _ = frame.Navigate(tag.NavigateTo, tag.Parameter, transitionInfo); } - public static SymbolIcon GetSymbolIcon(this Symbol symbol, FontSizeType fontSize = FontSizeType.None) + public static SymbolIcon GetSymbolIcon(this Symbol symbol, bool useSmallFontSize = false) { - var icon = new SymbolIcon() + var icon = new SymbolIcon { Symbol = symbol }; - if (fontSize is not FontSizeType.None) - icon.FontSize = (int)fontSize; + if (useSmallFontSize) + icon.FontSize = 16; // 20 is default return icon; } - public static SymbolIconSource GetSymbolIconSource(this Symbol symbol, bool isFilled = false, Brush? foregroundBrush = null, FontSizeType fontSize = FontSizeType.None) + public static SymbolIconSource GetSymbolIconSource(this Symbol symbol, bool isFilled = false, Brush? foregroundBrush = null, bool useSmallFontSize = false) { var icon = new SymbolIconSource { @@ -221,8 +220,8 @@ public static partial class UiHelper Symbol = symbol }; - if (fontSize is not FontSizeType.None) - icon.FontSize = (int)fontSize; + if (useSmallFontSize) + icon.FontSize = 16; // 20 is default if (foregroundBrush is not null) icon.Foreground = foregroundBrush;