Skip to content

Commit 8a248be

Browse files
authored
Download release assets (#3)
1 parent c609ac3 commit 8a248be

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

download-release-assets.sh

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
# Usage: ./download-release.sh owner repo tag "asset1 asset2 asset3"
4+
# Example: ./download-release.sh cli cli v1.0.0 "cli-linux-amd64 cli-darwin-amd64 cli-windows-amd64.exe"
5+
6+
if [ "$#" -lt 4 ]; then
7+
echo "Usage: $0 owner repo tag \"asset1 asset2 ...\""
8+
echo "Example: $0 kubernetes kubectl v1.28.0 \"kubectl-linux-amd64.tar.gz kubectl-darwin-amd64.tar.gz\""
9+
exit 1
10+
fi
11+
12+
OWNER=$1
13+
REPO=$2
14+
TAG=$3
15+
ASSETS=$4
16+
17+
# Get the release information once
18+
RELEASE_INFO=$(curl -s "https://api.github.com/repos/$OWNER/$REPO/releases/tags/$TAG")
19+
20+
if [ $? -ne 0 ]; then
21+
echo "Error: Failed to fetch release information"
22+
exit 1
23+
fi
24+
25+
# Function to download a single asset
26+
download_asset() {
27+
local asset_name=$1
28+
local asset_url=$(echo "$RELEASE_INFO" | grep -o "https://.*$asset_name" | head -n1)
29+
30+
if [ -z "$asset_url" ]; then
31+
echo "Warning: Asset '$asset_name' not found in release"
32+
return 1
33+
fi
34+
35+
echo "Downloading $asset_name..."
36+
curl -L -H "Accept: application/octet-stream" \
37+
--progress-bar \
38+
-o "$asset_name" \
39+
"$asset_url"
40+
41+
if [ $? -eq 0 ]; then
42+
echo "✓ Successfully downloaded: $asset_name"
43+
return 0
44+
else
45+
echo "✗ Failed to download: $asset_name"
46+
return 1
47+
fi
48+
}
49+
50+
# Initialize counters
51+
total=0
52+
successful=0
53+
54+
# Download each asset
55+
for asset in $ASSETS; do
56+
total=$((total + 1))
57+
if download_asset "$asset"; then
58+
successful=$((successful + 1))
59+
fi
60+
echo "----------------------------------------"
61+
done
62+
63+
# Print summary
64+
echo "Download Summary:"
65+
echo "Successfully downloaded: $successful/$total assets"
66+
if [ $successful -ne $total ]; then
67+
echo "Failed downloads: $((total - successful))"
68+
exit 1
69+
fi

0 commit comments

Comments
 (0)