Skip to content

Commit aaf7a88

Browse files
committed
feat: add check and delete existing asset before upload
1 parent 923f9f3 commit aaf7a88

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tools/upload_asset.sh

+26-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,33 @@ RELEASE_ID=$(curl -fsSL \
1919
-H "X-GitHub-Api-Version: 2022-11-28" \
2020
https://api.github.com/repos/aliyun/aliyun-cli/releases/tags/"$TAG" | jq '.["id"]')
2121

22+
if [ -z "$RELEASE_ID" ]; then
23+
echo "Failed to get release ID for tag $TAG"
24+
exit 1
25+
fi
26+
27+
# 获取现有资产列表
28+
ASSET_ID=$(curl -fsSL \
29+
-H "Accept: application/vnd.github+json" \
30+
-H "Authorization: Bearer $GITHUB_TOKEN" \
31+
-H "X-GitHub-Api-Version: 2022-11-28" \
32+
https://api.github.com/repos/aliyun/aliyun-cli/releases/$RELEASE_ID/assets | jq -r ".[] | select(.name == \"$(basename "$ASSET")\") | .id")
33+
34+
# 如果资产已存在,删除它
35+
if [ -n "$ASSET_ID" ]; then
36+
echo "Asset already exists. Deleting asset ID $ASSET_ID"
37+
curl -fsSL \
38+
-X DELETE \
39+
-H "Accept: application/vnd.github+json" \
40+
-H "Authorization: Bearer $GITHUB_TOKEN" \
41+
-H "X-GitHub-Api-Version: 2022-11-28" \
42+
https://api.github.com/repos/aliyun/aliyun-cli/releases/assets/$ASSET_ID
43+
fi
44+
45+
printf "Uploading %s to release %s\n" "$ASSET" "$RELEASE_ID"
46+
2247
curl -fsSL \
23-
-X POST \
48+
-X PUT \
2449
-H "Accept: application/vnd.github+json" \
2550
-H "Authorization: Bearer $GITHUB_TOKEN" \
2651
-H "X-GitHub-Api-Version: 2022-11-28" \

0 commit comments

Comments
 (0)