Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
17a7455
feat(workflow): generate index when release
502y Aug 31, 2025
5c5f5f9
revert(workflow): set github.repository back to CFPA
502y Aug 31, 2025
3524c3f
Revert "revert(workflow): set github.repository back to CFPA"
502y Aug 31, 2025
a4adc1b
Upload md5 to release
502y Aug 31, 2025
1da93fc
Update version index for
github-actions[bot] Aug 31, 2025
01139dd
revert github.repository back to CFPA
502y Aug 31, 2025
8a2d499
Merge branch 'main' of https://github.com/502y/Minecraft-Mod-Language…
502y Aug 31, 2025
4c83831
fix duplicate "Snapshot"
502y Aug 31, 2025
26c54a2
Update packer.yml
502y Aug 31, 2025
31cad83
Update version index for
github-actions[bot] Aug 31, 2025
912502e
Revert "Update packer.yml"
502y Aug 31, 2025
e45001e
Update packer.yml
502y Aug 31, 2025
c0b0185
Update version index for
github-actions[bot] Aug 31, 2025
ee0af8c
Update packer.yml
502y Aug 31, 2025
b52cc9b
Revert "Update packer.yml"
502y Aug 31, 2025
3706d78
Update version index for
github-actions[bot] Aug 31, 2025
1bf3101
Update packer.yml
502y Aug 31, 2025
29277e7
修改Packer 产物名称
502y Sep 4, 2025
f2e6936
修改Packer 产物名称
502y Sep 4, 2025
68b9ca4
Merge branch 'main' of https://github.com/502y/Minecraft-Mod-Language…
502y Sep 4, 2025
5e0dc52
Bash pwsh 傻傻分不清
502y Sep 4, 2025
85cca74
Update version index for
github-actions[bot] Sep 4, 2025
a2352ef
修复忘了的大写与1.12.2
502y Sep 4, 2025
3623a81
Merge branch 'main' of https://github.com/502y/Minecraft-Mod-Language…
502y Sep 4, 2025
ed0a7e9
修复环境变量展开问题
502y Sep 4, 2025
3941d9c
Update packer.yml
502y Sep 4, 2025
dbed6cb
Update packer.yml
502y Sep 4, 2025
00b6727
Update version index for
github-actions[bot] Sep 4, 2025
e65895d
Update packer.yml
502y Sep 4, 2025
ade2063
Merge branch 'main' of https://github.com/502y/Minecraft-Mod-Language…
502y Sep 4, 2025
d1ad052
Update version index for
github-actions[bot] Sep 4, 2025
1ac2092
也许,不用转义?
502y Sep 4, 2025
5469656
Update version index for
github-actions[bot] Sep 4, 2025
c8abd5b
Update packer.yml
502y Sep 4, 2025
3d09456
Merge branch 'main' of https://github.com/502y/Minecraft-Mod-Language…
502y Sep 4, 2025
fe3c679
Update packer.yml
502y Sep 4, 2025
119a9c1
Update packer.yml
502y Sep 4, 2025
bd38d6d
尝试优化索引生成
502y Sep 5, 2025
883d0f8
再压缩一下?
502y Sep 5, 2025
191f55a
移动上传步骤位置
502y Sep 5, 2025
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
182 changes: 153 additions & 29 deletions .github/workflows/packer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ on:
workflow_dispatch:
push:
branches: [ main ]
paths:
paths:
- 'src/**'
- 'config/packer/**'
- 'projects/**'



jobs:
build-packer:
if: github.repository == 'CFPAOrg/Minecraft-Mod-Language-Package'
name: Build / Cache Packer
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
with:
fetch-depth: 1
sparse-checkout: src

Expand All @@ -45,7 +44,7 @@ jobs:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v4
# with:
# with:
# fetch-depth: 1
# sparse-checkout: src

Expand All @@ -65,16 +64,15 @@ jobs:
# run: dotnet publish .\src\Uploader\Uploader.csproj -o ./ -r win-x64 -p:PublishSingeFile=true

initialize-release:
if: github.repository == 'CFPAOrg/Minecraft-Mod-Language-Package'
name: Initialize Release
runs-on: windows-latest
steps:

- name: Create timestamp
id: create_timestamp
run: echo "::set-output name=timestamp::$(date '+%Y%m%d%H%M%s')"
run: echo "timestamp=$(date '+%Y%m%d%H%M%s')" >> $GITHUB_OUTPUT
shell: bash

