From 968bc1d2be93f630d8d279129cab47dceb5a15f6 Mon Sep 17 00:00:00 2001 From: CodeSpaceiiii Date: Wed, 4 Dec 2024 10:05:47 +0800 Subject: [PATCH] feat: add check and delete existing asset before upload build: update macOS version for release workflow --- .github/workflows/release.yml | 2 +- tools/upload_asset.sh | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f74d9e1f1..19676cefb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/tools/upload_asset.sh b/tools/upload_asset.sh index 767a42584..7eed9785e 100644 --- a/tools/upload_asset.sh +++ b/tools/upload_asset.sh @@ -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" \