Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check and delete existing asset before upload #1156

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
build_for_macosx:
needs: [create_release]
name: Build for MacOSX
runs-on: macos-12
runs-on: macos-13
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
steps:
Expand Down
27 changes: 26 additions & 1 deletion tools/upload_asset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,33 @@ RELEASE_ID=$(curl -fsSL \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/aliyun/aliyun-cli/releases/tags/"$TAG" | jq '.["id"]')

if [ -z "$RELEASE_ID" ]; then
echo "Failed to get release ID for tag $TAG"
exit 1
fi

# 获取现有资产列表
ASSET_ID=$(curl -fsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/aliyun/aliyun-cli/releases/$RELEASE_ID/assets | jq -r ".[] | select(.name == \"$(basename "$ASSET")\") | .id")

# 如果资产已存在,删除它
if [ -n "$ASSET_ID" ]; then
echo "Asset already exists. Deleting asset ID $ASSET_ID"
curl -fsSL \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/aliyun/aliyun-cli/releases/assets/$ASSET_ID
fi

printf "Uploading %s to release %s\n" "$ASSET" "$RELEASE_ID"

curl -fsSL \
-X POST \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
Expand Down
Loading