-
Notifications
You must be signed in to change notification settings - Fork 5
75 lines (66 loc) · 2.57 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Release
on:
push:
tags:
- '*'
schedule:
- cron: '0 0 * * *' # 每天0点触发
workflow_dispatch:
permissions:
contents: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Goreleaser Release (Snapshot)
if: github.event_name != 'push' || startsWith(github.ref, 'refs/heads/') # 触发条件为手动或非 tag 的 push
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --snapshot --clean # 快照发布
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete existing assets from release
if: github.event_name != 'push' || startsWith(github.ref, 'refs/heads/') # 触发条件为手动或非 tag 的 push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 或者使用 PAT_TOKEN
run: |
RELEASE_TAG="prerelease-nightly"
# 获取 Release ID
RELEASE_ID=$(gh api -X GET repos/${{ github.repository }}/releases --jq '.[] | select(.tag_name=="'"$RELEASE_TAG"'") | .id')
if [ -z "$RELEASE_ID" ]; then
echo "Release with tag $RELEASE_TAG does not exist. Exiting."
exit 1
fi
# 获取所有资产(artifacts)
ASSET_IDS=$(gh api -X GET repos/${{ github.repository }}/releases/$RELEASE_ID/assets --jq '.[].id')
# 删除所有资产
for ASSET_ID in $ASSET_IDS; do
echo "Deleting asset with ID $ASSET_ID"
gh api -X DELETE repos/${{ github.repository }}/releases/assets/$ASSET_ID
done
- name: Upload new assets to release
if: github.event_name != 'push' || startsWith(github.ref, 'refs/heads/') # 触发条件为手动或非 tag 的 push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 或者使用 PAT_TOKEN
run: |
RELEASE_TAG="prerelease-nightly"
# 上传新的构建产物
gh release upload "$RELEASE_TAG" ./dist/*.tar.gz ./dist/*_checksums.txt --clobber
- name: Goreleaser Release (Official)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') # 触发条件为 tag 的 push
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean # 正式发布
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}