forked from xingguangcuican6666/android-simple-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (157 loc) · 7.24 KB
/
android.yml
File metadata and controls
186 lines (157 loc) · 7.24 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
name: Android CI
on:
push:
branches: [ master ]
tags:
- 'v*'
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
# 已集成chromium内核,无需编译,跳过此步骤
- name: 安装Gradle Wrapper
run: |
gradle wrapper --gradle-version 8.9
chmod +x ./gradlew
- name: 安装chromium webview依赖(系统已集成,默认即为chromium内核)
run: echo "Android WebView 默认基于Chromium,无需额外配置"
# 获取版本信息
- name: 获取版本信息
id: version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
else
VERSION=$(grep "versionName" app/build.gradle | awk '{print $2}' | tr -d '"')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
fi
echo "Version: $VERSION"
# 更新版本号(仅在tag推送时,用于构建)
- name: 更新build.gradle版本号
if: startsWith(github.ref, 'refs/tags/')
run: |
VERSION=${{ steps.version.outputs.version }}
VERSION_CODE=$(grep "versionCode" app/build.gradle | awk '{print $2}')
# 从版本号计算 versionCode (例如 1.0.0 -> 10000, 1.2.3 -> 10203)
# 支持标准语义化版本 major.minor.patch
IFS='.' read -ra VER <<< "$VERSION"
MAJOR=${VER[0]:-0}
MINOR=${VER[1]:-0}
PATCH=${VER[2]:-0}
# 移除可能的预发布标识符 (例如 1.0.0-beta -> 1.0.0)
PATCH=$(echo $PATCH | cut -d'-' -f1 | cut -d'+' -f1)
CALC_VERSION_CODE=$((MAJOR * 10000 + MINOR * 100 + PATCH))
# 使用计算出的 versionCode(确保单调递增)
if [ $CALC_VERSION_CODE -gt $VERSION_CODE ]; then
NEW_VERSION_CODE=$CALC_VERSION_CODE
else
NEW_VERSION_CODE=$((VERSION_CODE + 1))
fi
sed -i "s/versionCode $VERSION_CODE/versionCode $NEW_VERSION_CODE/" app/build.gradle
sed -i "s/versionName \".*\"/versionName \"$VERSION\"/" app/build.gradle
echo "Updated versionCode to $NEW_VERSION_CODE"
echo "Updated versionName to $VERSION"
- name: Build Debug APK
run: ./gradlew assembleDebug --no-daemon
working-directory: ./
# 配置签名(仅在发布时)
- name: 配置Release签名
if: startsWith(github.ref, 'refs/tags/')
run: |
# 验证所有必需的签名凭据是否存在
if [ -z "${{ secrets.KEYSTORE_BASE64 }}" ] || \
[ -z "${{ secrets.KEYSTORE_PASSWORD }}" ] || \
[ -z "${{ secrets.KEY_ALIAS }}" ] || \
[ -z "${{ secrets.KEY_PASSWORD }}" ]; then
echo "Error: Missing required signing secrets"
echo "Please configure: KEYSTORE_BASE64, KEYSTORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD"
exit 1
fi
# 创建临时目录用于存放签名文件
mkdir -p /tmp/signing
chmod 700 /tmp/signing
# 从GitHub Secrets解码keystore文件到临时目录
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > /tmp/signing/release.keystore
chmod 600 /tmp/signing/release.keystore
# 验证keystore文件是否成功创建
if [ ! -f /tmp/signing/release.keystore ] || [ ! -s /tmp/signing/release.keystore ]; then
echo "Error: Failed to create keystore file or file is empty"
exit 1
fi
echo "Keystore file created successfully in secure temporary directory"
- name: Build Release APK
if: startsWith(github.ref, 'refs/tags/')
run: ./gradlew assembleRelease --no-daemon
working-directory: ./
env:
KEYSTORE_FILE: /tmp/signing/release.keystore
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
- name: 清理签名密钥文件
if: always() && startsWith(github.ref, 'refs/tags/')
run: |
# 删除临时的keystore文件和目录以防止泄露
rm -rf /tmp/signing
echo "Keystore file and temporary directory cleaned up"
- name: 重命名APK文件
run: |
VERSION=${{ steps.version.outputs.version }}
if [ -f app/build/outputs/apk/debug/app-debug.apk ]; then
cp app/build/outputs/apk/debug/app-debug.apk app/build/outputs/apk/debug/SCE-API-${VERSION}-debug.apk
fi
# Release APK现在是已签名的
if [ -f app/build/outputs/apk/release/app-release.apk ]; then
cp app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/SCE-API-${VERSION}-release.apk
elif [ -f app/build/outputs/apk/release/app-release-unsigned.apk ]; then
# 如果签名失败,仍然复制未签名版本
cp app/build/outputs/apk/release/app-release-unsigned.apk app/build/outputs/apk/release/SCE-API-${VERSION}-release.apk
fi
- name: 上传Debug APK产物
uses: actions/upload-artifact@v4
with:
name: SCE-API-${{ steps.version.outputs.version }}-debug
path: app/build/outputs/apk/debug/SCE-API-${{ steps.version.outputs.version }}-debug.apk
- name: 上传Release APK产物
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4
with:
name: SCE-API-${{ steps.version.outputs.version }}-release
path: app/build/outputs/apk/release/SCE-API-${{ steps.version.outputs.version }}-release.apk
# 创建GitHub Release
- name: 创建GitHub Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: |
app/build/outputs/apk/debug/SCE-API-${{ steps.version.outputs.version }}-debug.apk
app/build/outputs/apk/release/SCE-API-${{ steps.version.outputs.version }}-release.apk
body: |
## SCE API v${{ steps.version.outputs.version }}
### 更新内容
- 自动构建发布
### 下载说明
- **SCE-API-${{ steps.version.outputs.version }}-debug.apk**: 调试版本,包含调试信息
- **SCE-API-${{ steps.version.outputs.version }}-release.apk**: 发布版本(已签名)
### 安装要求
- Android 7.0 (API 24) 或更高版本
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 注意:版本号更新仅用于构建APK,不会提交回仓库
# 手动管理版本:在推送新tag前,请手动更新 app/build.gradle 中的版本信息