# Create the release: https://github.com/actions/create-release
- name: Create release
id: create_release
Expand All @@ -88,10 +86,10 @@ jobs:
prerelease: false
outputs:
upload-url: ${{ steps.create_release.outputs.upload_url }}
tag-name: Snapshot-${{ steps.create_timestamp.outputs.timestamp }}


pack:
if: github.repository == 'CFPAOrg/Minecraft-Mod-Language-Package'
name: Pack Resources and Upload Artifacts/Releases
needs: [ build-packer, initialize-release ] # 显然,需要存在打包程序,才能打包。
strategy:
Expand All @@ -101,11 +99,23 @@ jobs:
# 如需添加新版本,在这里添加即可。
version: [ "1.12.2", "1.16", "1.16-fabric", "1.18", "1.18-fabric", "1.19", "1.20", "1.20-fabric", "1.21", "1.21-fabric" ]
runs-on: windows-latest
outputs:
# 为每个版本创建独立的输出变量
updated_versions_1_12_2: ${{ steps.collect-updated.outputs.version_1_12_2 }}
updated_versions_1_16: ${{ steps.collect-updated.outputs.version_1_16 }}
updated_versions_1_16_fabric: ${{ steps.collect-updated.outputs.version_1_16_fabric }}
updated_versions_1_18: ${{ steps.collect-updated.outputs.version_1_18 }}
updated_versions_1_18_fabric: ${{ steps.collect-updated.outputs.version_1_18_fabric }}
updated_versions_1_19: ${{ steps.collect-updated.outputs.version_1_19 }}
updated_versions_1_20: ${{ steps.collect-updated.outputs.version_1_20 }}
updated_versions_1_20_fabric: ${{ steps.collect-updated.outputs.version_1_20_fabric }}
updated_versions_1_21: ${{ steps.collect-updated.outputs.version_1_21 }}
updated_versions_1_21_fabric: ${{ steps.collect-updated.outputs.version_1_21_fabric }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 20 # 显然,需要有提交历史才能比较提交。20这个数是任意的。

# 由于Github的限制,这里需要重新拉取打包程序。
- name: Restore Packer
id: cache-restore
Expand Down Expand Up @@ -137,25 +147,139 @@ jobs:
- name: Upload Artifact for ${{ matrix.version }}
uses: actions/upload-artifact@v4
with:
name: Minecraft-Mod-Language-Package-${{ matrix.version }}
name: Minecraft-Mod-Language-Modpack-${{ matrix.version }}
path: |
Minecraft-Mod-Language-Package-${{ matrix.version }}.zip
Minecraft-Mod-Language-Modpack-${{ matrix.version }}.zip
${{ matrix.version }}.md5
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'

# Upload release asset: https://github.com/actions/upload-release-asset
- name: Update release asset for ${{ matrix.version }}
id: upload-release-asset
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
uses: actions/upload-release-asset@v1
- name: Collect updated versions
id: collect-updated
run: |
if [ "${{ steps.check-changes.outputs.changed }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# Replace all periods and hyphens with underscores
# 将.转换为_,适配变量名
output_key=$(echo "${{ matrix.version }}" | sed 's/[\.-]/_/g')
echo "version_$output_key=${{ matrix.version }}" >> $GITHUB_OUTPUT
fi
shell: bash
continue-on-error: true

upload-release-assets:
name: Upload Release Assets
needs: [ pack, initialize-release ]
runs-on: windows-latest
steps:
- name: Download all Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/

- name: Upload Release Assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get the upload URL from the previous job
$upload_url = "${{ needs.initialize-release.outputs.upload-url }}"

# Clean up the URL by removing the template part {?name,label}
$clean_upload_url = $upload_url.Split('{')[0]

# Iterate through downloaded artifact directories
Get-ChildItem -Path "artifacts" -Directory | ForEach-Object {
$artifact_dir_name = $_.Name
$version_tag = ($artifact_dir_name -split '-Modpack-')[1]

# Generate the correct asset names
if ($version_tag -eq '1.12.2') {
$zip_asset_name = "Minecraft-Mod-Language-Modpack.zip"
} else {
$formatted_version = $version_tag -replace '\.', '-'
$formatted_version = $formatted_version -replace 'fabric', 'Fabric'
$zip_asset_name = "Minecraft-Mod-Language-Modpack-$formatted_version.zip"
}

# Build file paths using sub-expression operator
$zip_path = "$(Join-Path -Path $_.FullName -ChildPath ($artifact_dir_name + '.zip'))"
$md5_path = "$(Join-Path -Path $_.FullName -ChildPath ($version_tag + '.md5'))"

# Build the full URL using the format operator -f
$zip_upload_url = "{0}?name={1}" -f $clean_upload_url, $zip_asset_name
$md5_upload_url = "{0}?name={1}" -f $clean_upload_url, ($version_tag + ".md5")

# Upload ZIP file
echo "Uploading ZIP: $zip_path as $zip_asset_name"
curl.exe -X POST `
-H "Authorization: token $env:GITHUB_TOKEN" `
-H "Content-Type: application/zip" `
--data-binary "@$zip_path" `
$zip_upload_url

# Upload MD5 file
echo "Uploading MD5: $md5_path as $version_tag.md5"
$md5_content = Get-Content -Path "$md5_path"
curl.exe -X POST `
-H "Authorization: token $env:GITHUB_TOKEN" `
-H "Content-Type: text/plain" `
--data-raw "$md5_content" `
$md5_upload_url
}
shell: pwsh

update-index:
name: Update Version Index (Optional)
needs: [pack, initialize-release]
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
upload_url: ${{ needs.initialize-release.outputs.upload-url }}
asset_path: Minecraft-Mod-Language-Package-${{ matrix.version }}.zip
asset_name: Minecraft-Mod-Language-Package-${{ matrix.version }}.zip
asset_content_type: application/zip

fetch-depth: 1

- name: Set up index branch
run: |
git fetch origin index
git checkout index || git checkout -b index

- name: Download existing index.json
run: |
if [ ! -f version-index.json ]; then
echo "{}" > version-index.json
fi

- name: Update index.json
env:
RELEASE_TAG: ${{ needs.initialize-release.outputs.tag-name }}
PACK_OUTPUTS: ${{ toJSON(needs.pack.outputs) }}
run: |
python3 - <<EOF
import json
import os

index_file = "version-index.json"
with open(index_file, "r") as f:
index = json.load(f)

release_tag = os.environ.get("RELEASE_TAG", "")
pack_outputs = json.loads(os.environ.get("PACK_OUTPUTS", "{}"))

# 遍历 pack Job 的所有输出
for key, version in pack_outputs.items():
# 只有当值不为空时,才更新索引
if version:
index[version] = release_tag

with open(index_file, "w") as f:
json.dump(index, f, indent=2)
EOF

- name: Commit and Push index.json
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add version-index.json
git commit -m "Update version index for $RELEASE_TAG" || echo "No changes to commit"
git push

upload:
if: github.repository == 'CFPAOrg/Minecraft-Mod-Language-Package'
Expand All @@ -164,23 +288,23 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
with:
fetch-depth: 1
sparse-checkout: src

# 构造程序
- name: Build Uploader
run: dotnet publish .\src\Uploader\Uploader.csproj -o ./ -r win-x64 -p:PublishSingeFile=true

# 还原artifact(资源包)
- name: Restore Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/

# feat: UTC 20:00~21:00 取消上传(避开远程服务器的4:00-4:10)
- name: Fail at inappropriate time
run: if [ `date -u +%H` -eq 20 ]; then exit -1; fi
path: artifacts/
# feat: UTC 20:00~21:00 取消上传(避开远程服务器的4:00-4:10)
- name: Fail at inappropriate time
run: if [ `date -u +%H` -eq 20 ]; then exit -1; fi
shell: bash

- name: Run Uploader
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ artifacts/
*.userosscache
*.sln.docstates
.vscode/
.idea/
/cache

# User-specific files (MonoDevelop/Xamarin Studio)
Expand Down
2 changes: 1 addition & 1 deletion src/Packer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ select config.Floating.DestinationReplacement // 全局路
? McMetaProvider.Create(file, file.Name) // 类型推断不出要用接口
: new RawFile(file, file.Name) as IResourceFileProvider;

string packName = $"./Minecraft-Mod-Language-Package-{config.Base.Version}.zip";
string packName = $"./Minecraft-Mod-Language-Modpack-{config.Base.Version}.zip";
await using var stream = File.Create(packName);

using (var archive = new ZipArchive(stream, ZipArchiveMode.Update, leaveOpen: true))
Expand Down
3 changes: 1 addition & 2 deletions src/Uploader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ static int Main(string host, string name, string password)
public static string RegulateFileName(this string fileName)
{
// 历史遗留问题:全部单词都要大小写
return CapitalizeGroup(fileName.Replace("Package", "Modpack") // 历史遗留问题:文件名
.Replace('.', '-') // 历史遗留问题:版本号需要输杠
return CapitalizeGroup(fileName.Replace('.', '-') // 历史遗留问题:版本号需要输杠
.Replace("-1-12-2", "") // 历史遗留问题:1.12.2文件没有版本号
.Split('-'));

Expand Down
Loading