Skip to content

Commit

Permalink
CD
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Nov 27, 2021
1 parent f59c600 commit 093b642
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2FSteamTools-Team%2FSteamTools%2Fbadge%3Fref%3Ddevelop&style=flat-square)](https://actions-badge.atrox.dev/SteamTools-Team/SteamTools/goto?ref=develop)
[![GitHub Star](https://img.shields.io/github/stars/SteamTools-Team/SteamTools.svg?style=social)](https://github.com/SteamTools-Team/SteamTools)
[![Gitee Star](https://gitee.com/rmbgame/SteamTools/badge/star.svg)](https://gitee.com/rmbgame/SteamTools)
[![QQ群](https://img.shields.io/badge/QQ群-101075312-blue.svg?style=flat-square&color=12b7f5)](https://qm.qq.com/cgi-bin/qm/qr?k=JVlZF31RKSDqcsxfEaw6AQE75P2NF18F&jump_from=webapi)
[![QQ群](https://img.shields.io/badge/QQ群-960746023-blue.svg?style=flat-square&color=12b7f5)](https://jq.qq.com/?_wv=1027&k=3JKPt4xC)
</div>

<div align="center"><img src="./resources/screenshots.jpg" /></div>
Expand Down
23 changes: 23 additions & 0 deletions src/ST.Tools.Publish/Models/CreateVersionRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System.Application.Models
{
public class CreateVersionRequest
{
public string? Version { get; set; }

/// <summary>
/// 新版本的描述
/// </summary>
public string? Desc { get; set; }

/// <summary>
/// 是否使用上一个版本的密钥
/// </summary>
public bool UseLastSKey { get; set; }
}
}
53 changes: 52 additions & 1 deletion src/ST.Tools.Publish/Steps/Step_cd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using System.CommandLine.Invocation;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using static System.Application.Utils;
using static System.ProjectPathUtil;
Expand All @@ -23,6 +26,16 @@ 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", "自动化打包")
Expand All @@ -33,8 +46,21 @@ public static void Add(RootCommand command)
full.AddOption(new Option<string[]>("-val", InputPubDirNameDesc));
full.AddOption(new Option<bool>("-dev", DevDesc));
command.AddCommand(full);
}

// wdb 11. (云端)读取上一步上传的数据写入数据库中
static async Task VerHandlerAsync(string token, bool use_last_skey, bool dev)
{
throw new NotImplementedException("TODO api_version_create");
var request = new CreateVersionRequest
{
Version = Utils.Version,
Desc = ReadVersionDesc(),
UseLastSKey = use_last_skey,
};
using var client = GetHttpClient();
using var rsp = await client.PostAsJsonAsync(api_version_create, request);
var value = await rsp.Content.ReadFromJsonAsync<AppIdWithPublicKey>();
if (!Step3.Handler(value, dev)) throw new Exception("Step3.Handler fail.");
}

static async Task FullHandlerAsync(string token, string[] val, bool dev)
Expand Down Expand Up @@ -82,6 +108,9 @@ static async Task FullHandlerAsync(string token, string[] val, bool dev)
// 12. (本地)读取 **Publish.json** 中的 SHA256 值写入 release-template.md
StepRel.Handler2(endWriteOK: false);

// wdb 11. (云端)读取上一步上传的数据写入数据库中
throw new NotImplementedException("TODO wdb");

Console.WriteLine("OK");
}

Expand Down Expand Up @@ -191,5 +220,27 @@ static AppDownloadType GetCompressedTypeByRID(string rid)
AppDownloadType.Compressed_XZ => CreateXZPack,
_ => throw new ArgumentOutOfRangeException(nameof(compressedType), compressedType, null),
};

/// <summary>
/// 读取更新日志
/// </summary>
/// <returns></returns>
static string ReadVersionDesc()
{
throw new NotImplementedException("TODO");
return string.Empty;
}

static HttpClient GetHttpClient()
{
var client = new HttpClient
{
BaseAddress = new Uri(api_base_url)
};
return client;
}

const string api_base_url = "https://api.steampp.net";
const string api_version_create = "/api/version";
}
}
68 changes: 39 additions & 29 deletions src/ST.Tools.Publish/Steps/Step_readrsa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,50 @@ public static void Add(RootCommand command)
}
var value = Serializable.DJSON<AppIdWithPublicKey>(val);
if (value == default)
{
Console.WriteLine("错误:读取剪切板值不能为 Null!");
return;
}
if (value.AppId == default)
{
Console.WriteLine("错误:读取剪切板值 AppId 无效!");
return;
}
if (string.IsNullOrWhiteSpace(value.PublicKey))
{
Console.WriteLine("错误:读取剪切板值 PublicKey 无效!");
return;
}
static string Env(bool dev) => dev ? "debug" : "release";
var env = Env(dev);
var pfxFilePath = Path.Combine(projPath,
$"rsa-public-key-{env}.pfx");
IOPath.FileIfExistsItDelete(pfxFilePath);
File.WriteAllText(pfxFilePath, value.PublicKey);
var appIdFilePath = Path.Combine(projPath,
$"app-id-{env}.pfx");
IOPath.FileIfExistsItDelete(appIdFilePath);
File.WriteAllBytes(appIdFilePath, value.AppId.ToByteArray());
Handler(value, dev);
Console.WriteLine("完成。");
Console.WriteLine(pfxFilePath);
Console.WriteLine(appIdFilePath);
});
command.AddCommand(rr);
}

public static bool Handler(AppIdWithPublicKey? value, bool dev)
{
if (value == default)
{
Console.WriteLine("错误:读取剪切板值不能为 Null!");
return false;
}

if (value.AppId == default)
{
Console.WriteLine("错误:读取剪切板值 AppId 无效!");
return false;
}
if (string.IsNullOrWhiteSpace(value.PublicKey))
{
Console.WriteLine("错误:读取剪切板值 PublicKey 无效!");
return false;
}

static string Env(bool dev) => dev ? "debug" : "release";
var env = Env(dev);

var pfxFilePath = Path.Combine(projPath,
$"rsa-public-key-{env}.pfx");
IOPath.FileIfExistsItDelete(pfxFilePath);
File.WriteAllText(pfxFilePath, value.PublicKey);

var appIdFilePath = Path.Combine(projPath,
$"app-id-{env}.pfx");
IOPath.FileIfExistsItDelete(appIdFilePath);
File.WriteAllBytes(appIdFilePath, value.AppId.ToByteArray());

Console.WriteLine(pfxFilePath);
Console.WriteLine(appIdFilePath);

return true;
}
}
}

0 comments on commit 093b642

Please sign in to comment.