NewLife/Stardust

发布构建客户端骨架代码
大石头 authored at 2023-12-11 14:54:01
eb6b328
Tree
1 Parent(s) 645350d
Summary: 4 changed files with 65 additions and 3 deletions.
Modified +1 -1
Added +39 -0
Modified +5 -2
Added +20 -0
Modified +1 -1
diff --git a/DeployAgent/DeployAgent.csproj b/DeployAgent/DeployAgent.csproj
index f2a6133..4c84441 100644
--- a/DeployAgent/DeployAgent.csproj
+++ b/DeployAgent/DeployAgent.csproj
@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFrameworks>net45;net461;net6.0;net7.0;net8.0</TargetFrameworks>
+    <TargetFrameworks>net461;net6.0;net7.0;net8.0</TargetFrameworks>
     <AssemblyTitle>星尘发布</AssemblyTitle>
     <Description>自动下载代码,编译后打包输出并推送发布中心。</Description>
     <Company>新生命开发团队</Company>
Added +39 -0
diff --git a/DeployAgent/DeployWorker.cs b/DeployAgent/DeployWorker.cs
new file mode 100644
index 0000000..de10b34
--- /dev/null
+++ b/DeployAgent/DeployWorker.cs
@@ -0,0 +1,39 @@
+using NewLife;
+using NewLife.Model;
+using NewLife.Serialization;
+using Stardust;
+using Stardust.Models;
+using Stardust.Services;
+
+namespace DeployAgent;
+
+public class DeployWorker : IHostedService
+{
+    private readonly AppClient _appClient;
+
+    public DeployWorker(AppClient appClient)
+    {
+        _appClient = appClient;
+    }
+
+    public Task StartAsync(CancellationToken cancellationToken)
+    {
+        _appClient.RegisterCommand("deploy/compile", OnCompile);
+
+        return Task.CompletedTask;
+    }
+
+    public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
+
+    private String OnCompile(String args)
+    {
+        if (args.IsNullOrEmpty()) throw new ArgumentNullException(nameof(args));
+
+        var cmd = args.ToJsonEntity<CompileCommand>();
+        if (cmd == null || cmd.Repository.IsNullOrEmpty()) throw new ArgumentNullException(nameof(cmd.Repository));
+
+        //todo 拉取代码编译逻辑
+
+        return "OK";
+    }
+}
Modified +5 -2
diff --git a/DeployAgent/Program.cs b/DeployAgent/Program.cs
index 8be7183..27106dd 100644
--- a/DeployAgent/Program.cs
+++ b/DeployAgent/Program.cs
@@ -1,4 +1,5 @@
-using NewLife.Log;
+using DeployAgent;
+using NewLife.Log;
 using NewLife.Model;
 using Stardust;
 
@@ -7,11 +8,13 @@ XTrace.UseConsole();
 
 // 初始化对象容器,提供注入能力
 var services = ObjectContainer.Current;
-services.AddSingleton(XTrace.Log);
+//services.AddSingleton(XTrace.Log);
 
 // 配置星尘。自动读取配置文件 config/star.config 中的服务器地址
 var star = services.AddStardust();
 
+services.AddHostedService<DeployWorker>();
+
 var host = services.BuildHost();
 
 // 异步阻塞,友好退出
Added +20 -0
diff --git a/Stardust/Models/CompileCommand.cs b/Stardust/Models/CompileCommand.cs
new file mode 100644
index 0000000..4df8d9f
--- /dev/null
+++ b/Stardust/Models/CompileCommand.cs
@@ -0,0 +1,20 @@
+namespace Stardust.Models;
+
+/// <summary>编译命令参数</summary>
+public class CompileCommand
+{
+    /// <summary>代码库。下载代码的位置</summary>
+    public String? Repository { get; set; }
+
+    /// <summary>分支</summary>
+    public String? Branch { get; set; }
+
+    /// <summary>项目路径。需要编译的项目路径</summary>
+    public String? ProjectPath { get; set; }
+
+    /// <summary>项目类型。默认dotnet</summary>
+    public ProjectKinds ProjectKind { get; set; }
+
+    /// <summary>打包过滤器。需要打包哪些文件,支持通配符,多项分号隔开</summary>
+    public String? PackageFilters { get; set; }
+}