Skip to content

Commit 7c620f6

Browse files
committed
Post-work support
支持部分文件打包 (把测试的那一堆commit合进来了)
1 parent ca7c460 commit 7c620f6

8 files changed

Lines changed: 190 additions & 114 deletions

File tree

.github/workflows/packer.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,51 @@ jobs:
1717
name: Build / Cache Packer
1818
runs-on: windows-latest
1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 1
23+
sparse-checkout: src
2124

2225
# 缓存程序。一方面,在不同job之间需要这么做;另一方面,大约可以改善运行时间?
2326
# actions/cache的逻辑会在job末尾缓存打包程序;如果不命中,就自行构造程序。
2427
- name: Cache Packer
2528
id: cache-packer
2629
uses: actions/cache@v3
2730
with:
28-
key: ${{ runner.os }}-${{ hashFiles('src/Pakcer/**') }}
29-
path: Packer.exe
31+
key: ${{ runner.os }}-Packer-${{ hashFiles('src/Packer/**') }}
32+
path: |
33+
Packer.exe
34+
git2-*.dll
3035
lookup-only: true
3136

3237
# 构造程序
3338
- name: Build Packer if not cached
34-
if: steps.cache-packer.outputs.cache_hit != 'true'
39+
if: steps.cache-packer.outputs.cache-hit != 'true'
3540
run: dotnet publish .\src\Packer\Packer.csproj -o ./ -r win-x64 -p:PublishSingleFile=true
3641

3742
build-uploader:
3843
if: github.repository == 'CFPAOrg/Minecraft-Mod-Language-Package'
3944
name: Build / Cache Uploader
4045
runs-on: windows-latest
4146
steps:
42-
- uses: actions/checkout@v2
47+
- uses: actions/checkout@v4
48+
with:
49+
fetch-depth: 1
50+
sparse-checkout: src
4351

4452
# 缓存程序。一方面,在不同job之间需要这么做;另一方面,大约可以改善运行时间?
4553
# actions/cache的逻辑会在job末尾缓存打包程序;如果不命中,就自行构造程序。
4654
- name: Cache Uploader
4755
id: cache-uploader
4856
uses: actions/cache@v3
4957
with:
50-
key: ${{ runner.os }}-${{ hashFiles('src/Uploader/**') }}
58+
key: ${{ runner.os }}-Uploader-${{ hashFiles('src/Uploader/**') }}
5159
path: Uploader.exe
5260
lookup-only: true
5361

5462
# 构造程序
5563
- name: Build Uploader if not cached
56-
if: steps.cache-uploader.outputs.cache_hit != 'true'
64+
if: steps.cache-uploader.outputs.cache-hit != 'true'
5765
run: dotnet publish .\src\Uploader\Uploader.csproj -o ./ -r win-x64 -p:PublishSingeFile=true
5866

5967
initialize-release:
@@ -102,8 +110,10 @@ jobs:
102110
id: cache-restore
103111
uses: actions/cache/restore@v3
104112
with:
105-
key: ${{ runner.os }}-${{ hashFiles('source/Pakcer/**') }}
106-
path: Packer.exe
113+
key: ${{ runner.os }}-${{ hashFiles('source/Packer/**') }}
114+
path: |
115+
Packer.exe
116+
git2-*.dll
107117
fail-on-cache-miss: true # 前一步理应构造过的。如果不命中,肯定有问题,不如直接挂掉。
108118

