/// <summary> /// 根据文件清单生成压缩包 /// </summary> /// <param name="dev"></param> /// <param name="item"></param> /// <param name="type"></param> public static void GenerateCompressedPackage(bool dev, PublishDirInfo item, AppDownloadType type) { var fileEx = GetFileExByCompressedType(type); var packPath = GetPackPath(dev, item, fileEx); Console.WriteLine($"正在生成压缩包:{packPath}"); IOPath.FileIfExistsItDelete(packPath); GetCreatePackByCompressedType(type)(packPath, item.Files); using var fileStream = File.OpenRead(packPath); var sha256 = Hashs.String.SHA256(fileStream); var fileInfoM = new PublishFileInfo { SHA256 = sha256, Length = fileStream.Length, Path = packPath, }; if (item.BuildDownloads.ContainsKey(type)) { item.BuildDownloads[type] = fileInfoM; } else { item.BuildDownloads.Add(type, fileInfoM); } }
public static void HandlerItem(bool dev, PublishDirInfo item) { var rpmPath = GetPackPath(dev, item, FileEx.RPM); //var cpioPath = GetPackPath(item, FileEx.CPIO); using var targetStream = File.Open(rpmPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None); //using var cpioStream = File.Open(cpioPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None); using var cpioStream = new MemoryStream(); ArchiveBuilder2 archiveBuilder2 = new() { Log = TaskLoggingHelper.Instance, }; ArchiveBuilder archiveBuilder = archiveBuilder2; var archiveEntries = archiveBuilder.FromDirectory( item.Path, Constants.HARDCODED_APP_NAME, LinuxPackConstants.Prefix, Array.Empty <ITaskItem>()); LinuxPackConstants.AddFileNameDesktop(archiveBuilder2, archiveEntries); //archiveEntries.AddRange(archiveBuilder.FromLinuxFolders(this.LinuxFolders)); archiveEntries = archiveEntries .OrderBy(e => e.TargetPathWithFinalSlash, StringComparer.Ordinal) .ToList(); CpioFileCreator cpioCreator = new CpioFileCreator(); cpioCreator.FromArchiveEntries( archiveEntries, cpioStream); cpioStream.Position = 0; // Prepare the list of dependencies List <PackageDependency> dependencies = new List <PackageDependency>(); if (item.DeploymentMode == DeploymentMode.FDE) { dependencies.Add(new PackageDependency { Name = LinuxPackConstants.aspnetcore_runtime_6_0 }); } //if (this.RpmDotNetDependencies != null) //{ // dependencies.AddRange( // this.RpmDotNetDependencies.Select( // d => GetPackageDependency(d))); //} //if (this.RpmDependencies != null) //{ // dependencies.AddRange( // this.RpmDependencies.Select( // d => GetPackageDependency(d))); //} RpmPackageCreator rpmCreator = new RpmPackageCreator(); rpmCreator.CreatePackage( archiveEntries, cpioStream, LinuxPackConstants.PackageName, Utils.GetVersion(dev), RpmTask.GetPackageArchitecture(item.Name), LinuxPackConstants.Release, LinuxPackConstants.CreateUser, LinuxPackConstants.UserName, LinuxPackConstants.InstallService, LinuxPackConstants.ServiceName, LinuxPackConstants.RpmVendor, LinuxPackConstants.Description, LinuxPackConstants.Url, LinuxPackConstants.Prefix, LinuxPackConstants.PreInstallScript, LinuxPackConstants.PostInstallScript, LinuxPackConstants.PreRemoveScript, LinuxPackConstants.PostRemoveScript, dependencies, null !, privateKey !, targetStream); }
public static void Add(RootCommand command) { // newv 1. (云端)创建新版本号RSA密钥 // getv 1. (云端)获取之前创建新版本号RSA密钥 // 3. (本地)读取剪切板公钥值写入txt的pfx文件中 var ver = new Command("ver", "初始化版本") { Handler = CommandHandler.Create(VerHandlerAsync) }; ver.AddOption(new Option <string>("-token", "jwt")); ver.AddOption(new Option <bool>("-use_last_skey", "是否使用上一个版本的密钥")); ver.AddOption(new Option <bool>("-dev", DevDesc)); command.AddCommand(ver); // 手动发布 pubxml // full 中间步骤多合一 var full = new Command("full", "自动化打包与上传哈希") { Handler = CommandHandler.Create(FullHandlerAsync) }; full.AddOption(new Option <string>("-token", "jwt")); full.AddOption(new Option <string[]>("-val", InputPubDirNameDesc)); full.AddOption(new Option <bool>("-dev", DevDesc)); command.AddCommand(full); #if DEBUG var nsis = new Command("nsis", "调试 NSIS 打包") { Handler = CommandHandler.Create((string path) => { if (!string.IsNullOrWhiteSpace(path)) { var buildDownloads = new Dictionary <AppDownloadType, PublishFileInfo> { { AppDownloadType.Compressed_7z, new PublishFileInfo { Path = path } } }; var dirName = new PublishDirInfo { BuildDownloads = buildDownloads, }; NSISBuild(true, new[] { dirName }); } else { var publish_json_path = PublishJsonFilePath; var publish_json_str = File.ReadAllText(publish_json_path); var dirNames = Serializable.DJSON <PublishDirInfo[]>(publish_json_str) ?.Where(x => x.Name.StartsWith("win-")).ToArray(); if (!dirNames.Any_Nullable()) { Console.WriteLine($"错误:发布配置文件读取失败!{publish_json_path}"); return; } dirNames = dirNames.ThrowIsNull(nameof(dirNames)); NSISBuild(true, dirNames); } }) }; nsis.AddOption(new Option <string>("-path", "7z Path")); command.AddCommand(nsis); #endif }
static void GenerateCompressedPackage(bool dev, PublishDirInfo item) { var type = GetCompressedTypeByRID(item.Name); GenerateCompressedPackage(dev, item, type); }
public static void HandlerItem(bool dev, PublishDirInfo item) { var debPath = GetPackPath(dev, item, FileEx.DEB); //var debTarPath = GetPackPath(item, FileEx.DEB_TAR); var debTarXzPath = GetPackPath(dev, item, FileEx.DEB_TAR_XZ); using var targetStream = File.Open(debPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None); //using var tarStream = File.Open(debTarPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None); using var tarStream = new MemoryStream(); ArchiveBuilder2 archiveBuilder2 = new() { Log = TaskLoggingHelper.Instance, }; ArchiveBuilder archiveBuilder = archiveBuilder2; var archiveEntries = archiveBuilder.FromDirectory( item.Path, Constants.HARDCODED_APP_NAME, LinuxPackConstants.Prefix, Array.Empty <ITaskItem>()); LinuxPackConstants.AddFileNameDesktop(archiveBuilder2, archiveEntries); //archiveEntries.AddRange(archiveBuilder.FromLinuxFolders(this.LinuxFolders)); DebTask.EnsureDirectories(archiveEntries); archiveEntries = archiveEntries .OrderBy(e => e.TargetPathWithFinalSlash, StringComparer.Ordinal) .ToList(); TarFileCreator.FromArchiveEntries(archiveEntries, tarStream); tarStream.Position = 0; // Prepare the list of dependencies List <string> dependencies = new List <string>(); if (item.DeploymentMode == DeploymentMode.FDE) { dependencies.Add(LinuxPackConstants.aspnetcore_runtime_6_0); } //if (this.DebDependencies != null) //{ // var debDependencies = this.DebDependencies.Select(d => d.ItemSpec).ToArray(); // dependencies.AddRange(debDependencies); //} //if (this.DebDotNetDependencies != null) //{ // var debDotNetDependencies = this.DebDotNetDependencies.Select(d => d.ItemSpec).ToArray(); // dependencies.AddRange(debDotNetDependencies); //} // Prepare the list of recommended dependencies List <string> recommends = new List <string>(); //if (this.DebRecommends != null) //{ // recommends.AddRange(this.DebRecommends.Select(d => d.ItemSpec)); //} // XZOutputStream class has low quality (doesn't even know it's current position, // needs to be disposed to finish compression, etc), // So we are doing compression in a separate step using (var tarXzStream = File.Open(debTarXzPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) using (var xzStream = new XZOutputStream(tarXzStream, XZOutputStream.DefaultThreads, XZOutputStream.DefaultPreset, true)) { tarStream.CopyTo(xzStream); } using (var tarXzStream = File.Open(debTarXzPath, FileMode.Open, FileAccess.Read, FileShare.None)) { var pkg = DebPackageCreator.BuildDebPackage( archiveEntries, LinuxPackConstants.PackageName, LinuxPackConstants.Description, LinuxPackConstants.DebMaintainer, Utils.GetVersion(dev), DebTask.GetPackageArchitecture(item.Name), LinuxPackConstants.CreateUser, LinuxPackConstants.UserName, LinuxPackConstants.InstallService, LinuxPackConstants.ServiceName, LinuxPackConstants.Prefix, //LinuxPackConstants.DebSection, "utils", LinuxPackConstants.DebPriority, LinuxPackConstants.DebHomepage, LinuxPackConstants.PreInstallScript, LinuxPackConstants.PostInstallScript, LinuxPackConstants.PreRemoveScript, LinuxPackConstants.PostRemoveScript, dependencies, recommends, null !); DebPackageCreator.WriteDebPackage( archiveEntries, tarXzStream, targetStream, pkg); } File.Delete(debTarXzPath); }