mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
Merge branch 'dev' of https://github.com/MaaAssistantArknights/MaaAssistantArknights into dev
This commit is contained in:
2
.github/workflows/dev-build.yml
vendored
2
.github/workflows/dev-build.yml
vendored
@@ -50,7 +50,7 @@ jobs:
|
||||
name: windows-latest
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
- name: Cache .nuke/temp, ~/.nuget/packages
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
|
||||
2
.github/workflows/release-maa.yml
vendored
2
.github/workflows/release-maa.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
||||
name: windows-latest
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
- name: Cache .nuke/temp, ~/.nuget/packages
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"AppVeyor",
|
||||
"AzurePipelines",
|
||||
"Bamboo",
|
||||
"Bitbucket",
|
||||
"Bitrise",
|
||||
"GitHubActions",
|
||||
"GitLab",
|
||||
|
||||
@@ -8,7 +8,6 @@ public class ActionConfiguration : Enumeration
|
||||
{
|
||||
public static readonly ActionConfiguration DevBuild = new() { Value = "dev-build" };
|
||||
public static readonly ActionConfiguration ReleaseMaa = new() { Value = "release-maa" };
|
||||
public static readonly ActionConfiguration ReleaseMaaResource = new() { Value = "release-maa-resource" };
|
||||
|
||||
public static implicit operator string(ActionConfiguration configuration)
|
||||
{
|
||||
@@ -19,7 +18,6 @@ public class ActionConfiguration : Enumeration
|
||||
{
|
||||
"dev-build" => DevBuild,
|
||||
"release-maa" => ReleaseMaa,
|
||||
"release-maa-resource" => ReleaseMaaResource,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
using Nuke.Common;
|
||||
using Nuke.Common.Execution;
|
||||
using Nuke.Common.Git;
|
||||
using Nuke.Common.IO;
|
||||
using Nuke.Common.Tools.GitHub;
|
||||
using Octokit;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using MaaBuilder.Models;
|
||||
|
||||
namespace MaaBuilder;
|
||||
|
||||
[CheckBuildProjectConfigurations]
|
||||
public partial class Build : NukeBuild
|
||||
{
|
||||
public static int Main()
|
||||
@@ -40,16 +34,16 @@ public partial class Build : NukeBuild
|
||||
const string DevBranch = "dev";
|
||||
|
||||
const string MaaDevBundlePackageNameTemplate = "MaaBundle-Dev-{VERSION}";
|
||||
const string MaaResourcePackageNameTemplate = "MaaResource-{VERSION}";
|
||||
|
||||
string Version = "";
|
||||
string ChangeLog = "";
|
||||
|
||||
string MaaDevBundlePackageName => MaaDevBundlePackageNameTemplate.Replace("{VERSION}", Version);
|
||||
string MaaResourcePackageName => MaaResourcePackageNameTemplate.Replace("{VERSION}", Version);
|
||||
|
||||
string LatestTag;
|
||||
|
||||
List<Checksum> ArtifactChecksums = new();
|
||||
|
||||
protected override void OnBuildInitialized()
|
||||
{
|
||||
Parameters = new BuildParameters(this);
|
||||
|
||||
@@ -224,13 +224,6 @@ public partial class Build
|
||||
Assert.True(GhTag is not null, "ReleaseMaa -> Auto Triggered,Tag 为 Null");
|
||||
Assert.True(GitHubPersonalAccessToken is not null, "ReleaseMaa -> Auto Triggered,PAT 为 Null");
|
||||
}
|
||||
|
||||
// 若是 ReleaseMaaResource,Branch 必须为 Master,PAT 必须存在
|
||||
if (GhActionName == ActionConfiguration.ReleaseMaaResource)
|
||||
{
|
||||
Assert.True(GhBranch == MasterBranch, "ReleaseMaaResource -> Auto Triggered,Branch 不为 master");
|
||||
Assert.True(GitHubPersonalAccessToken is not null, "ReleaseMaaResource -> Auto Triggered,PAT 为 Null");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using MaaBuilder.Models;
|
||||
using Microsoft.Extensions.FileSystemGlobbing;
|
||||
using Nuke.Common;
|
||||
@@ -11,7 +14,7 @@ namespace MaaBuilder;
|
||||
|
||||
public partial class Build
|
||||
{
|
||||
void BundlePackage(AbsolutePath input, string bundleName)
|
||||
void BundlePackage(AbsolutePath input, string bundleName, string packageType)
|
||||
{
|
||||
var packName = bundleName;
|
||||
if (packName.EndsWith(".zip") is false)
|
||||
@@ -27,6 +30,29 @@ public partial class Build
|
||||
|
||||
Information($"创建压缩文件:{bundle}");
|
||||
ZipFile.CreateFromDirectory(input, bundle, CompressionLevel.SmallestSize, false);
|
||||
|
||||
var sourceDirectory = new DirectoryInfo(input);
|
||||
var allFiles = sourceDirectory.GetFiles("*.*", SearchOption.AllDirectories);
|
||||
var allHashes = allFiles
|
||||
.Select(x => FileSystemTasks.GetFileHash(x.FullName).ToUpperInvariant())
|
||||
.OrderBy(x => x);
|
||||
var hashCombinedBuilder = new StringBuilder();
|
||||
foreach (var h in allHashes)
|
||||
{
|
||||
hashCombinedBuilder.Append(h);
|
||||
}
|
||||
var combinedHashString = hashCombinedBuilder.ToString();
|
||||
var hash = GetStringMd5(combinedHashString);
|
||||
|
||||
var bundleHash = FileSystemTasks.GetFileHash(bundle).ToUpperInvariant();
|
||||
|
||||
ArtifactChecksums.Add(new Checksum
|
||||
{
|
||||
FileHash = bundleHash,
|
||||
FileIdentity = hash,
|
||||
FileName = packName,
|
||||
PackageType = packageType
|
||||
});
|
||||
}
|
||||
|
||||
static void MoveGlobFiles(AbsolutePath source, AbsolutePath target, IEnumerable<string> include, IEnumerable<string> exclude)
|
||||
@@ -78,6 +104,14 @@ public partial class Build
|
||||
ZipFile.ExtractToDirectory(file, tempDir, true);
|
||||
}
|
||||
|
||||
BundlePackage(tempDir, bundleName);
|
||||
BundlePackage(tempDir, bundleName, package.PackageType);
|
||||
}
|
||||
|
||||
static string GetStringMd5(string input)
|
||||
{
|
||||
using var md5 = MD5.Create();
|
||||
var inputBytes = Encoding.ASCII.GetBytes(input);
|
||||
var hashBytes = md5.ComputeHash(inputBytes);
|
||||
return Convert.ToHexString(hashBytes);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public partial class Build
|
||||
|
||||
void CreateGitHubRelease(string repo, string commitish, string releaseName)
|
||||
{
|
||||
var assets = Parameters.ArtifactOutput.GlobFiles("*.zip", "checksum.txt");
|
||||
var assets = Parameters.ArtifactOutput.GlobFiles("*.zip", "checksum.json");
|
||||
|
||||
var release = new NewRelease(Version)
|
||||
{
|
||||
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using MaaBuilder.Models;
|
||||
using System.Text.Json;
|
||||
using Nuke.Common;
|
||||
using Nuke.Common.IO;
|
||||
|
||||
namespace MaaBuilder;
|
||||
|
||||
@@ -16,7 +13,7 @@ public partial class Build
|
||||
.Executes(() =>
|
||||
{
|
||||
var buildOutput = Parameters.BuildOutput / BuildConfiguration.Release;
|
||||
BundlePackage(buildOutput, MaaDevBundlePackageName);
|
||||
BundlePackage(buildOutput, MaaDevBundlePackageName, "DevBundle");
|
||||
});
|
||||
|
||||
Target UseMaaRelease => _ => _
|
||||
@@ -40,18 +37,14 @@ public partial class Build
|
||||
.Executes(() =>
|
||||
{
|
||||
Information("已完成打包");
|
||||
var checksumFile = Parameters.ArtifactOutput / "checksum.txt";
|
||||
var checksum = new List<string>();
|
||||
var checksumFile = Parameters.ArtifactOutput / "checksum.json";
|
||||
|
||||
foreach (var file in Parameters.ArtifactOutput.GlobFiles("*.zip"))
|
||||
foreach (var chs in ArtifactChecksums)
|
||||
{
|
||||
var size = (new FileInfo(file).Length / 1024.0 / 1024.0).ToString("F3");
|
||||
var hash = FileSystemTasks.GetFileHash(file);
|
||||
Information($"找到 Artifact ({hash}):{file} ({size} MB)");
|
||||
|
||||
checksum.Add($"{file.Name}:{hash}");
|
||||
Information($"Artifact:{chs}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(checksumFile, checksum, Encoding.UTF8);
|
||||
|
||||
var str = JsonSerializer.Serialize(ArtifactChecksums);
|
||||
File.WriteAllText(checksumFile, str, Encoding.UTF8);
|
||||
});
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public partial class Build
|
||||
{
|
||||
Target UsePublishArtifact => _ => _
|
||||
.After(SetPackageBundled, SetMaaChangeLog)
|
||||
.Produces(RootDirectory / "artifacts" / "*.zip")
|
||||
.Produces(RootDirectory / "artifacts" / "*.*")
|
||||
.OnlyWhenStatic(() => GitHubActions != null);
|
||||
|
||||
Target UsePublishRelease => _ => _
|
||||
@@ -21,7 +21,7 @@ public partial class Build
|
||||
|
||||
if (Parameters.GhActionName == ActionConfiguration.DevBuild)
|
||||
{
|
||||
Information($"DevBuild 跳过发布 Release");
|
||||
Information("DevBuild 跳过发布 Release");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,8 +36,6 @@ public partial class Build
|
||||
Information($"运行 ReleaseMaa 将在 {Parameters.MainRepo} 创建 Release {Parameters.GhTag}");
|
||||
|
||||
CreateGitHubRelease(Parameters.MainRepo, Parameters.CommitHashFull, Version);
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Nuke.Common" Version="6.0.3" />
|
||||
<PackageReference Include="Nuke.Common" Version="6.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VariableHidesOuterVariable/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassNeverInstantiated_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBeMadeStatic_002ELocal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=builder/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=builder_005Cci/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=builder_005Chelper/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=builder_005Cjob/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_INTERNAL_MODIFIER/@EntryValue">Implicit</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_PRIVATE_MODIFIER/@EntryValue">Implicit</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/METHOD_OR_OPERATOR_BODY/@EntryValue">ExpressionBody</s:String>
|
||||
|
||||
18
tools/MaaBuilder/Models/Checksum.cs
Normal file
18
tools/MaaBuilder/Models/Checksum.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MaaBuilder.Models;
|
||||
|
||||
public record Checksum
|
||||
{
|
||||
[JsonPropertyName("file_name")]
|
||||
public string FileName { get; set; }
|
||||
|
||||
[JsonPropertyName("package_type")]
|
||||
public string PackageType { get; set; }
|
||||
|
||||
[JsonPropertyName("file_hash")]
|
||||
public string FileHash { get; set; }
|
||||
|
||||
[JsonPropertyName("file_identity")]
|
||||
public string FileIdentity { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user