forked from taamarin/box_for_magisk
-
Notifications
You must be signed in to change notification settings - Fork 69
303 lines (256 loc) · 10.4 KB
/
Copy pathdebug.yml
File metadata and controls
303 lines (256 loc) · 10.4 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
name: debug
on:
workflow_dispatch:
inputs:
version:
description: '预发布版本号'
required: true
type: string
jobs:
build:
if: github.ref_name == 'test'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
artifact_name: ${{ steps.get_version.outputs.artifact_name }}
latest_release_tag: ${{ steps.get_version.outputs.latest_release_tag }}
steps:
- uses: actions/checkout@v4.1.0
with:
fetch-depth: 0
- name: Update Module.prop
run: |
dos2unix module.prop || true
VERSION="${{ github.event.inputs.version }}"
VERSION=$(printf "%s" "$VERSION" | tr -d '\r' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -z "$VERSION" ]; then
echo "version 不能为空"
exit 1
fi
COMMIT_HASH=$(git log --oneline -n 1 | awk '{print $1}')
sed -i "s/^version=.*/version=${VERSION}(${COMMIT_HASH})/g" module.prop
sed -i "s/versionCode=.*/versionCode=$(date +%Y%m%d)/g" module.prop
- name: Get Version
id: get_version
run: |
VERSION=$(grep -oP 'version=\K[^ ]+' module.prop | tr -d '\r')
LATEST_RELEASE_TAG=$(git tag -l --sort=-v:refname | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "artifact_name=box_$VERSION" >> "$GITHUB_OUTPUT"
echo "latest_release_tag=$LATEST_RELEASE_TAG" >> "$GITHUB_OUTPUT"
- name: Generate Asset
run: |
sudo mkdir -p /box
sudo cp -r --parents $(find ./ -type f ! -path './.git/*' ! -name 'CHANGELOG.md' ! -name 'update.json' ! -name 'build.sh' ! -path './.github/*' ! -path './docs/*' ! -name 'LICENSE') /box/
- name: Upload Debug Asset => (box_${{ steps.get_version.outputs.version }})
uses: actions/upload-artifact@v4
with:
name: "box_${{ steps.get_version.outputs.version }}"
path: /box/
prerelease:
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- build
if: success()
steps:
- name: Checkout
uses: actions/checkout@v4.1.0
with:
fetch-depth: 0
- name: Get Version Info
id: get_version
run: |
VERSION="${{ needs.build.outputs.version }}"
COMMIT_HASH=$(git log -1 --pretty=format:"%h")
COMMIT_DATE=$(git log -1 --pretty=format:"%ad" --date=short)
COMMIT_MSG=$(git log -1 --pretty=format:"%B")
LATEST_RELEASE_TAG="${{ needs.build.outputs.latest_release_tag }}"
ARTIFACT_NAME="${{ needs.build.outputs.artifact_name }}"
if [ -n "$LATEST_RELEASE_TAG" ]; then
CHANGELOG_TITLE="自 $LATEST_RELEASE_TAG 以来的变更"
CHANGELOG_BODY=$(git log "$LATEST_RELEASE_TAG..HEAD" --pretty=format:'- %s (%h)' --no-merges)
else
CHANGELOG_TITLE="最近变更"
CHANGELOG_BODY=$(git log -n 20 --pretty=format:'- %s (%h)' --no-merges)
fi
if [ -z "$CHANGELOG_BODY" ]; then
CHANGELOG_BODY="- 暂无新的提交"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
echo "commit_hash=$COMMIT_HASH" >> "$GITHUB_OUTPUT"
echo "commit_date=$COMMIT_DATE" >> "$GITHUB_OUTPUT"
echo "changelog_title=$CHANGELOG_TITLE" >> "$GITHUB_OUTPUT"
{
echo 'commit_msg<<EOF'
echo "$COMMIT_MSG"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
{
echo 'changelog_body<<EOF'
echo "$CHANGELOG_BODY"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: "${{ steps.get_version.outputs.artifact_name }}"
path: ./artifact
- name: Create ZIP Package
run: |
cd artifact
zip -r "../${{ steps.get_version.outputs.artifact_name }}.zip" .
cd ..
- name: Delete Current Release Assets
uses: mknejp/delete-release-assets@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: debug
fail-if-no-assets: false
fail-if-no-release: false
assets: '*'
- name: Update Tag to Current Commit
uses: richardsimko/update-tag@v1
with:
tag_name: debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Prerelease
uses: softprops/action-gh-release@v1
with:
tag_name: debug
name: "Debug Build - ${{ steps.get_version.outputs.version }}"
body: |
## 📦 调试构建
**版本:** ${{ steps.get_version.outputs.version }}
**提交:** ${{ steps.get_version.outputs.commit_hash }}
**日期:** ${{ steps.get_version.outputs.commit_date }}
### 更新日志
<details>
<summary>${{ steps.get_version.outputs.changelog_title }}</summary>
```text
${{ steps.get_version.outputs.changelog_body }}
```
</details>
### 提交信息
${{ steps.get_version.outputs.commit_msg }}
---
⚠️ 这是预发布版本,用于测试和调试。
files: ${{ steps.get_version.outputs.artifact_name }}.zip
prerelease: true
draft: false
telegram-upload:
runs-on: ubuntu-latest
permissions:
contents: read
needs:
- build
- prerelease
if: success()
steps:
- uses: actions/checkout@v4.1.0
with:
fetch-depth: 0
- name: Get Version Info
id: get_version
run: |
VERSION="${{ needs.build.outputs.version }}"
COMMIT_HASH=$(git log -1 --pretty=format:"%h")
COMMIT_DATE=$(git log -1 --pretty=format:"%ad" --date=short)
LATEST_RELEASE_TAG="${{ needs.build.outputs.latest_release_tag }}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "commit_hash=$COMMIT_HASH" >> "$GITHUB_OUTPUT"
echo "commit_date=$COMMIT_DATE" >> "$GITHUB_OUTPUT"
echo "tag_name=debug" >> "$GITHUB_OUTPUT"
echo "latest_release_tag=$LATEST_RELEASE_TAG" >> "$GITHUB_OUTPUT"
- name: Get Commit Message
id: commit_info
run: |
COMMIT_MSG=$(git log -1 --pretty=format:"%B")
LATEST_RELEASE_TAG="${{ steps.get_version.outputs.latest_release_tag }}"
if [ -n "$LATEST_RELEASE_TAG" ]; then
CHANGELOG_BODY=$(git log "$LATEST_RELEASE_TAG..HEAD" -n 10 --pretty=format:'- %s (%h)' --no-merges)
else
CHANGELOG_BODY=$(git log -n 10 --pretty=format:'- %s (%h)' --no-merges)
fi
if [ -z "$CHANGELOG_BODY" ]; then
CHANGELOG_BODY="- 暂无新的提交"
fi
escape_md_v2_code() {
perl -pe 's/([`\\])/\\$1/g'
}
COMMIT_MSG_ESCAPED=$(printf "%s" "$COMMIT_MSG" | escape_md_v2_code)
CHANGELOG_ESCAPED=$(printf "%s" "$CHANGELOG_BODY" | escape_md_v2_code)
{
echo 'commit_msg<<EOF'
echo "$COMMIT_MSG_ESCAPED"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
{
echo 'changelog_body<<EOF'
echo "$CHANGELOG_ESCAPED"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Download Release Asset
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
# Get release info
RELEASE_INFO=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.get_version.outputs.tag_name }}")
# Get download URL for the zip file
DOWNLOAD_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[0].browser_download_url')
ASSET_NAME=$(echo "$RELEASE_INFO" | jq -r '.assets[0].name')
if [ -z "$DOWNLOAD_URL" ] || [ "$DOWNLOAD_URL" = "null" ]; then
echo "Release asset not found for tag: ${{ steps.get_version.outputs.tag_name }}"
exit 1
fi
# Download the release asset
curl -sL -o "$ASSET_NAME" "$DOWNLOAD_URL"
echo "asset_name=$ASSET_NAME" >> "$GITHUB_OUTPUT"
id: download_asset
- name: Send to Telegram
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
VERSION: ${{ steps.get_version.outputs.version }}
COMMIT_HASH: ${{ steps.get_version.outputs.commit_hash }}
COMMIT_DATE: ${{ steps.get_version.outputs.commit_date }}
CHANGELOG_BODY: ${{ steps.commit_info.outputs.changelog_body }}
RELEASE_URL: https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_version.outputs.tag_name }}
REPOSITORY_URL: https://github.com/${{ github.repository }}
run: |
escape_md_v2() {
perl -pe 's/([_*\[\]()~`>#+\-=|{}.!\\])/\\$1/g'
}
escape_md_v2_code() {
perl -pe 's/([`\\])/\\$1/g'
}
escape_md_v2_url() {
perl -pe 's/([)\\])/\\$1/g'
}
VERSION_ESCAPED=$(printf "%s" "$VERSION" | escape_md_v2)
COMMIT_HASH_ESCAPED=$(printf "%s" "$COMMIT_HASH" | escape_md_v2_code)
COMMIT_DATE_ESCAPED=$(printf "%s" "$COMMIT_DATE" | escape_md_v2)
REPOSITORY_URL_ESCAPED=$(printf "%s" "$REPOSITORY_URL" | escape_md_v2_url)
RELEASE_URL_ESCAPED=$(printf "%s" "$RELEASE_URL" | escape_md_v2_url)
MESSAGE=$(cat <<EOF
📦 *Box 模块自动构建*
*版本:* $VERSION_ESCAPED
*提交:* \`$COMMIT_HASH_ESCAPED\`
*日期:* $COMMIT_DATE_ESCAPED
*更新日志:*
\`\`\`
$CHANGELOG_BODY
\`\`\`
[仓库地址]($REPOSITORY_URL_ESCAPED) \| [Release 详情]($RELEASE_URL_ESCAPED)
\#模块更新
EOF
)
curl -sS -f -F "chat_id=$TG_CHAT_ID" \
-F "document=@${{ steps.download_asset.outputs.asset_name }}" \
-F "caption=$MESSAGE" \
-F "parse_mode=MarkdownV2" \
"https://api.telegram.org/bot$TG_BOT_TOKEN/sendDocument"