109119
- name: Check changed path on ${{ matrix.version }}
@@ -117,6 +127,7 @@ jobs:
117127
src/**
118128
119129
- name: Run Packer for ${{ matrix.version }}
130+
# 分发包中应当包含全部内容
120131
run: ./Packer --version="${{ matrix.version }}"
121132
# 运行逻辑:内容有更改 或 手动运行
122133
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'

.github/workflows/pr-packer.yml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,27 @@ jobs:
1717
name: Build / Cache Packer
1818
runs-on: windows-latest
1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 1
23+
sparse-checkout: src
24+
2125

2226
# 缓存程序。一方面,在不同job之间需要这么做;另一方面,大约可以改善运行时间?
2327
# actions/cache的逻辑会在job末尾缓存打包程序;如果不命中,就自行构造程序。
2428
- name: Cache Packer
2529
id: cache-packer
2630
uses: actions/cache@v3
2731
with:
28-
key: ${{ runner.os }}-${{ hashFiles('src/Pakcer/**') }}
29-
path: Packer.exe
32+
key: ${{ runner.os }}-Packer-${{ hashFiles('src/Packer/**') }}
33+
path: |
34+
Packer.exe
35+
git2-*.dll
3036
lookup-only: true
3137

3238
# 构造程序
3339
- name: Build Packer if not cached
34-
if: steps.cache-packer.outputs.cache_hit != 'true'
40+
if: steps.cache-packer.outputs.cache-hit != 'true'
3541
run: dotnet publish .\src\Packer\Packer.csproj -o ./ -r win-x64 -p:PublishSingleFile=true
3642

3743

@@ -48,15 +54,18 @@ jobs:
4854
steps:
4955
- uses: actions/checkout@v2
5056
with:
51-
fetch-depth: 20 # 显然,需要有提交历史才能比较提交。20这个数是任意的。
57+
fetch-depth: 2
58+
- run: git fetch --depth=1 origin main
5259

5360
# 由于Github的限制,这里需要重新拉取打包程序。
5461
- name: Restore Packer
5562
id: cache-restore
5663
uses: actions/cache/restore@v3
5764
with:
58-
key: ${{ runner.os }}-${{ hashFiles('src/Pakcer/**') }}
59-
path: Packer.exe
65+
key: ${{ runner.os }}-${{ hashFiles('src/Packer/**') }}
66+
path: |
67+
Packer.exe
68+
git2-*.dll
6069
fail-on-cache-miss: true # 前一步理应构造过的。如果不命中,肯定有问题,不如直接挂掉。
6170

6271
- name: Check changed path on ${{ matrix.version }}
@@ -65,16 +74,26 @@ jobs:
6574
with:
6675
# 判断位置:该版本文件、该版本配置、代码
6776
paths: >
68-
projects/${{ matrix.version }}
77+
projects/${{ matrix.version }}/**
78+
config/packer/${{ matrix.version }}.json
79+
src/**
80+
81+
- name: Check critical path on ${{ matrix.version }}
82+
uses: MarceloPrado/has-changed-path@v1.0
83+
id: check-critical-changes
84+
with:
85+
# 判断位置:该版本配置、代码
86+
paths: >
6987
config/packer/${{ matrix.version }}.json
7088
src/**
7189
7290
- name: Run Packer for ${{ matrix.version }}
73-
run: ./Packer --version="${{ matrix.version }}"
91+
# 部分包原则:Packer和配置均没有改动
92+
run: ./Packer --version="${{ matrix.version }}" --increment=${{ !steps.check-critical-changes.outputs.changed }}
7493
# 运行逻辑:内容有更改 或 手动运行
7594
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
7695

77-
# 额 要两分半才能传完 然而 GitHub actions 直接传的话 会压成 zip 内套 zip 就这样了吧 --cy
96+
# 额 要两分半才能传完 然而 GitHub actions 直接传的话 会压成 zip 内套 zip 就这样了吧 --cy
7897
- name: Unzip Files
7998
run: unzip -q Minecraft-Mod-Language-Package-${{ matrix.version }}.zip -d Minecraft-Mod-Language-Package-${{ matrix.version }} || echo 0
8099
shell: bash

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ coreclr.dll
1515
mscordaccore.dll
1616
/src/Packer/Properties/launchSettings.json
1717

18+
# libgit2sharp
19+
20+
git2-*.dll
21+
1822
# artifact temporary files
1923
artifacts/
2024

src/Packer/Extensions/DirectoryExtension.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Packer.Models;
1+
using Packer.Helpers;
2+
using Packer.Models;
23
using Packer.Models.Providers;
34
using Serilog;
45
using System;
@@ -60,7 +61,7 @@ select providerGroup.Aggregate(
6061
/// 遍历未经合并的文件,用于递归调用
6162
/// </summary>
6263
internal static EvaluatorReturnType EnumerateRawProviders(this DirectoryInfo namespaceDirectory, Config config)
63-
=> from policy in Utils.RetrieveStrategy(namespaceDirectory)
64+
=> from policy in ConfigHelpers.RetrieveStrategy(namespaceDirectory)
6465
from enumeratedPair in functionTable[policy.Type].Invoke(
6566
namespaceDirectory, config, policy.Parameters)
6667
select enumeratedPair;
@@ -70,7 +71,7 @@ internal static EvaluatorReturnType FromCurrentDirectory(DirectoryInfo namespace
7071
Config config,
7172
ParameterType? parameters)
7273
{
73-
var floatingConfig = Utils.RetrieveLocalConfig(namespaceDirectory);
74+
var floatingConfig = ConfigHelpers.RetrieveLocalConfig(namespaceDirectory);
7475
var localConfig = config.Modify(floatingConfig);
7576

7677
return from candidate in namespaceDirectory.EnumerateFiles("*", SearchOption.AllDirectories)
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,83 @@
1-
using Packer.Models;
2-
using Serilog;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.IO;
6-
using System.Linq;
7-
using System.Text.Encodings.Web;
8-
using System.Text.Json;
9-
using System.Text.Json.Serialization;
10-
using System.Threading.Tasks;
11-
12-
13-
namespace Packer
14-
{
15-
/// <summary>
16-
/// 杂项工具类
17-
/// </summary>
18-
public static class Utils
19-
{
20-
/// <summary>
21-
/// 从给定的命名空间获取局域配置
22-
/// </summary>
23-
/// <param name="directory">命名空间目录</param>
24-
/// <returns>若文件存在,返回<see cref="FloatingConfig"/>;否则,返回<see langword="null"/></returns>
25-
public static FloatingConfig? RetrieveLocalConfig(DirectoryInfo directory)
26-
{
27-
var configFile = directory.GetFiles("local-config.json").FirstOrDefault();
28-
29-
if (configFile is null) return null;
30-
31-
using var reader = configFile.OpenText();
32-
return JsonSerializer.Deserialize<FloatingConfig>(
33-
reader.ReadToEnd(),
34-
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
35-
}
36-
37-
/// <summary>
38-
/// 从仓库根目录获取全局配置
39-
/// </summary>
40-
/// <param name="configTemplate">配置路径模板</param>
41-
/// <param name="version">打包版本,用于定位全局配置</param>
42-
public static async Task<Config> RetrieveConfig(string configTemplate, string version)
43-
{
44-
Log.Information("正在获取配置。目标版本:{0}", version);
45-
46-
var configPath = string.Format(configTemplate, version);
47-
48-
Log.Information("配置位置:{0}", configPath);
49-
50-
var content = await File.ReadAllBytesAsync(configPath);
51-
return JsonSerializer.Deserialize<Config>(
52-
content,
53-
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })!;
54-
}
55-
56-
/// <summary>
57-
/// 从给定的命名空间获取策略内容
58-
/// </summary>
59-
/// <param name="directory">命名空间目录</param>
60-
/// <returns>若文件存在,返回对应的内容;否则,返回<c>Direct</c></returns>
61-
/// <exception cref="InvalidDataException">策略文件非法</exception>
62-
public static List<PackerPolicy> RetrieveStrategy(DirectoryInfo directory)
63-
{
64-
var file = directory.GetFiles("packer-policy.json").FirstOrDefault();
65-
66-
if (file is null)
67-
return new List<PackerPolicy>
68-
{
69-
new PackerPolicy { Type = PackerPolicyType.Direct }
70-
};
71-
72-
using var reader = file.OpenText();
73-
var result = JsonSerializer.Deserialize<List<PackerPolicy>>(
74-
reader.ReadToEnd(),
75-
new JsonSerializerOptions
76-
{
77-
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
78-
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
79-
});
80-
if (result is null)
81-
throw new InvalidDataException($"The policy file {file.FullName} cannot have null values.");
82-
return result;
83-
}
84-
}
85-
}
1+
using Packer.Models;
2+
using Serilog;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text.Json;
7+
using System.Text.Json.Serialization;
8+
using System.Threading.Tasks;
9+
10+
11+
namespace Packer.Helpers
12+
{
13+
/// <summary>
14+
/// 配置相关的工具类
15+
/// </summary>
16+
public static class ConfigHelpers
17+
{
18+
/// <summary>
19+
/// 从给定的命名空间获取局域配置
20+
/// </summary>
21+
/// <param name="directory">命名空间目录</param>
22+
/// <returns>若文件存在,返回<see cref="FloatingConfig"/>;否则,返回<see langword="null"/></returns>
23+
public static FloatingConfig? RetrieveLocalConfig(DirectoryInfo directory)
24+
{
25+
var configFile = directory.GetFiles("local-config.json").FirstOrDefault();
26+
27+
if (configFile is null) return null;
28+
29+
using var reader = configFile.OpenText();
30+
return JsonSerializer.Deserialize<FloatingConfig>(
31+
reader.ReadToEnd(),
32+
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
33+
}
34+
35+
/// <summary>
36+
/// 从仓库根目录获取全局配置
37+
/// </summary>
38+
/// <param name="configTemplate">配置路径模板</param>
39+
/// <param name="version">打包版本,用于定位全局配置</param>
40+
public static async Task<Config> RetrieveConfig(string configTemplate, string version)
41+
{
42+
Log.Information("正在获取配置。目标版本:{0}", version);
43+
44+
var configPath = string.Format(configTemplate, version);
45+
46+
Log.Information("配置位置:{0}", configPath);
47+
48+
var content = await File.ReadAllBytesAsync(configPath);
49+
return JsonSerializer.Deserialize<Config>(
50+
content,
51+
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })!;
52+
}
53+
54+
/// <summary>
55+
/// 从给定的命名空间获取策略内容
56+
/// </summary>
57+
/// <param name="directory">命名空间目录</param>
58+
/// <returns>若文件存在,返回对应的内容;否则,返回<c>Direct</c></returns>
59+
/// <exception cref="InvalidDataException">策略文件非法</exception>
60+
public static List<PackerPolicy> RetrieveStrategy(DirectoryInfo directory)
61+
{
62+
var file = directory.GetFiles("packer-policy.json").FirstOrDefault();
63+
64+
if (file is null)
65+
return new List<PackerPolicy>
66+
{
67+
new PackerPolicy { Type = PackerPolicyType.Direct }
68+
};
69+
70+
using var reader = file.OpenText();
71+
var result = JsonSerializer.Deserialize<List<PackerPolicy>>(
72+
reader.ReadToEnd(),
73+
new JsonSerializerOptions
74+
{
75+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
76+
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
77+
});
78+
if (result is null)
79+
throw new InvalidDataException($"The policy file {file.FullName} cannot have null values.");
80+
return result;
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)