diff --git a/.github/workflows/packer.yml b/.github/workflows/packer.yml index f695d01120d3..adbd900221f4 100644 --- a/.github/workflows/packer.yml +++ b/.github/workflows/packer.yml @@ -129,7 +129,7 @@ jobs: with: name: grouped-Minecraft-Mod-Language-Modpack-${{ matrix.version }} path: | - Minecraft-Mod-Language-Modpack-${{ matrix.version }}-namespaced.zip + grouped-Minecraft-Mod-Language-Modpack-${{ matrix.version }}.zip if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' upload: @@ -163,7 +163,7 @@ jobs: uses: actions/download-artifact@v4 with: path: artifacts/ - pattern: Minecraft-Mod-Language-Modpack-* # 先不拉取新格式,否则会乱掉 + # pattern: Minecraft-Mod-Language-Modpack-* # Pending: 把按命名空间传的包也传上去 diff --git a/src/Packer/Program.cs b/src/Packer/Program.cs index d75c283aa410..fb871c68b89b 100644 --- a/src/Packer/Program.cs +++ b/src/Packer/Program.cs @@ -27,13 +27,7 @@ public static async Task Main(string version, bool increment = false, bool group version: version); Log.Information("开始对版本 {0} 的打包", config.Base.Version); - var targetModIdentifiers = increment ? GitHelpers.EnumerateChangedMods(config.Base.Version) - : Enumerable.Empty(); - - - - - + var targetModIdentifiers = increment ? GitHelpers.EnumerateChangedMods(config.Base.Version) : []; IEnumerable initialFiles = [ new RawFile(new FileInfo("./projects/templates/pack.png"), "pack.png"), @@ -70,7 +64,7 @@ public static async Task Main(string version, bool increment = false, bool group if (grouped) { - string packName = $"./Minecraft-Mod-Language-Modpack-{config.Base.Version}-namespaced.zip"; + string packName = $"./grouped-Minecraft-Mod-Language-Modpack-{config.Base.Version}.zip"; Log.Information("组合包:{0}", packName); var acceptableVersions = config.Base.FallbackVersions.Prepend(config.Base.Version).ToList(); diff --git a/src/Uploader/Program.cs b/src/Uploader/Program.cs index f3675e993c1d..4cdf3e7abece 100644 --- a/src/Uploader/Program.cs +++ b/src/Uploader/Program.cs @@ -1,17 +1,18 @@ +using Octokit; using Renci.SshNet; using Serilog; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Security.Cryptography; using System.Threading.Tasks; -using Octokit; namespace Uploader { static class Program { + static readonly string ServerPathPrefix = "/var/www/html/files"; + static async Task Main(string host, string name, string password) { Log.Logger = new LoggerConfiguration() @@ -34,7 +35,8 @@ static async Task Main(string host, string name, string password) Log.Warning("未找到 artifact 文件夹。可能是所有版本都没有触发打包。"); return; } - + + // 旧格式 var packs = artifactDirectory .EnumerateFiles("Minecraft-Mod-Language-Modpack-*.zip", SearchOption.AllDirectories) .Select(_ => @@ -49,33 +51,56 @@ static async Task Main(string host, string name, string password) .Select(_ => (name: _.Name, file: _)); var files = packs.Concat(md5s); - Console.WriteLine("待上传的文件数目:{0}", files.Count()); + // 新格式 + var newPacks = artifactDirectory + .EnumerateFiles("grouped-Minecraft-Mod-Language-Modpack-*.zip", SearchOption.AllDirectories); + + // 新包只往服务器传 + await UploadToServer(host, name, password, files.Concat(newPacks.Select(_ => (_.Name, _)))); + await UnpackOnServer(host, name, password, newPacks); - await UploadToServer(host, name, password, files); await UploadSnapshotAssets(client, files); await UpdateAutobuildAssets(client, files); + } - async static Task UploadToServer(string host, string username, string password, IEnumerable<(string name, FileInfo file)> files) + async static Task UnpackOnServer(string host, string username, string password, IEnumerable files) { - using var scpClient = new ScpClient(host, port: 22, username, password); - scpClient.Connect(); // 与下载服务器建立连接 + using var sshClient = new SshClient(host, port: 22, username, password); + sshClient.Connect(); - // 确认连接状态 - if (scpClient.IsConnected) + // 目标位置:<...>/new// + foreach (var file in files) { - Log.Information("SCP服务器连接成功"); - } - else - { - Log.Error("SCP服务器连接失败"); - throw new InvalidOperationException(); + var packName = file.Name; + var version = packName["grouped-Minecraft-Mod-Language-Modpack-".Length..^".zip".Length]; + + var targetDirectory = $"{ServerPathPrefix}/{version}/"; + var zipPath = $"{ServerPathPrefix}/{packName}"; + + if (sshClient.RunCommand($"unzip -o '{zipPath}' -d '{targetDirectory}'").ExitStatus == 0) + { + Log.Information(" 解包文件:{0}", zipPath); + } + else + { + Log.Warning(" 解包失败:{0}", zipPath); + } + + sshClient.RunCommand($"rm '{zipPath}'"); } + } + + async static Task UploadToServer(string host, string username, string password, IEnumerable<(string name, FileInfo file)> files) + { + using var sftpClient = new SftpClient(host, port: 22, username, password); + sftpClient.Connect(); foreach (var (name, file) in files) { - var destinationName = $"/var/www/html/files/{name}"; - scpClient.Upload(file, destinationName); // 没有async :( + using var stream = file.OpenRead(); + var destinationName = $"{ServerPathPrefix}/{name}"; + await sftpClient.UploadFileAsync(stream, destinationName); Log.Information(" 写入文件:{0}", destinationName); } } diff --git a/src/Uploader/Uploader.csproj b/src/Uploader/Uploader.csproj index 3138052add63..4d476a0e314c 100644 --- a/src/Uploader/Uploader.csproj +++ b/src/Uploader/Uploader.csproj @@ -8,10 +8,10 @@ - +