Skip to content

Commit

Permalink
feat: add check and delete existing asset before upload
Browse files Browse the repository at this point in the history
build: update macOS version for release workflow
  • Loading branch information
CodeSpaceiiii authored and peze committed Dec 4, 2024
1 parent 923f9f3 commit 8f485d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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

0 comments on commit 8f485d1

Please sign in to comment.