Skip to content

Commit

Permalink
Merge branch 'eesast:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sigureling authored May 11, 2024
2 parents 219743e + b90b408 commit 4147476
Show file tree
Hide file tree
Showing 28 changed files with 834 additions and 273 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/debug.yml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
59 changes: 59 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: deploy
on:
push:
branches: [dev, main, master]
pull_request:
branches: [dev, main, master]

env:
version: 1.1.0.0

jobs:
deploy-to-tencent-cos:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup dotnet-script
run: dotnet tool install --global dotnet-script
- name: Pre-Process
run: dotnet script .github/preProcess/MauiEnvConfig.csx
- name: Install Workloads
run: dotnet workload install maui-windows
- name: Create Folders need
run: |
mkdir D:\a\installer
mkdir D:\a\publish
- name: Copy THUAI7
run: Copy-Item -recurse D:\a\THUAI7\THUAI7\ D:\a\mirror\
- name: Test
run: tree D:\a\mirror
- name: Remove directories not needed
run: |
Remove-Item -recurse -force D:\a\mirror\.git
Remove-Item -recurse D:\a\mirror\.github
Remove-Item -recurse D:\a\mirror\installer
Remove-Item -recurse D:\a\mirror\interface
Remove-Item -recurse D:\a\mirror\logic
- name: Build Server
run: |
mkdir D:\a\mirror\logic
dotnet build "./logic/Server/Server.csproj" -o "D:\a\mirror\logic\Server" -p:WindowsAppSDKSelfContained=true -c Release
- name: Build Client
run: dotnet publish "./logic/Client/Client.csproj" -o "D:\a\mirror\logic\Client" -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
- name: Deploy to bucket
run: dotnet run --project "./dependency/deploy/deploy.csproj" ${{ secrets.INSTALLER_COS_SECRET_ID }} ${{ secrets.INSTALLER_COS_SECRET_KEY }}
- name: Get installer package(No Key contained for safety)
run: |
$version=Get-ChildItem -Path D:\a\publish | ForEach-Object { $_.name }
[Environment]::SetEnvironmentVariable("version", $version, "Machine")
dotnet publish "./installer/installer.csproj" -o "D:\a\installer" -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
./dependency/7z/7za.exe a -r D:\a\publish\Installer_v${version}.zip D:\a\installer\*
- name: Upload installer package
uses: actions/upload-artifact@v4
with:
name: Installer_v${{ env.version }}.zip
path: D:\a\publish\Installer_v${{ env.version }}.zip
Binary file added dependency/7z/7za.dll
Binary file not shown.
Binary file added dependency/7z/7za.exe
Binary file not shown.
117 changes: 117 additions & 0 deletions dependency/deploy/BaseViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Windows.Input;
using System.Runtime.CompilerServices;

namespace installer.ViewModel
{
public abstract class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
///<summary>
///announce notification
///</summary>
///<param name="propertyName">property name</param>
public virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
///<summary>
///BaseCommand
///</summary>
public class BaseCommand : ICommand
{
private Func<object?, bool>? _canExecute;
private Action<object?> _execute;

public BaseCommand(Func<object?, bool>? canExecute, Action<object?> execute)
{
_canExecute = canExecute;
_execute = execute;
}

public BaseCommand(Action<object?> execute) :
this(null, execute)
{
}


public event EventHandler? CanExecuteChanged
{
add
{
if (_canExecute != null)
{
//CommandManager.RequerySuggested += value;
}
}
remove
{
if (_canExecute != null)
{
//CommandManager.RequerySuggested -= value;
}
}
}

public bool CanExecute(object? parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}

public void Execute(object? parameter)
{
if (_execute != null && CanExecute(parameter))
{
_execute(parameter);
}
}
}

public class RadioConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value == null || parameter == null)
{
return false;
}
string checkvalue = value.ToString() ?? "";
string targetvalue = parameter.ToString() ?? "";
bool r = checkvalue.Equals(targetvalue);
return r;
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is null || parameter is null)
{
return null;
}

if ((bool)value)
{
return parameter.ToString();
}
return null;
}
}

public abstract class BaseViewModel : NotificationObject
{
private const string constBackgroundColor = "White";
public string ConstBackgroundColor { get => constBackgroundColor; }

private const string constFontSize = "18";
public string ConstFontSize { get => constFontSize; }

private const string constTextColor = "Blue";
public string ConstTextColor { get => constTextColor; }
}
}
17 changes: 17 additions & 0 deletions dependency/deploy/Data/FakeData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace installer.Data
{
public enum DevicePlatform
{
WinUI
}
public static class DeviceInfo
{
public static DevicePlatform Platform { get; set; } = DevicePlatform.WinUI;
}
}
16 changes: 16 additions & 0 deletions dependency/deploy/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace installer
{
public static class MauiProgram
{
public static bool RefreshLogs_WhileDebug = false;
public static bool ErrorTrigger_WhileDebug = true;
public static string SecretID = "***";
public static string SecretKey = "***";
}
}
72 changes: 72 additions & 0 deletions dependency/deploy/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using installer.Data;
using installer.Model;
using installer.Services;
using System.Collections.Concurrent;
using System.Diagnostics;

Logger Log = LoggerProvider.FromConsole();

