1010 - ' projects/**'
1111
1212
13-
1413jobs :
1514 build-packer :
1615 name : Build / Cache Packer
@@ -63,54 +62,16 @@ jobs:
6362 if : steps.cache-uploader.outputs.cache-hit != 'true'
6463 run : dotnet publish .\src\Uploader\Uploader.csproj -o ./ -r win-x64
6564
66- initialize-release :
67- name : Initialize Release
68- runs-on : windows-latest
69- steps :
70-
71- - name : Create timestamp
72- id : create_timestamp
73- run : echo "timestamp=$(date '+%Y%m%d%H%M%s')" >> $GITHUB_OUTPUT
74- shell : bash
75-
76- # Create the release: https://github.com/actions/create-release
77- - name : Create release
78- id : create_release
79- uses : actions/create-release@v1
80- env :
81- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
82- with :
83- tag_name : Snapshot-${{ steps.create_timestamp.outputs.timestamp }}
84- release_name : 汉化资源包-Snapshot-${{ steps.create_timestamp.outputs.timestamp }}
85- draft : false
86- prerelease : false
87- outputs :
88- upload-url : ${{ steps.create_release.outputs.upload_url }}
89- tag-name : Snapshot-${{ steps.create_timestamp.outputs.timestamp }}
90-
91-
9265 pack :
9366 name : Pack Resources and Upload Artifacts/Releases
94- needs : [ build-packer, initialize-release ] # 显然,需要存在打包程序,才能打包。
67+ needs : [ build-packer ]
9568 strategy :
96- fail-fast : false # 把正常的文件先打包了,避免一处错误阻塞整个仓库。
69+ fail-fast : false
9770 matrix :
9871 # 版本列表。将对这里的每个版本判断,按需打包。
9972 # 如需添加新版本,在这里添加即可。
10073 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" ]
10174 runs-on : windows-latest
102- outputs :
103- # 为每个版本创建独立的输出变量
104- updated_versions_1_12_2 : ${{ steps.collect-updated.outputs.version_1_12_2 }}
105- updated_versions_1_16 : ${{ steps.collect-updated.outputs.version_1_16 }}
106- updated_versions_1_16_fabric : ${{ steps.collect-updated.outputs.version_1_16_fabric }}
107- updated_versions_1_18 : ${{ steps.collect-updated.outputs.version_1_18 }}
108- updated_versions_1_18_fabric : ${{ steps.collect-updated.outputs.version_1_18_fabric }}
109- updated_versions_1_19 : ${{ steps.collect-updated.outputs.version_1_19 }}
110- updated_versions_1_20 : ${{ steps.collect-updated.outputs.version_1_20 }}
111- updated_versions_1_20_fabric : ${{ steps.collect-updated.outputs.version_1_20_fabric }}
112- updated_versions_1_21 : ${{ steps.collect-updated.outputs.version_1_21 }}
113- updated_versions_1_21_fabric : ${{ steps.collect-updated.outputs.version_1_21_fabric }}
11475 steps :
11576 - uses : actions/checkout@v2
11677 with :
12586 path : |
12687 Packer.exe
12788 git2-*.dll
128- fail-on-cache-miss : true # 前一步理应构造过的。如果不命中,肯定有问题,不如直接挂掉。
89+ fail-on-cache-miss : true # 应由前序保证
12990
13091 - name : Check changed path on ${{ matrix.version }}
13192 uses : MarceloPrado/has-changed-path@v1.0
@@ -153,140 +114,15 @@ jobs:
153114 ${{ matrix.version }}.md5
154115 if : steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
155116
156- - name : Collect updated versions
157- id : collect-updated
158- run : |
159- if [ "${{ steps.check-changes.outputs.changed }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
160- # Replace all periods and hyphens with underscores
161- # 将.转换为_,适配变量名
162- output_key=$(echo "${{ matrix.version }}" | sed 's/[\.-]/_/g')
163- echo "version_$output_key=${{ matrix.version }}" >> $GITHUB_OUTPUT
164- fi
165- shell : bash
166- continue-on-error : true
167-
168- upload-release-assets :
169- name : Upload Release Assets
170- needs : [ pack, initialize-release ]
171- runs-on : windows-latest
172- steps :
173- - name : Download all Artifacts
174- uses : actions/download-artifact@v4
175- with :
176- path : artifacts/
177-
178- - name : Upload Release Assets
179- env :
180- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
181- run : |
182- # Get the upload URL from the previous job
183- $upload_url = "${{ needs.initialize-release.outputs.upload-url }}"
184-
185- # Clean up the URL by removing the template part {?name,label}
186- $clean_upload_url = $upload_url.Split('{')[0]
187-
188- # Iterate through downloaded artifact directories
189- Get-ChildItem -Path "artifacts" -Directory | ForEach-Object {
190- $artifact_dir_name = $_.Name
191- $version_tag = ($artifact_dir_name -split '-Modpack-')[1]
192-
193- # Generate the correct asset names
194- if ($version_tag -eq '1.12.2') {
195- $zip_asset_name = "Minecraft-Mod-Language-Modpack.zip"
196- } else {
197- $formatted_version = $version_tag -replace '\.', '-'
198- $formatted_version = $formatted_version -replace 'fabric', 'Fabric'
199- $zip_asset_name = "Minecraft-Mod-Language-Modpack-$formatted_version.zip"
200- }
201-
202- # Build file paths using sub-expression operator
203- $zip_path = "$(Join-Path -Path $_.FullName -ChildPath ($artifact_dir_name + '.zip'))"
204- $md5_path = "$(Join-Path -Path $_.FullName -ChildPath ($version_tag + '.md5'))"
205-
206- # Build the full URL using the format operator -f
207- $zip_upload_url = "{0}?name={1}" -f $clean_upload_url, $zip_asset_name
208- $md5_upload_url = "{0}?name={1}" -f $clean_upload_url, ($version_tag + ".md5")
209-
210- # Upload ZIP file
211- echo "Uploading ZIP: $zip_path as $zip_asset_name"
212- curl.exe -X POST `
213- -H "Authorization: token $env:GITHUB_TOKEN" `
214- -H "Content-Type: application/zip" `
215- --data-binary "@$zip_path" `
216- $zip_upload_url
217-
218- # Upload MD5 file
219- echo "Uploading MD5: $md5_path as $version_tag.md5"
220- $md5_content = Get-Content -Path "$md5_path"
221- curl.exe -X POST `
222- -H "Authorization: token $env:GITHUB_TOKEN" `
223- -H "Content-Type: text/plain" `
224- --data-raw "$md5_content" `
225- $md5_upload_url
226- }
227- shell : pwsh
228-
229- update-index :
230- name : Update Version Index (Optional)
231- needs : [pack, initialize-release]
232- runs-on : ubuntu-latest
233- steps :
234- - name : Checkout repo
235- uses : actions/checkout@v4
236- with :
237- fetch-depth : 1
238-
239- - name : Set up index branch
240- run : |
241- git fetch origin index
242- git checkout index || git checkout -b index
243-
244- - name : Download existing index.json
245- run : |
246- if [ ! -f version-index.json ]; then
247- echo "{}" > version-index.json
248- fi
249-
250- - name : Update index.json
251- env :
252- RELEASE_TAG : ${{ needs.initialize-release.outputs.tag-name }}
253- PACK_OUTPUTS : ${{ toJSON(needs.pack.outputs) }}
254- run : |
255- python3 - <<EOF
256- import json
257- import os
258-
259- index_file = "version-index.json"
260- with open(index_file, "r") as f:
261- index = json.load(f)
262-
263- release_tag = os.environ.get("RELEASE_TAG", "")
264- pack_outputs = json.loads(os.environ.get("PACK_OUTPUTS", "{}"))
265-
266- # 遍历 pack Job 的所有输出
267- for key, version in pack_outputs.items():
268- # 只有当值不为空时,才更新索引
269- if version:
270- index[version] = release_tag
271-
272- with open(index_file, "w") as f:
273- json.dump(index, f, indent=2)
274- EOF
275-
276- - name : Commit and Push index.json
277- run : |
278- git config user.name "github-actions[bot]"
279- git config user.email "github-actions[bot]@users.noreply.github.com"
280- git add version-index.json
281- git commit -m "Update version index for $RELEASE_TAG" || echo "No changes to commit"
282- git push
283-
284117 upload :
118+ concurrency :
119+ group : packer-upload
120+ cancel-in-progress : false
285121 if : github.repository == 'CFPAOrg/Minecraft-Mod-Language-Package'
286- name : Upload Resource Packs to Remote Server
287- needs : [ pack, build-uploader ] # 显然,需要打包完成,并且存在上传程序,才可以上传给分发服务器
122+ name : Upload Resource Packs to Various places
123+ needs : [ pack, build-uploader ]
288124 runs-on : windows-latest
289- steps :
125+ steps :
290126 - uses : actions/checkout@v4 # 计算 cache key 需要
291127 with :
292128 fetch-depth : 1
@@ -298,7 +134,7 @@ jobs:
298134 key : ${{ runner.os }}-Uploader-${{ hashFiles('src/Uploader/**') }}
299135 path : |
300136 Uploader.exe
301- fail-on-cache-miss : true # 前一步理应构造过的。如果不命中,肯定有问题,不如直接挂掉。
137+ fail-on-cache-miss : true # 应由前序保证
302138
303139 # 还原artifact(资源包)
304140 - name : Restore Artifacts
@@ -313,3 +149,7 @@ jobs:
313149
314150 - name : Run Uploader
315151 run : .\Uploader --host="${{ secrets.SSH_IP }}" --name="${{ secrets.SSH_USER }}" --password="${{ secrets.SSH_PWD }}"
152+ env :
153+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
154+ SHA : ${{ github.sha }}
155+ REPO_ID : ${{ github.repository_id }}
0 commit comments