Skip to content
Merged
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
189 changes: 177 additions & 12 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# This workflow will build and test a .NET project and publish DLL artifacts.
name: GEffectsLogic CI

name: .NET
permissions:
contents: write

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-artifacts:
runs-on: ubuntu-latest

runs-on: ubuntu-slim
outputs:
versionprefix_changed: ${{ steps.versionprefix.outputs.changed }}
version: ${{ steps.versionprefix.outputs.version }}
artifact_name: ${{ steps.artifact-name.outputs.name }}

steps:
- uses: actions/checkout@v4

Expand All @@ -23,6 +27,25 @@ jobs:
- name: Restore dependencies
run: dotnet restore

- name: Detect VersionPrefix change on main push
id: versionprefix
shell: bash
run: |
version=v$(grep -oPm1 '(?<=<VersionPrefix>)[^<]+' GEffectsLogic/GEffectsLogic.csproj)
echo "version=$version" >> "$GITHUB_OUTPUT"

before="${{ github.event.before }}"
if [ -z "$before" ] || [ "$before" = "0000000000000000000000000000000000000000" ]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi

if git diff "$before" "${{ github.sha }}" -- GEffectsLogic/GEffectsLogic.csproj | grep -q 'VersionPrefix'; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Build all configurations
run: |
dotnet build GEffectsLogic/GEffectsLogic.csproj -c Release --no-restore
Expand All @@ -35,18 +58,41 @@ jobs:
mkdir -p artifacts/net481/release
mkdir -p artifacts/net481/debug

cp GEffectsLogic/bin/Release/net10.0/GEffectsLogic.dll artifacts/net10.0/release/
cp GEffectsLogic/bin/Debug/net10.0/GEffectsLogic.dll artifacts/net10.0/debug/
cp GEffectsLogic/bin/Debug/net10.0/GEffectsLogic.pdb artifacts/net10.0/debug/
cp GEffectsLogic/bin/Release/net10.0/GEffectsLogic-net10.0.dll artifacts/net10.0/release/
cp GEffectsLogic/bin/Release/net10.0/GEffectsLogic-net10.0.deps.json artifacts/net10.0/release/
cp GEffectsLogic/bin/Release/net10.0/GEffectsLogic-net10.0.pdb artifacts/net10.0/release/
cp GEffectsLogic/bin/Debug/net10.0/GEffectsLogic-net10.0.dll artifacts/net10.0/debug/
cp GEffectsLogic/bin/Debug/net10.0/GEffectsLogic-net10.0.deps.json artifacts/net10.0/debug/
cp GEffectsLogic/bin/Debug/net10.0/GEffectsLogic-net10.0.pdb artifacts/net10.0/debug/

cp GEffectsLogic/bin/Release/net481/GEffectsLogic-net481.dll artifacts/net481/release/
cp GEffectsLogic/bin/Release/net481/GEffectsLogic-net481.pdb artifacts/net481/release/
cp GEffectsLogic/bin/Debug/net481/GEffectsLogic-net481.dll artifacts/net481/debug/
cp GEffectsLogic/bin/Debug/net481/GEffectsLogic-net481.pdb artifacts/net481/debug/

- name: Compute artifact name
id: artifact-name
shell: bash
run: |
version="${{ steps.versionprefix.outputs.version }}"
short_hash="${GITHUB_SHA::7}"

if [ "$GITHUB_EVENT_NAME" = "push" ] && [ "$GITHUB_REF" = "refs/heads/main" ]; then
if [ "${{ steps.versionprefix.outputs.changed }}" = "true" ]; then
artifact_name="GEffectsLogic-${version}"
else
artifact_name="GEffectsLogic-${version}-${short_hash}"
fi
else
artifact_name="GEffectsLogic-${version}-${short_hash}-debug"
fi

cp GEffectsLogic/bin/Release/net481/GEffectsLogic.dll artifacts/net481/release/
cp GEffectsLogic/bin/Debug/net481/GEffectsLogic.dll artifacts/net481/debug/
cp GEffectsLogic/bin/Debug/net481/GEffectsLogic.pdb artifacts/net481/debug/
echo "name=$artifact_name" >> "$GITHUB_OUTPUT"

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: GEffectsLogic
name: ${{ steps.artifact-name.outputs.name }}
path: artifacts/

