-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathandroid.yml
More file actions
217 lines (185 loc) · 7.37 KB
/
Copy pathandroid.yml
File metadata and controls
217 lines (185 loc) · 7.37 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
name: 编译ZeroTermux
on:
push:
branches: [ "main", "master" ]
tags:
- "ZeroTermux-*"
- "v*"
- "[0-9]*"
paths-ignore:
- ".github/ISSUE_TEMPLATE/**"
- "**/README.md"
pull_request:
branches: [ "main", "master" ]
paths-ignore:
- ".github/ISSUE_TEMPLATE/**"
- "**/README.md"
workflow_dispatch:
permissions:
contents: write
concurrency:
group: android-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
JAVA_VERSION: "17"
ANDROID_API_LEVEL: "36"
ANDROID_BUILD_TOOLS: "36.0.0"
ANDROID_NDK_VERSION: "29.0.14206865"
jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'push' || !startsWith(github.event.head_commit.message, '[skip ci]') }}
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: 配置 JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- name: 配置 Gradle 缓存
uses: gradle/actions/setup-gradle@v4
- name: 配置 Android SDK
uses: android-actions/setup-android@v3
- name: 安装项目所需 Android 组件
run: |
yes | sdkmanager --licenses >/dev/null
sdkmanager \
"platform-tools" \
"platforms;android-${ANDROID_API_LEVEL}" \
"build-tools;${ANDROID_BUILD_TOOLS}" \
"ndk;${ANDROID_NDK_VERSION}"
- name: 给 gradlew 执行权限
run: chmod +x gradlew
- name: 编译 Debug 和 Release APK
run: ./gradlew --build-cache --stacktrace :app:assembleDebug :app:assembleRelease
- name: 整理构建产物
env:
REF_NAME: ${{ github.ref_name }}
REF_TYPE: ${{ github.ref_type }}
run: |
if [[ "$REF_TYPE" == "tag" ]]; then
APP_NAME="ZeroTermux-$REF_NAME"
else
APP_NAME="ZeroTermux-Nightly"
fi
mkdir -p dist
shopt -s nullglob
for file in app/build/outputs/apk/debug/*.apk; do
filename=$(basename "$file")
if [[ "$filename" =~ ^termux-app_.+-(debug|release)_(.+)\.apk$ ]]; then
build_type="${BASH_REMATCH[1]}"
abi="${BASH_REMATCH[2]}"
else
echo "Unexpected APK name: $filename" >&2
exit 1
fi
target="dist/${APP_NAME}_${build_type}_${abi}.apk"
cp "$file" "$target"
zip -j "${target%.apk}.zip" "$target"
done
for file in app/build/outputs/apk/release/*.apk; do
filename=$(basename "$file")
if [[ "$filename" =~ ^termux-app_.+-(debug|release)_(.+)\.apk$ ]]; then
build_type="${BASH_REMATCH[1]}"
abi="${BASH_REMATCH[2]}"
else
echo "Unexpected APK name: $filename" >&2
exit 1
fi
target="dist/${APP_NAME}_${build_type}_${abi}.apk"
cp "$file" "$target"
zip -j "${target%.apk}.zip" "$target"
done
ls -lah dist
- name: 上传 Debug Universal Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_debug_universal', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_debug_universal.zip
if-no-files-found: ignore
- name: 上传 Debug Arm64 Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_debug_arm64-v8a', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_debug_arm64-v8a.zip
if-no-files-found: ignore
- name: 上传 Debug Armeabi Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_debug_armeabi-v7a', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_debug_armeabi-v7a.zip
if-no-files-found: ignore
- name: 上传 Debug X86 Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_debug_x86', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_debug_x86.zip
if-no-files-found: ignore
- name: 上传 Debug X86_64 Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_debug_x86_64', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_debug_x86_64.zip
if-no-files-found: ignore
- name: 上传 Release Universal Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_release_universal', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_release_universal.zip
if-no-files-found: ignore
- name: 上传 Release Arm64 Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_release_arm64-v8a', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_release_arm64-v8a.zip
if-no-files-found: ignore
- name: 上传 Release Armeabi Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_release_armeabi-v7a', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_release_armeabi-v7a.zip
if-no-files-found: ignore
- name: 上传 Release X86 Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_release_x86', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_release_x86.zip
if-no-files-found: ignore
- name: 上传 Release X86_64 Zip
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}_release_x86_64', github.ref_type == 'tag' && format('ZeroTermux-{0}', github.ref_name) || 'ZeroTermux-Nightly') }}
path: dist/*_release_x86_64.zip
if-no-files-found: ignore
- name: 清空标签 Release 旧附件
if: startsWith(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ github.token }}
run: |
set -e
OWNER="${{ github.repository_owner }}"
REPO="${GITHUB_REPOSITORY#*/}"
TAG_NAME="${{ github.ref_name }}"
RELEASE_ID=$(gh api "repos/$OWNER/$REPO/releases/tags/$TAG_NAME" --jq '.id' 2>/dev/null || true)
if [[ -z "$RELEASE_ID" ]]; then
echo "tag release 不存在,跳过清理"
exit 0
fi
ASSET_IDS=$(gh api --paginate "repos/$OWNER/$REPO/releases/$RELEASE_ID/assets" --jq '.[].id')
for ASSET_ID in $ASSET_IDS; do
echo "删除 tag asset $ASSET_ID"
gh api -X DELETE "repos/$OWNER/$REPO/releases/assets/$ASSET_ID"
done
- name: 创建正式发布
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
draft: false
prerelease: false
files: dist/*.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}