Skip to content

Commit 191f55a

Browse files
committed
移动上传步骤位置
Update packer.yml Update packer.yml Update packer.yml try this Update packer.yml Revert "fix?" This reverts commit 164a4be. fix? 移动上传步骤位置
1 parent 883d0f8 commit 191f55a

File tree

1 file changed

+62
-40
lines changed

1 file changed

+62
-40
lines changed

.github/workflows/packer.yml

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -153,57 +153,79 @@ jobs:
153153
${{ matrix.version }}.md5
154154
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
155155

156-
- name: Set asset name
157-
run: |
158-
$version_tag = "${{ matrix.version }}"
159-
# 如果版本是 1.12.2,则文件名不带版本号后缀
160-
if ($version_tag -eq '1.12.2') {
161-
$asset_name = "Minecraft-Mod-Language-Modpack.zip"
162-
} else {
163-
# 否则,转换短横线和版本号
164-
$formatted_version = $version_tag -replace '\.', '-'
165-
$formatted_version = $formatted_version -replace 'fabric', 'Fabric'
166-
$asset_name = "Minecraft-Mod-Language-Modpack-$formatted_version.zip"
167-
}
168-
echo "ASSET_NAME=$asset_name" >> $env:GITHUB_ENV
169-
170-
# Upload release asset: https://github.com/actions/upload-release-asset
171-
- name: Update release asset for ${{ matrix.version }} (ZIP)
172-
id: upload-release-asset-zip
173-
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
174-
uses: actions/upload-release-asset@v1
175-
env:
176-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
177-
with:
178-
upload_url: ${{ needs.initialize-release.outputs.upload-url }}
179-
asset_path: Minecraft-Mod-Language-Modpack-${{ matrix.version }}.zip
180-
asset_name: ${{ env.ASSET_NAME }}
181-
asset_content_type: application/zip
182-
183-
# 新增步骤:上传 MD5 文件
184-
- name: Update release asset for ${{ matrix.version }} (MD5)
185-
id: upload-release-asset-md5
186-
if: steps.check-changes.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
187-
uses: actions/upload-release-asset@v1
188-
env:
189-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
190-
with:
191-
upload_url: ${{ needs.initialize-release.outputs.upload-url }}
192-
asset_path: ${{ matrix.version }}.md5
193-
asset_name: ${{ matrix.version }}.md5
194-
asset_content_type: text/plain
195-
196156
- name: Collect updated versions
197157
id: collect-updated
198158
run: |
199159
if [ "${{ steps.check-changes.outputs.changed }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
200160
# Replace all periods and hyphens with underscores
161+
# 将.转换为_,适配变量名
201162
output_key=$(echo "${{ matrix.version }}" | sed 's/[\.-]/_/g')
202163
echo "version_$output_key=${{ matrix.version }}" >> $GITHUB_OUTPUT
203164
fi
204165
shell: bash
205166
continue-on-error: true
206167

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+
207229
update-index:
208230
name: Update Version Index (Optional)
209231
needs: [pack, initialize-release]

0 commit comments

Comments
 (0)