test:
Expand All @@ -69,3 +115,122 @@ jobs:

- name: Test (Debug)
run: dotnet test GEffectLogicTests/GEffectLogicTests.csproj -c Debug --no-build --verbosity normal

release-artifacts:
runs-on: ubuntu-slim
needs: build-artifacts
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.build-artifacts.outputs.versionprefix_changed == 'true' }}
steps:
- name: Verify version change
shell: bash
run: |
new_version="${{ needs.build-artifacts.outputs.version }}"
current_version=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest" | grep -oP '"tag_name": "\K(.*)(?=")')

echo "csproj version: $new_version"
echo "latest release version: $current_version"

if [ "$new_version" = "$current_version" ]; then
echo "VersionPrefix has not changed since the last release. Skipping release."
exit 1
fi

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build-artifacts.outputs.artifact_name }}
path: release-assets

- name: Zip release payload
shell: bash
run: |
artifact_name="${{ needs.build-artifacts.outputs.artifact_name }}"
cd release-assets
zip -r "../${artifact_name}.zip" .

- name: Create GitHub release
id: github-release
shell: bash
run: |
json_payload=$(jq -n \
--arg tag_name "${{ needs.build-artifacts.outputs.version }}" \
--arg name "${{ needs.build-artifacts.outputs.version }}" \
'{ tag_name: $tag_name, name: $name, draft: true, prerelease: false, generate_release_notes: true }')

echo "Creating release with payload: $json_payload"
response_file=$(mktemp)
http_status=$(curl -sS -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d "$json_payload" \
-o "$response_file" \
-w "%{http_code}")

if [ "$http_status" -ne 201 ]; then
echo "Failed to create release. Expected HTTP 201, got HTTP $http_status." >&2
cat "$response_file" >&2
exit 1
fi

upload_url=$(jq -r '.upload_url' "$response_file")
if [ -z "$upload_url" ] || [ "$upload_url" = "null" ]; then
echo "Release created but upload_url is missing in response." >&2
cat "$response_file" >&2
exit 1
fi

upload_url="${upload_url%\{*}"
asset_name="${{ needs.build-artifacts.outputs.artifact_name }}.zip"
asset_path="$asset_name"

if [ ! -f "$asset_path" ]; then
echo "Expected release asset file '$asset_path' was not found." >&2
exit 1
fi

