Skip to content

Commit acc7744

Browse files
committed
Update release.yml
1 parent 237ba94 commit acc7744

1 file changed

Lines changed: 43 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
name: 发布到GitHub Release
22

33
on:
4-
push:
5-
tags:
6-
- '**'
7-
- '!debug**'
4+
workflow_run:
5+
workflows: ["ColorMC构建"]
6+
types:
7+
- completed
88

99
jobs:
1010
release:
11+
if: github.event.workflow_run.conclusion == 'success'
1112
runs-on: ubuntu-latest
1213
permissions:
1314
contents: write
15+
actions: read
1416

1517
steps:
1618
- name: 检查是否为debug标签
19+
id: check_debug
1720
run: |
18-
echo "当前标签: ${{ github.ref }}"
19-
if [[ "${{ github.ref }}" == refs/tags/debug* ]]; then
21+
echo "工作流程分支/标签: ${{ github.event.workflow_run.head_branch }}"
22+
if [[ "${{ github.event.workflow_run.head_branch }}" == refs/tags/debug* ]]; then
2023
echo "这是debug标签,跳过发布"
21-
exit 0
24+
echo "is_debug=true" >> $GITHUB_OUTPUT
25+
else
26+
echo "不是debug标签,继续发布"
27+
echo "is_debug=false" >> $GITHUB_OUTPUT
2228
fi
2329
30+
- name: 跳过debug标签
31+
if: steps.check_debug.outputs.is_debug == 'true'
32+
run: |
33+
echo "跳过发布,因为这是debug标签"
34+
exit 0
35+
2436
- name: 下载所有构建产物
2537
uses: actions/download-artifact@v4
2638
with:
2739
path: artifacts/
2840
pattern: '*'
2941
merge-multiple: true
42+
github-token: ${{ secrets.GITHUB_TOKEN }}
3043

3144
- name: 列出所有下载的产物
3245
run: |
@@ -35,20 +48,39 @@ jobs:
3548
echo " - $(basename "$file")"
3649
done
3750
51+
- name: 提取标签名
52+
id: get_tag
53+
run: |
54+
# 从工作流程的head_branch中提取标签名
55+
if [[ "${{ github.event.workflow_run.head_branch }}" == refs/tags/* ]]; then
56+
TAG_NAME="${GITHUB_EVENT_WORKFLOW_RUN_HEAD_BRANCH#refs/tags/}"
57+
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
58+
echo "提取的标签名: $TAG_NAME"
59+
else
60+
echo "不是标签触发,使用SHA前7位"
61+
SHA_SHORT="${GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA:0:7}"
62+
echo "tag_name=$SHA_SHORT" >> $GITHUB_OUTPUT
63+
echo "使用SHA: $SHA_SHORT"
64+
fi
65+
env:
66+
GITHUB_EVENT_WORKFLOW_RUN_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
67+
GITHUB_EVENT_WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
68+
3869
- name: 创建GitHub Release
3970
uses: softprops/action-gh-release@v1
4071
with:
41-
tag_name: ${{ github.ref_name }}
42-
name: Release ${{ github.ref_name }}
72+
tag_name: ${{ steps.get_tag.outputs.tag_name }}
73+
name: Release ${{ steps.get_tag.outputs.tag_name }}
4374
body: |
44-
ColorMC 构建产物 - ${{ github.ref_name }}
75+
ColorMC 构建产物 - ${{ steps.get_tag.outputs.tag_name }}
4576
4677
包含以下平台的构建:
4778
- Linux (.deb, .rpm, .AppImage, .pkg.tar.zst)
4879
- macOS (.zip, .dmg)
4980
- Windows (.msi, 可执行文件)
5081
51-
构建时间: ${{ github.event.head_commit.timestamp }}
82+
构建工作流程: ${{ github.event.workflow_run.html_url }}
83+
构建时间: ${{ github.event.workflow_run.created_at }}
5284
files: |
5385
artifacts/**/*.deb
5486
artifacts/**/*.rpm

0 commit comments

Comments
 (0)