// 全权读写
Tencent_Cos Cloud = new Tencent_Cos("1319625962", "ap-beijing", "thuai7", Log);
Cloud.UpdateSecret(args[0], args[1]);

Downloader d = new Downloader();
d.Cloud.UpdateSecret(args[0], args[1]);
d.Data.Config.InstallPath = @"D:\a\mirror\";

d.Log.Partner.Add(Log);
// 每次更新需要更新默认值
d.CurrentVersion = new TVersion();
File.Create(Path.Combine("D:\\a\\publish", d.CurrentVersion.InstallerVersion.ToString()));

if (d.CheckUpdate())
{
foreach (var r in d.Data.MD5Update)
{
Log.LogInfo($"{r.state}, {r.name}");
}

d.Data.SaveMD5Data();
List<Task> l = new List<Task>();
foreach (var r in d.Data.MD5Update)
{
var n = r.name.Replace('\\', '/');
n = n.TrimStart('.').TrimStart('/');
if (r.state == System.Data.DataRowState.Added || r.state == System.Data.DataRowState.Modified)
{
l.Add(Cloud.UploadFileAsync(Path.Combine(d.Data.Config.InstallPath, r.name), n));
}
else if (r.state == System.Data.DataRowState.Deleted)
{
l.Add(Cloud.DeleteFileAsync(n));
}
}
Task.WaitAll(l.ToArray());
}
else
{
Log.LogInfo("Nothing to update");
}

d.Data.SaveMD5Data();
Cloud.UploadFile(d.Data.MD5DataPath, "hash.json");

Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "CAPI", "cpp", "API", "src", "AI.cpp"),
$"Templates/t.{d.CurrentVersion.TemplateVersion}.cpp");
Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "CAPI", "python", "PyAPI", "AI.py"),
$"Templates/t.{d.CurrentVersion.TemplateVersion}.py");
Log.LogInfo("User code uploaded.");

var list = (from i in d.Data.MD5Data
select i.Key.Replace(Path.DirectorySeparatorChar, '/').TrimStart('.').TrimStart('/')).ToArray();
Log.LogInfo(list[0]);
using (FileStream s = new FileStream(Path.Combine(d.Data.Config.InstallPath, "compress.csv"), FileMode.Create, FileAccess.Write))
using (StreamWriter w = new StreamWriter(s))
{
foreach (var item in list)
{
w.WriteLine("https://thuai7-1319625962.cos.ap-beijing.myqcloud.com/" + item);
}
}
Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "compress.csv"), "compress.csv");
Log.LogInfo("Compress csv generated.");
21 changes: 21 additions & 0 deletions dependency/deploy/Services/OtherService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace installer.Services
{
public static class Application
{
public static App? Current;
}

public class App
{
public void Quit()
{

}
}
}
31 changes: 31 additions & 0 deletions dependency/deploy/deploy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Downloader.cs" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\installer\Data\ConfigFileData.cs" Link="Data\ConfigFileData.cs" />
<Compile Include="..\..\installer\Data\DownloadReport.cs" Link="Data\DownloadReport.cs" />
<Compile Include="..\..\installer\Data\MD5FileData.cs" Link="Data\MD5FileData.cs" />
<Compile Include="..\..\installer\Model\Downloader.cs" Link="Models\Downloader.cs" />
<Compile Include="..\..\installer\Model\EEsast.cs" Link="Models\EEsast.cs" />
<Compile Include="..\..\installer\Model\Local_Data.cs" Link="Models\Local_Data.cs" />
<Compile Include="..\..\installer\Model\Logger.cs" Link="Models\Logger.cs" />
<Compile Include="..\..\installer\Model\Run_Program.cs" Link="Models\Run_Program.cs" />
<Compile Include="..\..\installer\Model\Tencent_Cos.cs" Link="Models\Tencent_Cos.cs" />
<Compile Include="..\..\installer\Services\FileService.cs" Link="Services\FileService.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Tencent.QCloud.Cos.Sdk" Version="5.4.35" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions dependency/deploy/deploy.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Deploy", "Deploy.csproj", "{1E0F079D-EECF-4DC8-A783-A86F25A2397E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1E0F079D-EECF-4DC8-A783-A86F25A2397E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E0F079D-EECF-4DC8-A783-A86F25A2397E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E0F079D-EECF-4DC8-A783-A86F25A2397E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E0F079D-EECF-4DC8-A783-A86F25A2397E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7B9F1497-D14B-47E1-AEEF-A4254398185F}
EndGlobalSection
EndGlobal
4 changes: 2 additions & 2 deletions installer/Data/MD5FileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public class TVersion
{
// 代码库版本
[JsonInclude]
public Version LibVersion = new Version(1, 0, 2, 2);
public Version LibVersion = new Version(1, 0, 2, 3);
// 选手代码模板版本
[JsonInclude]
public Version TemplateVersion = new Version(1, 0, 0, 3);
// 本体版本
[JsonInclude]
public Version InstallerVersion = new Version(1, 0, 2, 0);
public Version InstallerVersion = new Version(1, 1, 0, 0);
public static bool operator <(TVersion l, TVersion r)
{
return l.LibVersion < r.LibVersion || l.TemplateVersion < r.TemplateVersion || l.InstallerVersion < r.InstallerVersion;
Expand Down
Loading

0 comments on commit 4147476

Please sign in to comment.