Skip to content

Commit a8a6e1f

Browse files
authored
feat: Implement combine assets in 3.8.3-patch branch. (#77)
1 parent 7c4bd36 commit a8a6e1f

1 file changed

Lines changed: 128 additions & 21 deletions

File tree

.github/workflows/build-assets-in-release.yml

Lines changed: 128 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,6 @@ jobs:
119119
cp -r shared/windows/* "$archive_name/" 2>/dev/null || echo "No Windows files to copy"
120120
fi
121121
122-
# - name: List built files (Windows)
123-
# if: runner.os == 'Windows'
124-
# run: |
125-
# $tag_version = "${{ github.ref_name }}"
126-
# $archive_name = "${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
127-
# Write-Host "Checking directory: $archive_name"
128-
# if (Test-Path $archive_name) {
129-
# Get-ChildItem -Path $archive_name -Recurse
130-
# } else {
131-
# Write-Host "Directory $archive_name not found"
132-
# }
133-
134-
# - name: List built files (Unix)
135-
# if: runner.os != 'Windows'
136-
# run: |
137-
# tag_version="${{ github.ref_name }}"
138-
# archive_name="${{ matrix.os_name }}-${{ matrix.arch }}-$tag_version-assets"
139-
# echo "Checking directory: $archive_name"
140-
# ls -la $archive_name || echo "Directory $archive_name not found"
141-
# find $archive_name -type f || echo "No files found in $archive_name"
142-
143122
- name: Create archive (Windows)
144123
if: runner.os == 'Windows'
145124
run: |
@@ -183,3 +162,131 @@ jobs:
183162
draft: false
184163
env:
185164
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165+
166+
combine-assets:
167+
runs-on: ubuntu-latest
168+
needs: build
169+
steps:
170+
- name: Download release assets
171+
run: |
172+
tag_version="${{ github.ref_name }}"
173+
repo="${{ github.repository }}"
174+
175+
release_info=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
176+
"https://api.github.com/repos/$repo/releases/tags/$tag_version")
177+
178+
mkdir -p downloads
179+
180+
declare -A asset_mapping
181+
asset_mapping["ubuntu-amd64-$tag_version-assets.zip"]="linux_x64"
182+
asset_mapping["ubuntu-arm64-$tag_version-assets.zip"]="linux_arm64"
183+
asset_mapping["macos-amd64-$tag_version-assets.zip"]="mac_x64"
184+
asset_mapping["macos-arm64-$tag_version-assets.zip"]="mac_arm64"
185+
asset_mapping["windows-amd64-$tag_version-assets.zip"]="win_x64"
186+
asset_mapping["windows-386-$tag_version-assets.zip"]="win_ia32"
187+
188+
for asset in "${!asset_mapping[@]}"; do
189+
echo "Attempting to download: $asset"
190+
191+
download_url=$(echo "$release_info" | jq -r --arg name "$asset" \
192+
'.assets[] | select(.name == $name) | .browser_download_url')
193+
194+
if [ "$download_url" != "null" ] && [ -n "$download_url" ]; then
195+
echo "Downloading $asset from $download_url"
196+
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
197+
-o "downloads/$asset" "$download_url"
198+
199+
if [ -f "downloads/$asset" ]; then
200+
echo "Successfully downloaded: $asset ($(du -h "downloads/$asset" | cut -f1))"
201+
echo "${asset}:${asset_mapping[$asset]}" >> downloads/mapping.txt
202+
else
203+
echo "Failed to download: $asset"
204+
fi
205+
else
206+
echo "Asset not found in release: $asset"
207+
fi
208+
done
209+
210+
echo "Downloaded files:"
211+
ls -la downloads/
212+
213+
- name: Create combined archive
214+
run: |
215+
tag_version="${{ github.ref_name }}"
216+
combined_name="all-platforms-$tag_version-assets"
217+
218+
mkdir -p "$combined_name/assets"
219+
220+
if [ -f "downloads/mapping.txt" ]; then
221+
while IFS=':' read -r zip_file target_dir; do
222+
if [ -f "downloads/$zip_file" ]; then
223+
echo "Processing: $zip_file -> assets/$target_dir"
224+
225+
mkdir -p "$combined_name/assets/$target_dir"
226+
227+
temp_dir="temp_extract_$(basename "$zip_file" .zip)"
228+
mkdir -p "$temp_dir"
229+
230+
unzip -q "downloads/$zip_file" -d "$temp_dir"
231+
232+
extracted_content=$(find "$temp_dir" -mindepth 1 -maxdepth 1 -type d)
233+
234+
if [ -n "$extracted_content" ] && [ $(echo "$extracted_content" | wc -l) -eq 1 ]; then
235+
echo "Moving contents from: $extracted_content"
236+
mv "$extracted_content"/* "$combined_name/assets/$target_dir/" 2>/dev/null || true
237+
else
238+
echo "Moving all extracted content"
239+
mv "$temp_dir"/* "$combined_name/assets/$target_dir/" 2>/dev/null || true
240+
fi
241+
242+
rm -rf "$temp_dir"
243+
244+
echo "Completed processing: $zip_file"
245+
else
246+
echo "File not found: downloads/$zip_file"
247+
fi
248+
done < downloads/mapping.txt
249+
fi
250+
251+
echo "=== Combined archive structure ==="
252+
echo "Directory tree:"
253+
tree "$combined_name" 2>/dev/null || find "$combined_name" -type d | sed 's/[^/]*\//│ /g;s/│ \([^/]*\)$/├── \1/'
254+
255+
echo ""
256+
echo "File count per platform:"
257+
for platform_dir in "$combined_name/assets"/*/; do
258+
if [ -d "$platform_dir" ]; then
259+
file_count=$(find "$platform_dir" -type f | wc -l)
260+
dir_name=$(basename "$platform_dir")
261+
echo " $dir_name: $file_count files"
262+
263+
echo " Sample files:"
264+
find "$platform_dir" -type f | head -3 | while read file; do
265+
echo " $(basename "$file")"
266+
done
267+
fi
268+
done
269+
270+
zip -r "$combined_name.zip" "$combined_name/"
271+
272+
echo ""
273+
echo "=== Created combined archive ==="
274+
ls -la "$combined_name.zip"
275+
echo "Archive size: $(du -h "$combined_name.zip" | cut -f1)"
276+
277+
- name: Upload combined assets to release
278+
uses: softprops/action-gh-release@v2
279+
with:
280+
files: all-platforms-${{ github.ref_name }}-assets.zip
281+
draft: false
282+
env:
283+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
284+
############
285+
286+
# assets/
287+
# ├── linux_arm64
288+
# ├── linux_x64
289+
# ├── mac_arm64
290+
# ├── mac_x64
291+
# ├── win_ia32
292+
# └── win_x64

0 commit comments

Comments
 (0)