Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/packer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
uses: actions/download-artifact@v4
with:
path: artifacts/
pattern: Minecraft-Mod-Language-Modpack-* # 先不拉取新格式,否则会乱掉
# pattern: Minecraft-Mod-Language-Modpack-*

# Pending: 把按命名空间传的包也传上去

Expand Down
10 changes: 2 additions & 8 deletions src/Packer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();





var targetModIdentifiers = increment ? GitHelpers.EnumerateChangedMods(config.Base.Version) : [];

IEnumerable<IResourceFileProvider> initialFiles = [
new RawFile(new FileInfo("./projects/templates/pack.png"), "pack.png"),
Expand Down Expand Up @@ -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();
Expand Down
61 changes: 43 additions & 18 deletions src/Uploader/Program.cs
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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(_ =>
Expand All @@ -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<FileInfo> 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/<version>/
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("<Server> 解包文件:{0}", zipPath);
}
else
{
Log.Warning("<Server> 解包失败:{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("<Server> 写入文件:{0}", destinationName);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uploader/Uploader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neon.SSH.NET" Version="2.11.1" />
<PackageReference Include="Octokit" Version="14.0.0" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="SSH.NET" Version="2026.0.0" />
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.4.0-alpha.22272.1" />
</ItemGroup>

Expand Down
Loading