-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (137 loc) · 5.66 KB
/
build.yml
File metadata and controls
159 lines (137 loc) · 5.66 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: 构建模块与通知
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'src/module/**'
release:
types: [published]
permissions:
contents: write
jobs:
build:
name: 构建
runs-on: ubuntu-latest
outputs:
commit_count: ${{ steps.get_version.outputs.commit_count }}
steps:
- name: 拉取代码
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: 更新 versionCode
id: get_version
run: |
COMMIT_COUNT=$(git rev-list --count HEAD)
sed -i "s/^versionCode=.*/versionCode=$COMMIT_COUNT/" src/module/module.prop
echo "versionCode 已更新为: $COMMIT_COUNT"
echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
- name: 上传构建产物
uses: actions/upload-artifact@v7
with:
name: NetProxy-Module
path: src/module/
notify:
name: 发送通知
runs-on: ubuntu-latest
needs: build
if: always()
steps:
- name: 下载构建产物
if: ${{ needs.build.result == 'success' }}
uses: actions/download-artifact@v8
with:
name: NetProxy-Module
path: src/module
- name: 准备变量
if: ${{ needs.build.result == 'success' }}
run: |
COMMIT_COUNT=${{ needs.build.outputs.commit_count }}
VERSION=$(grep '^version=' src/module/module.prop | cut -d= -f2)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_ENV
- name: 打包模块
if: ${{ needs.build.result == 'success' }}
run: |
# 1. 完整包 (全部组件)
FULL_NAME="NetProxy_${{ env.VERSION }}_${{ env.COMMIT_COUNT }}.zip"
echo "FULL_NAME=$FULL_NAME" >> $GITHUB_ENV
cd src/module
7z a -tzip -mx=9 "../../$FULL_NAME" .
cd ../..
# 2. 精简包 (排除 IPSET 相关文件)
LITE_NAME="NetProxy_${{ env.VERSION }}_${{ env.COMMIT_COUNT }}_lite.zip"
echo "LITE_NAME=$LITE_NAME" >> $GITHUB_ENV
cd src/module
7z a -tzip -mx=9 "../../$LITE_NAME" . -x!"bin/IPSET-LKM/*" -x!"bin/ipset"
cd ../..
# 3. 纯脚本包 (排除所有二进制文件)
MINI_NAME="NetProxy_${{ env.VERSION }}_${{ env.COMMIT_COUNT }}_mini.zip"
echo "MINI_NAME=$MINI_NAME" >> $GITHUB_ENV
cd src/module
7z a -tzip -mx=9 "../../$MINI_NAME" . -x!"bin/sing-box" -x!"bin/proxylink" -x!"bin/ipset" -x!"bin/IPSET-LKM/*" -x!"bin/zashboard/*"
cd ../..
- name: 发送模块到 Telegram
if: ${{ needs.build.result == 'success' }}
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
CAPTION="模块构建成功通知
版本: \`${{ env.VERSION }}\` (build ${{ env.COMMIT_COUNT }})
说明:
\`\`\`
$COMMIT_MSG
\`\`\`
[提交记录](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
[构建日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
# 发送完整包
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
# 发送精简包
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
# 发送纯脚本包
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
- name: 失败通知
if: ${{ needs.build.result == 'failure' }}
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
uses: cbrgm/telegram-github-action@v1
with:
token: ${{ secrets.TG_BOT_TOKEN }}
to: ${{ secrets.TG_CHAT_ID }}
thread-id: 2275
parse-mode: markdown
message: |
模块构建失败通知!
说明:
\`\`\`
$COMMIT_MSG
\`\`\`
[提交记录](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
[构建日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Release 发布通知
if: ${{ github.event_name == 'release' }}
uses: cbrgm/telegram-github-action@v1
with:
token: ${{ secrets.TG_BOT_TOKEN }}
to: ${{ secrets.TG_CHAT_ID }}
thread-id: 2343
parse-mode: markdown
message: |
新版本发布通知!
版本: `${{ github.event.release.tag_name }}`
[查看更新日志](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.event.release.tag_name }})
[下载模块](${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/NetProxy-Module.zip)