Skip to content

Commit 8f485d1

Browse files
CodeSpaceiiiipeze
authored andcommitted
feat: add check and delete existing asset before upload
build: update macOS version for release workflow
1 parent 923f9f3 commit 8f485d1

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
build_for_macosx:
2222
needs: [create_release]
2323
name: Build for MacOSX
24-
runs-on: macos-12
24+
runs-on: macos-13
2525
env:
2626
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
2727
steps:

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)