Skip to content

Commit 33a5b46

Browse files
authored
build: update assets combine logic. (#83)
1 parent 2575df4 commit 33a5b46

1 file changed

Lines changed: 46 additions & 22 deletions

File tree

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

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ jobs:
172172
tag_version="${{ github.ref_name }}"
173173
repo="${{ github.repository }}"
174174
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-
180175
declare -A asset_mapping
181176
asset_mapping["ubuntu-amd64-$tag_version-assets.zip"]="linux_x64"
182177
asset_mapping["ubuntu-arm64-$tag_version-assets.zip"]="linux_arm64"
@@ -185,30 +180,59 @@ jobs:
185180
asset_mapping["windows-amd64-$tag_version-assets.zip"]="win_x64"
186181
asset_mapping["windows-386-$tag_version-assets.zip"]="win_ia32"
187182
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')
183+
gh release download "$tag_version" --repo "$repo" --dir downloads || true
184+
185+
if [ ! "$(ls -A downloads 2>/dev/null)" ]; then
186+
echo "Falling back to API download method"
193187
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"
188+
release_info=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
189+
"https://api.github.com/repos/$repo/releases/tags/$tag_version")
190+
191+
mkdir -p downloads
192+
193+
for asset in "${!asset_mapping[@]}"; do
194+
echo "Attempting to download: $asset"
198195
196+
asset_id=$(echo "$release_info" | jq -r --arg name "$asset" \
197+
'.assets[] | select(.name == $name) | .id')
198+
199+
if [ "$asset_id" != "null" ] && [ -n "$asset_id" ]; then
200+
echo "Downloading $asset (ID: $asset_id)"
201+
202+
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
203+
-H "Accept: application/octet-stream" \
204+
-o "downloads/$asset" \
205+
"https://api.github.com/repos/$repo/releases/assets/$asset_id"
206+
207+
if [ -f "downloads/$asset" ]; then
208+
if file "downloads/$asset" | grep -q "Zip archive"; then
209+
echo "Successfully downloaded: $asset ($(du -h "downloads/$asset" | cut -f1))"
210+
echo "${asset}:${asset_mapping[$asset]}" >> downloads/mapping.txt
211+
else
212+
echo "Downloaded file is not a valid ZIP archive: $asset"
213+
rm -f "downloads/$asset"
214+
fi
215+
else
216+
echo "Failed to download: $asset"
217+
fi
218+
else
219+
echo "Asset not found in release: $asset"
220+
fi
221+
done
222+
else
223+
echo "Successfully downloaded using gh CLI"
224+
225+
for asset in "${!asset_mapping[@]}"; do
199226
if [ -f "downloads/$asset" ]; then
200-
echo "Successfully downloaded: $asset ($(du -h "downloads/$asset" | cut -f1))"
201227
echo "${asset}:${asset_mapping[$asset]}" >> downloads/mapping.txt
202-
else
203-
echo "Failed to download: $asset"
204228
fi
205-
else
206-
echo "Asset not found in release: $asset"
207-
fi
208-
done
229+
done
230+
fi
209231
210232
echo "Downloaded files:"
211233
ls -la downloads/
234+
env:
235+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
212236

213237
- name: Create combined archive
214238
run: |
@@ -289,4 +313,4 @@ jobs:
289313
# ├── mac_arm64
290314
# ├── mac_x64
291315
# ├── win_ia32
292-
# └── win_x64
316+
# └── win_x64

0 commit comments

Comments
 (0)