mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-16 02:01:29 -07:00
Add build metadata for diagnostics, update checks
is this actually gonna work? uhhhh maybe idk
This commit is contained in:
parent
17c36ccb91
commit
2258000a89
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
@ -6,28 +6,33 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
configuration: [Debug, Release]
|
||||
platform: [x64]
|
||||
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: '6.x'
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --no-restore
|
||||
|
||||
- name: Publish
|
||||
run: dotnet publish -p:PublishSingleFile=true -r win-${{ matrix.platform }} -c ${{ matrix.configuration }} --self-contained false .\Bloxstrap\Bloxstrap.csproj
|
||||
run: dotnet publish -p:PublishSingleFile=true -p:CommitHash=${{ github.sha }} -p:CommitRef=${{ github.ref_type }}/${{ github.ref_name }} -r win-x64 -c ${{ matrix.configuration }} --self-contained false .\Bloxstrap\Bloxstrap.csproj
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Bloxstrap (${{ matrix.configuration }}, ${{ matrix.platform }})
|
||||
name: Bloxstrap (${{ matrix.configuration }}, x64)
|
||||
path: |
|
||||
.\Bloxstrap\bin\${{ matrix.configuration }}\net6.0-windows\win-${{ matrix.platform }}\publish\*
|
||||
.\Bloxstrap\bin\${{ matrix.configuration }}\net6.0-windows\win-x64\publish\*
|
||||
|
||||
release:
|
||||
needs: build
|
||||
@ -40,9 +45,11 @@ jobs:
|
||||
with:
|
||||
name: Bloxstrap (Release, x64)
|
||||
path: x64
|
||||
|
||||
- name: Rename binaries
|
||||
run: |
|
||||
mv x64/Bloxstrap.exe Bloxstrap-${{ github.ref_name }}-x64.exe
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
|
@ -15,6 +15,7 @@ using Microsoft.Win32;
|
||||
|
||||
using Bloxstrap.Extensions;
|
||||
using Bloxstrap.Models;
|
||||
using Bloxstrap.Models.Attributes;
|
||||
using Bloxstrap.UI.BootstrapperDialogs;
|
||||
using Bloxstrap.UI.Menu.Views;
|
||||
using Bloxstrap.Utility;
|
||||
@ -44,6 +45,7 @@ namespace Bloxstrap
|
||||
public static bool IsMenuLaunch { get; private set; } = false;
|
||||
public static string[] LaunchArgs { get; private set; } = null!;
|
||||
|
||||
public static BuildMetadataAttribute BuildMetadata => Assembly.GetExecutingAssembly().GetCustomAttribute<BuildMetadataAttribute>()!;
|
||||
public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2];
|
||||
|
||||
// singletons
|
||||
@ -118,6 +120,11 @@ namespace Bloxstrap
|
||||
|
||||
Logger.WriteLine($"[App::OnStartup] Starting {ProjectName} v{Version}");
|
||||
|
||||
if (String.IsNullOrEmpty(BuildMetadata.CommitHash))
|
||||
Logger.WriteLine($"[App::OnStartup] Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from {BuildMetadata.Machine}");
|
||||
else
|
||||
Logger.WriteLine($"[App::OnStartup] Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from commit {BuildMetadata.CommitHash} ({BuildMetadata.CommitRef})");
|
||||
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
|
@ -39,4 +39,13 @@
|
||||
<ProjectReference Include="..\wpfui\src\Wpf.Ui\Wpf.Ui.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="Bloxstrap.Models.Attributes.BuildMetadataAttribute">
|
||||
<_Parameter1>$([System.DateTime]::UtcNow.ToString("s"))Z</_Parameter1>
|
||||
<_Parameter2>$(COMPUTERNAME)\$(USERNAME)</_Parameter2>
|
||||
<_Parameter3>$(CommitHash)</_Parameter3>
|
||||
<_Parameter4>$(CommitRef)</_Parameter4>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -576,25 +576,34 @@ namespace Bloxstrap
|
||||
return;
|
||||
}
|
||||
|
||||
string currentVersion = $"{App.ProjectName} v{App.Version}";
|
||||
|
||||
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Checking for {App.ProjectName} updates...");
|
||||
|
||||
var releaseInfo = await Utilities.GetJson<GithubRelease>($"https://api.github.com/repos/{App.ProjectRepository}/releases/latest");
|
||||
|
||||
if (releaseInfo?.Assets is null || currentVersion == releaseInfo.Name)
|
||||
if (releaseInfo is null || releaseInfo.Assets is null)
|
||||
{
|
||||
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found");
|
||||
return;
|
||||
}
|
||||
|
||||
int numCurrentVersion = Utilities.VersionToNumber(App.Version);
|
||||
int numLatestVersion = Utilities.VersionToNumber(releaseInfo.TagName);
|
||||
|
||||
// check if we aren't using a deployed build, so we can update to one if a new version comes out
|
||||
if (numCurrentVersion == numLatestVersion && App.BuildMetadata.CommitRef.StartsWith("tag") || numCurrentVersion > numLatestVersion)
|
||||
{
|
||||
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SetStatus($"Getting the latest {App.ProjectName}...");
|
||||
|
||||
// 64-bit is always the first option
|
||||
GithubReleaseAsset asset = releaseInfo.Assets[0];
|
||||
string downloadLocation = Path.Combine(Directories.LocalAppData, "Temp", asset.Name);
|
||||
|
||||
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Downloading {releaseInfo.Name}...");
|
||||
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Downloading {releaseInfo.TagName}...");
|
||||
|
||||
if (!File.Exists(downloadLocation))
|
||||
{
|
||||
@ -604,7 +613,7 @@ namespace Bloxstrap
|
||||
await response.Content.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Starting {releaseInfo.Name}...");
|
||||
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Starting {releaseInfo.TagName}...");
|
||||
|
||||
ProcessStartInfo startInfo = new()
|
||||
{
|
||||
|
12
Bloxstrap/Extensions/DateTimeEx.cs
Normal file
12
Bloxstrap/Extensions/DateTimeEx.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Bloxstrap.Extensions
|
||||
{
|
||||
static class DateTimeEx
|
||||
{
|
||||
public static string ToFriendlyString(this DateTime dateTime)
|
||||
{
|
||||
return dateTime.ToString("dddd, d MMMM yyyy 'at' h:mm:ss tt", App.CultureFormat);
|
||||
}
|
||||
}
|
||||
}
|
@ -39,9 +39,9 @@ namespace Bloxstrap
|
||||
|
||||
public void WriteLine(string message)
|
||||
{
|
||||
string timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
string timestamp = DateTime.UtcNow.ToString("s") + "Z";
|
||||
string outcon = $"{timestamp} {message}";
|
||||
string outlog = outcon.Replace(Directories.UserProfile, "<UserProfileFolder>");
|
||||
string outlog = outcon.Replace(Directories.UserProfile, "%UserProfile%");
|
||||
|
||||
Debug.WriteLine(outcon);
|
||||
WriteToLog(outlog);
|
||||
|
21
Bloxstrap/Models/Attributes/CompileTimeInfoAttribute.cs
Normal file
21
Bloxstrap/Models/Attributes/CompileTimeInfoAttribute.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Bloxstrap.Models.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly)]
|
||||
public class BuildMetadataAttribute : Attribute
|
||||
{
|
||||
public DateTime Timestamp { get; set; }
|
||||
public string Machine { get; set; }
|
||||
public string CommitHash { get; set; }
|
||||
public string CommitRef { get; set; }
|
||||
|
||||
public BuildMetadataAttribute(string timestamp, string machine, string commitHash, string commitRef)
|
||||
{
|
||||
Timestamp = DateTime.Parse(timestamp).ToLocalTime();
|
||||
Machine = machine;
|
||||
CommitHash = commitHash;
|
||||
CommitRef = commitRef;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,21 @@
|
||||
namespace Bloxstrap.UI.Menu.ViewModels
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
using Bloxstrap.Extensions;
|
||||
using Bloxstrap.Models.Attributes;
|
||||
|
||||
namespace Bloxstrap.UI.Menu.ViewModels
|
||||
{
|
||||
public class AboutViewModel
|
||||
{
|
||||
public string Version => $"Version {App.Version}";
|
||||
|
||||
public BuildMetadataAttribute BuildMetadata => App.BuildMetadata;
|
||||
|
||||
public string BuildTimestamp => BuildMetadata.Timestamp.ToFriendlyString();
|
||||
public string BuildCommitHashUrl => $"https://github.com/{App.ProjectRepository}/commit/{BuildMetadata.CommitHash}";
|
||||
|
||||
public Visibility BuildInformationVisibility => BuildMetadata.CommitRef.StartsWith("tag") ? Visibility.Collapsed : Visibility.Visible;
|
||||
public Visibility BuildCommitVisibility => String.IsNullOrEmpty(BuildMetadata.CommitHash) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using Bloxstrap.Enums;
|
||||
using Bloxstrap.Extensions;
|
||||
using Bloxstrap.Models;
|
||||
|
||||
namespace Bloxstrap.UI.Menu.ViewModels
|
||||
@ -50,7 +51,7 @@ namespace Bloxstrap.UI.Menu.ViewModels
|
||||
{
|
||||
Version = info.Version,
|
||||
VersionGuid = info.VersionGuid,
|
||||
Timestamp = info.Timestamp?.ToString("dddd, d MMMM yyyy 'at' h:mm:ss tt", App.CultureFormat)!
|
||||
Timestamp = info.Timestamp?.ToFriendlyString()!
|
||||
};
|
||||
|
||||
OnPropertyChanged(nameof(ChannelDeployInfo));
|
||||
|
@ -41,6 +41,41 @@
|
||||
<ui:Anchor Margin="4,16,0,0" Content="Discord help server" Icon="Chat48" NavigateUri="https://discord.gg/nKjV3mGq6R" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Visibility="{Binding BuildInformationVisibility, Mode=OneTime}">
|
||||
<TextBlock Text="Build Information" FontWeight="Medium" FontSize="20" Margin="0,16,0,0" />
|
||||
<TextBlock Text="Using an unreleased version, I see?" TextWrapping="Wrap" Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
|
||||
<Grid Column="0" Margin="0,8,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,4,16,4" FontSize="14" FontWeight="Medium" Text="Timestamp" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0,0,0,4" VerticalAlignment="Bottom" Text="{Binding BuildTimestamp, Mode=OneTime}" Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,4,16,4" FontSize="14" FontWeight="Medium" Text="Machine" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0,0,0,4" VerticalAlignment="Bottom" Text="{Binding BuildMetadata.Machine, Mode=OneTime}" Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Margin="0,4,16,4" FontSize="14" FontWeight="Medium" Text="Commit Hash" Visibility="{Binding BuildCommitVisibility, Mode=OneTime}" />
|
||||
<TextBlock Grid.Row="2" Grid.Column="1" Margin="0,0,0,4" VerticalAlignment="Bottom" Foreground="{DynamicResource TextFillColorTertiaryBrush}" Visibility="{Binding BuildCommitVisibility, Mode=OneTime}">
|
||||
<Hyperlink Foreground="{DynamicResource TextFillColorTertiaryBrush}" Command="models:GlobalViewModel.OpenWebpageCommand" CommandParameter="{Binding BuildCommitHashUrl, Mode=OneTime}">
|
||||
<TextBlock Text="{Binding BuildMetadata.CommitHash, Mode=OneTime}" />
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Margin="0,4,16,4" FontSize="14" FontWeight="Medium" Text="Commit Ref" Visibility="{Binding BuildCommitVisibility, Mode=OneTime}" />
|
||||
<TextBlock Grid.Row="3" Grid.Column="1" Margin="0,0,0,4" VerticalAlignment="Bottom" Text="{Binding BuildMetadata.CommitRef, Mode=OneTime}" Foreground="{DynamicResource TextFillColorTertiaryBrush}" Visibility="{Binding BuildCommitVisibility, Mode=OneTime}" />
|
||||
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="Contributors" FontWeight="Medium" FontSize="20" Margin="0,16,0,0" />
|
||||
<TextBlock Text="These are the people who have made notable contributions to Bloxstrap, helping make it what it is." TextWrapping="Wrap" Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
<Grid Column="0" Margin="0,8,0,0">
|
||||
|
@ -19,11 +19,9 @@ namespace Bloxstrap
|
||||
// 2.0.0 downloads updates to <BaseFolder>/Updates so lol
|
||||
bool isAutoUpgrade = Environment.ProcessPath.StartsWith(Path.Combine(Directories.Base, "Updates")) || Environment.ProcessPath.StartsWith(Path.Combine(Directories.LocalAppData, "Temp"));
|
||||
|
||||
// if downloaded version doesn't match, replace installed version with downloaded version
|
||||
FileVersionInfo currentVersionInfo = FileVersionInfo.GetVersionInfo(Environment.ProcessPath);
|
||||
FileVersionInfo installedVersionInfo = FileVersionInfo.GetVersionInfo(Directories.Application);
|
||||
|
||||
if (installedVersionInfo.ProductVersion == currentVersionInfo.ProductVersion)
|
||||
if (Utility.MD5Hash.FromFile(Environment.ProcessPath) == Utility.MD5Hash.FromFile(Directories.Application))
|
||||
return;
|
||||
|
||||
MessageBoxResult result;
|
||||
|
@ -39,5 +39,12 @@ namespace Bloxstrap
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public static int VersionToNumber(string version)
|
||||
{
|
||||
// yes this is kinda stupid lol
|
||||
version = version.Replace("v", "").Replace(".", "");
|
||||
return Int32.Parse(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user