echo "Uploading release asset: $asset_name"
upload_response_file=$(mktemp)
upload_status=$(curl -sS -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/zip" \
-H "X-GitHub-Api-Version: 2026-03-10" \
--data-binary @"$asset_path" \
"${upload_url}?name=${asset_name}" \
-o "$upload_response_file" \
-w "%{http_code}")

if [ "$upload_status" -ne 201 ]; then
echo "Failed to upload release asset. Expected HTTP 201, got HTTP $upload_status." >&2
cat "$upload_response_file" >&2
exit 1
fi

release_id=$(jq -r '.id' "$response_file")
if [ -z "$release_id" ] || [ "$release_id" = "null" ]; then
echo "Release created but id is missing in response." >&2
cat "$response_file" >&2
exit 1
fi

publish_payload='{"draft":false}'
publish_response_file=$(mktemp)
publish_status=$(curl -sS -L -X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/repos/${{ github.repository }}/releases/$release_id \
-d "$publish_payload" \
-o "$publish_response_file" \
-w "%{http_code}")

if [ "$publish_status" -ne 200 ]; then
echo "Failed to publish release. Expected HTTP 200, got HTTP $publish_status." >&2
cat "$publish_response_file" >&2
exit 1
fi

echo "Release created and asset uploaded successfully."
18 changes: 12 additions & 6 deletions GEffectsLogic/GEffectsLogic.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net481;net10.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net481;net10.0</TargetFrameworks>
<RootNamespace>GEffectsLogic</RootNamespace>
<PackageId>GEffectsLogic</PackageId>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Configurations>Debug;Release;PerfDebug</Configurations>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>

<VersionPrefix>0.3.0</VersionPrefix>
<VersionPrefix>0.3.2</VersionPrefix>
<Version>$(VersionPrefix)</Version>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<AssemblyVersion>0.3.1.0</AssemblyVersion>
<FileVersion>$(VersionPrefix).0</FileVersion>

<GitShortHash>nogit</GitShortHash>
Expand All @@ -21,6 +23,10 @@
<Copyright>GNU GPL v3.0</Copyright>
</PropertyGroup>

<PropertyGroup>
<AssemblyName>GEffectsLogic-$(TargetFramework)</AssemblyName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
</PropertyGroup>
Expand All @@ -38,7 +44,7 @@
<InformationalVersionPostfix>-perfDebug</InformationalVersionPostfix>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PropertyGroup>
<DebugType>portable</DebugType>
</PropertyGroup>

Expand Down
8 changes: 5 additions & 3 deletions GEffectsLogic/GEffectsLogicInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ public virtual void Update(double deltaTime, double currentGx, double currentGy,
#if PERFDEBUG
var sw = Stopwatch.StartNew();
#endif
List<double> dtList = new();
List<double> dtList = [];

if (deltaTime > 1) {
if (deltaTime > 1)
{
int stepCount = (int)deltaTime * 2;
dtList.AddRange(Enumerable.Repeat(deltaTime / stepCount, stepCount));
if (!stable) Logger.Log($"High deltaTime detected: {deltaTime}s - splitting it into {stepCount} steps of {deltaTime / stepCount}s each", UniqueID, Logger.LogLevel.Warning);
}
else if (deltaTime <= 0) {
else if (deltaTime <= 0)
{
Logger.Log($"Negative deltaTime detected: {deltaTime}s", UniqueID, Logger.LogLevel.Error);
}
else
Expand Down
8 changes: 4 additions & 4 deletions GraphicLogicTest/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using GraphicLogicTest.Logging;
using GraphicLogicTest.Views.GLoCPlot;
using GraphicLogicTest.Views.SimulationView;
using LiveChartsCore;
using LiveChartsCore.Defaults;
Expand All @@ -13,8 +15,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using GraphicLogicTest.Logging;
using GraphicLogicTest.Views.GLoCPlot;

namespace GraphicLogicTest
{
Expand All @@ -31,9 +31,9 @@ public MainWindow()
_ = new TestLogging();
GEffectsLogic.Logging.Logger.Instance = new LogicLogging();
GEffectsLogic.LogicSettings.DebugMode = true;

_simulationViewModel = new SimulationViewModel();

InitializeComponent();
DataContext = this;
RegisterWindowViews();
Expand Down
1 change: 0 additions & 1 deletion GraphicLogicTest/SimulationViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
using GraphicLogicTest.Logging;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Reflection;
Expand Down
8 changes: 4 additions & 4 deletions GraphicLogicTest/Views/GLoCPlot/GLoCPlot.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.ObjectModel;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
Expand All @@ -8,6 +7,7 @@
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
using System.Collections.ObjectModel;

namespace GraphicLogicTest.Views.GLoCPlot
{
Expand All @@ -19,7 +19,7 @@ public partial class GLoCPlot : UserControl
public string EndG { get; set; } = "9";
public string Iterations { get; set; } = "10";

private ObservableCollection<ObservablePoint> GLoCPoints = new();
private ObservableCollection<ObservablePoint> GLoCPoints = [];

public List<ISeries> Series { get; private set; }

Expand Down Expand Up @@ -57,8 +57,8 @@ private void AddGAccelerationLine(double startG, double endG, double endTime)
Name = "GAcceleration",
Values = new ObservableCollection<ObservablePoint>()
{
new ObservablePoint(0.0, startG),
new ObservablePoint(endTime, endG)
new(0.0, startG),
new(endTime, endG)
},
GeometrySize = 0,
Stroke = new SolidColorPaint(SKColors.DarkViolet),
Expand Down
Loading