ToB企服应用市场:ToB评测及商务社交产业平台

标题: 基于DotNetty实现自动发布 - 项目的配置与发现 [打印本页]

作者: 河曲智叟    时间: 2024-2-5 12:06
标题: 基于DotNetty实现自动发布 - 项目的配置与发现
前言

上一篇,我们实现了基于 DotNetty 的通信基础模块的搭建,本篇,主要实现待发布 Web 项目的集成。
创建待发布项目

待发布项目集成 Git

Git 是一个开源的分布式版本控制系统。我们使用它实现自动化检测需要发布的文件。
配置待发布项目




解决方案模型
  1. /// <summary> 解决方案领域模型 </summary>
  2. [Table("Solution")]
  3. public class Solution
  4. {
  5.     [Key]
  6.     public int Id { get; set; }
  7.     /// <summary> 解决方案名称 </summary>
  8.     public string SolutionName { get; set; } = string.Empty;
  9.     /// <summary> 解决方案Git仓储路径 </summary>
  10.     public string GitRepositoryPath { get; set; } = string.Empty;
  11. }
复制代码
确定配置解决方案
  1. /// <summary> 确定配置解决方案 </summary>
  2. [RelayCommand]
  3. private void OkConfigSolution()
  4. {
  5.     try
  6.     {
  7.         if (string.IsNullOrEmpty(ConfigSolution.SolutionName))
  8.         {
  9.             throw new Exception("请填写解决方案名称");
  10.         }
  11.         if (!GitHelper.IsValidRepository(ConfigSolution.GitRepositoryPath))
  12.         {
  13.             throw new Exception("非法的Git仓储路径");
  14.         }
  15.     }
  16.     catch (Exception ex)
  17.     {
  18.         Growl.ClearGlobal();
  19.         Growl.WarningGlobal(ex.Message);
  20.         return;
  21.     }
  22.     //持久化到Sqlite
  23.     solutionRepository.AddSolution(ConfigSolution.Map2Entity());
  24.     Growl.SuccessGlobal("操作成功");
  25.     //重新加载解决方案
  26.     LoadSolutions();
  27.     //关闭弹窗
  28.     configSolutionDialog?.Close();
  29. }
复制代码
执行 Git 命令
  1.     /// <summary> 执行git命令 </summary>
  2.     private async Task RunGitCommand(string cmd)
  3.     {
  4.         var loading = Loading.Show();
  5.         string output = string.Empty;
  6.         LogText = string.Empty;
  7.         await Task.Run(() =>
  8.         {
  9.             var _process = new Process();
  10.             _process.StartInfo.WorkingDirectory = GitRepositoryPath;
  11.             _process.StartInfo.FileName = "cmd.exe";
  12.             _process.StartInfo.Arguments = "/C " + cmd;
  13.             _process.StartInfo.UseShellExecute = false;
  14.             _process.StartInfo.CreateNoWindow = true;
  15.             _process.StartInfo.RedirectStandardInput = true;
  16.             _process.StartInfo.RedirectStandardOutput = true;
  17.             _process.StartInfo.RedirectStandardError = true;
  18.             _process.Start();//启动程序
  19.             output = _process.StandardOutput.ReadToEnd();
  20.             if (string.IsNullOrEmpty(output))
  21.             {
  22.                 output = _process.StandardError.ReadToEnd();
  23.                 if (string.IsNullOrEmpty(output))
  24.                 {
  25.                     output = "没有返回值";
  26.                 }
  27.             }
  28.             _process.WaitForExit();
  29.             _process.Close();
  30.         });
  31.         LogText = output;
  32.         loading.Close();
  33.     }
复制代码
总结

至此,我们实现了待发布项目的配置与发现,简单集成了常用的 Git 命令等
代码仓库

项目暂且就叫 OpenDeploy 吧

欢迎大家拍砖,Star
下一步

计划下一步,实现一键发布,自动检测到自上次发布以来的代码变化,自动识别要发布的文件,一次性打包通过 DotNetty 发送到服务器

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4