Skip to content

Commit 5bbbeaf

Browse files
committed
ci:
1 parent f375e6f commit 5bbbeaf

1 file changed

Lines changed: 60 additions & 91 deletions

File tree

.github/workflows/build.yml

Lines changed: 60 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,57 @@
1-
name: 构建模块与通知
1+
name: 构建与发布工作流
22

33
on:
44
workflow_dispatch:
55
push:
66
branches: [ main ]
77
paths:
88
- 'src/module/**'
9-
release:
10-
types: [published]
9+
tags:
10+
- '*'
1111

1212
permissions:
1313
contents: write
1414

1515
jobs:
16-
build:
17-
name: 构建
16+
build_and_release:
17+
name: 构建与发布
1818
runs-on: ubuntu-latest
19-
outputs:
20-
commit_count: ${{ steps.get_version.outputs.commit_count }}
2119
steps:
2220
- name: 拉取代码
2321
uses: actions/checkout@v6
2422
with:
2523
fetch-depth: 0
2624

27-
- name: 更新 versionCode
28-
id: get_version
25+
- name: 更新并准备变量
2926
run: |
3027
COMMIT_COUNT=$(git rev-list --count HEAD)
3128
sed -i "s/^versionCode=.*/versionCode=$COMMIT_COUNT/" src/module/module.prop
32-
echo "versionCode 已更新为: $COMMIT_COUNT"
33-
echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
34-
35-
- name: 上传构建产物
36-
uses: actions/upload-artifact@v7
37-
with:
38-
name: NetProxy-Module
39-
path: src/module/
40-
41-
notify:
42-
name: 发送通知
43-
runs-on: ubuntu-latest
44-
needs: build
45-
if: always()
46-
steps:
47-
- name: 下载构建产物
48-
if: ${{ needs.build.result == 'success' }}
49-
uses: actions/download-artifact@v8
50-
with:
51-
name: NetProxy-Module
52-
path: src/module
53-
- name: 准备变量
54-
if: ${{ needs.build.result == 'success' }}
55-
run: |
56-
COMMIT_COUNT=${{ needs.build.outputs.commit_count }}
5729
VERSION=$(grep '^version=' src/module/module.prop | cut -d= -f2)
5830
echo "VERSION=$VERSION" >> $GITHUB_ENV
5931
echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_ENV
32+
33+
# 定义包名
34+
FULL_NAME="NetProxy_${VERSION}_${COMMIT_COUNT}.zip"
35+
LITE_NAME="NetProxy_${VERSION}_${COMMIT_COUNT}_lite.zip"
36+
MINI_NAME="NetProxy_${VERSION}_${COMMIT_COUNT}_mini.zip"
37+
38+
echo "FULL_NAME=$FULL_NAME" >> $GITHUB_ENV
39+
echo "LITE_NAME=$LITE_NAME" >> $GITHUB_ENV
40+
echo "MINI_NAME=$MINI_NAME" >> $GITHUB_ENV
6041
6142
- name: 打包模块
62-
if: ${{ needs.build.result == 'success' }}
6343
run: |
64-
# 1. 完整包 (全部组件)
65-
FULL_NAME="NetProxy_${{ env.VERSION }}_${{ env.COMMIT_COUNT }}.zip"
66-
echo "FULL_NAME=$FULL_NAME" >> $GITHUB_ENV
6744
cd src/module
68-
7z a -tzip -mx=9 "../../$FULL_NAME" .
69-
cd ../..
70-
45+
# 1. 完整包 (全部组件)
46+
7z a -tzip -mx=9 "../../${{ env.FULL_NAME }}" .
7147
# 2. 精简包 (排除 IPSET 相关文件)
72-
LITE_NAME="NetProxy_${{ env.VERSION }}_${{ env.COMMIT_COUNT }}_lite.zip"
73-
echo "LITE_NAME=$LITE_NAME" >> $GITHUB_ENV
74-
cd src/module
75-
7z a -tzip -mx=9 "../../$LITE_NAME" . -x!"bin/IPSET-LKM/*" -x!"bin/ipset"
76-
cd ../..
77-
48+
7z a -tzip -mx=9 "../../${{ env.LITE_NAME }}" . -x!"bin/IPSET-LKM/*" -x!"bin/ipset"
7849
# 3. 纯脚本包 (排除所有二进制文件)
79-
MINI_NAME="NetProxy_${{ env.VERSION }}_${{ env.COMMIT_COUNT }}_mini.zip"
80-
echo "MINI_NAME=$MINI_NAME" >> $GITHUB_ENV
81-
cd src/module
82-
7z a -tzip -mx=9 "../../$MINI_NAME" . -x!"bin/sing-box" -x!"bin/proxylink" -x!"bin/ipset" -x!"bin/IPSET-LKM/*" -x!"bin/zashboard/*"
50+
7z a -tzip -mx=9 "../../${{ env.MINI_NAME }}" . -x!"bin/sing-box" -x!"bin/proxylink" -x!"bin/ipset" -x!"bin/IPSET-LKM/*" -x!"bin/zashboard/*"
8351
cd ../..
8452
85-
- name: 发送模块到 Telegram
86-
if: ${{ needs.build.result == 'success' }}
53+
- name: 发送模块到 Telegram (分支推送/手动触发)
54+
if: ${{ github.ref_type != 'tag' }}
8755
env:
8856
COMMIT_MSG: ${{ github.event.head_commit.message }}
8957
run: |
@@ -92,68 +60,69 @@ jobs:
9260
版本: \`${{ env.VERSION }}\` (build ${{ env.COMMIT_COUNT }})
9361
说明:
9462
\`\`\`
95-
$COMMIT_MSG
63+
${COMMIT_MSG:-"手动触发或无说明"}
9664
\`\`\`
9765
9866
[提交记录](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
9967
[构建日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
10068
10169
# 发送完整包
102-
curl -s -F "chat_id=${{ secrets.TG_CHAT_ID }}" \
103-
-F "document=@${{ env.FULL_NAME }}" \
104-
-F "message_thread_id=2275" \
105-
-F "parse_mode=Markdown" \
106-
-F "caption=$CAPTION" \
107-
https://api.telegram.org/bot${{ secrets.TG_BOT_TOKEN }}/sendDocument
70+
curl -s -F "chat_id=${{ secrets.TG_CHAT_ID }}" -F "document=@${{ env.FULL_NAME }}" -F "message_thread_id=2275" -F "parse_mode=Markdown" -F "caption=$CAPTION" https://api.telegram.org/bot${{ secrets.TG_BOT_TOKEN }}/sendDocument
10871
10972
# 发送精简包
110-
curl -s -F "chat_id=${{ secrets.TG_CHAT_ID }}" \
111-
-F "document=@${{ env.LITE_NAME }}" \
112-
-F "message_thread_id=2275" \
113-
-F "caption=lite: 不含 IPSET 驱动,适用于内核已内置 IPSET 的设备" \
114-
https://api.telegram.org/bot${{ secrets.TG_BOT_TOKEN }}/sendDocument
73+
curl -s -F "chat_id=${{ secrets.TG_CHAT_ID }}" -F "document=@${{ env.LITE_NAME }}" -F "message_thread_id=2275" -F "caption=lite: 不含 IPSET 驱动,适用于内核已内置 IPSET 的设备" https://api.telegram.org/bot${{ secrets.TG_BOT_TOKEN }}/sendDocument
11574
11675
# 发送纯脚本包
117-
curl -s -F "chat_id=${{ secrets.TG_CHAT_ID }}" \
118-
-F "document=@${{ env.MINI_NAME }}" \
119-
-F "message_thread_id=2275" \
120-
-F "caption=mini: 不含二进制文件和 IPSET 驱动,需自行放入 sing-box、proxylink、zashboard 等组件" \
121-
https://api.telegram.org/bot${{ secrets.TG_BOT_TOKEN }}/sendDocument
76+
curl -s -F "chat_id=${{ secrets.TG_CHAT_ID }}" -F "document=@${{ env.MINI_NAME }}" -F "message_thread_id=2275" -F "caption=mini: 不含二进制文件和 IPSET 驱动,需自行放入 sing-box、proxylink、zashboard 等组件" https://api.telegram.org/bot${{ secrets.TG_BOT_TOKEN }}/sendDocument
12277
123-
- name: 失败通知
124-
if: ${{ needs.build.result == 'failure' }}
78+
- name: 发布 GitHub Release (Tag 触发)
79+
if: ${{ github.ref_type == 'tag' }}
80+
uses: softprops/action-gh-release@v2
81+
with:
82+
body_path: .github/changelog.md
83+
files: |
84+
${{ env.FULL_NAME }}
85+
${{ env.LITE_NAME }}
86+
${{ env.MINI_NAME }}
12587
env:
126-
COMMIT_MSG: ${{ github.event.head_commit.message }}
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
90+
- name: 发送 Release 通知到 Telegram (Tag 触发)
91+
if: ${{ github.ref_type == 'tag' }}
12792
uses: cbrgm/telegram-github-action@v1
12893
with:
12994
token: ${{ secrets.TG_BOT_TOKEN }}
13095
to: ${{ secrets.TG_CHAT_ID }}
131-
thread-id: 2275
96+
thread-id: 2343
13297
parse-mode: markdown
13398
message: |
134-
模块构建失败通知!
99+
**新版本发布通知**
135100
136-
说明:
137-
\`\`\`
138-
$COMMIT_MSG
139-
\`\`\`
140-
141-
[提交记录](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
142-
[构建日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
101+
版本: `${{ github.ref_name }}`
102+
103+
[查看更新日志并下载](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.ref_name }})
104+
105+
**直接下载:**
106+
[完整包](${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.ref_name }}/${{ env.FULL_NAME }})
107+
[精简包](${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.ref_name }}/${{ env.LITE_NAME }})
108+
[纯脚本包](${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.ref_name }}/${{ env.MINI_NAME }})
143109
144-
- name: Release 发布通知
145-
if: ${{ github.event_name == 'release' }}
110+
- name: 失败通知
111+
if: ${{ failure() }}
112+
env:
113+
COMMIT_MSG: ${{ github.event.head_commit.message }}
146114
uses: cbrgm/telegram-github-action@v1
147115
with:
148116
token: ${{ secrets.TG_BOT_TOKEN }}
149117
to: ${{ secrets.TG_CHAT_ID }}
150-
thread-id: 2343
118+
thread-id: 2275
151119
parse-mode: markdown
152120
message: |
153-
新版本发布通知!
154-
155-
版本: `${{ github.event.release.tag_name }}`
121+
**工作流执行失败!**
156122
157-
[查看更新日志](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.event.release.tag_name }})
158-
159-
[下载模块](${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/NetProxy-Module.zip)
123+
说明:
124+
\`\`\`
125+
${COMMIT_MSG:-"无"}
126+
\`\`\`
127+
128+
[点击查看构建日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})

0 commit comments

Comments
 (0)