-
Notifications
You must be signed in to change notification settings - Fork 27
132 lines (112 loc) · 4.39 KB
/
Copy pathrelease.yml
File metadata and controls
132 lines (112 loc) · 4.39 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
name: 创建 Release 并上传 APK
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version_code:
description: '版本号 (versionCode),留空则使用 version.properties 中的值'
required: false
type: string
default: ''
version_name:
description: '版本名称 (versionName),留空则使用 version.properties 中的值'
required: false
type: string
default: ''
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-release:
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: write
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置 JDK 21
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
- name: 设置 Gradle
uses: gradle/actions/setup-gradle@v4
- name: 授予 gradlew 执行权限
run: chmod +x gradlew
- name: 验证签名 Secrets
run: |
missing=""
[ -z "${{ secrets.KEYSTORE_BASE64 }}" ] && missing="$missing KEYSTORE_BASE64"
[ -z "${{ secrets.STORE_PASSWORD }}" ] && missing="$missing STORE_PASSWORD"
[ -z "${{ secrets.KEY_ALIAS }}" ] && missing="$missing KEY_ALIAS"
[ -z "${{ secrets.KEY_PASSWORD }}" ] && missing="$missing KEY_PASSWORD"
if [ -n "$missing" ]; then
echo "::error::以下 Secrets 未配置:$missing"
exit 1
fi
- name: 准备签名文件
run: echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > app/release.jks
- name: 构建 Release APK 并生成构建清单
run: |
./gradlew :app:assembleRelease :app:printReleaseAppConfig --stacktrace \
-PStoreFile=release.jks \
-PStorePassword="${{ secrets.STORE_PASSWORD }}" \
-PKeyAlias="${{ secrets.KEY_ALIAS }}" \
-PKeyPassword="${{ secrets.KEY_PASSWORD }}"
env:
GRADLE_OPTS: -Xmx2g -Dfile.encoding=UTF-8
APP_VERSION_CODE: ${{ github.event.inputs.version_code || '' }}
APP_VERSION_NAME: ${{ github.event.inputs.version_name || '' }}
- name: 读取构建清单
id: manifest
run: |
MANIFEST_PATH="app/build/outputs/build-manifest.json"
if [ ! -f "$MANIFEST_PATH" ]; then
echo "::error::build-manifest.json 未找到,请确保构建步骤执行成功。"
echo "预期路径: $MANIFEST_PATH"
exit 1
fi
echo "=== 构建清单内容 ==="
cat "$MANIFEST_PATH"
APK_PATH=$(jq -r '.apkPath' "$MANIFEST_PATH")
APK_NAME=$(jq -r '.apkName' "$MANIFEST_PATH")
APP_CONFIG_PATH=$(jq -r '.appConfigPath' "$MANIFEST_PATH")
VERSION_NAME=$(jq -r '.versionName' "$MANIFEST_PATH")
if [ ! -f "$APK_PATH" ]; then
echo "::error::APK 文件不存在: $APK_PATH"
exit 1
fi
echo "apk_path=$APK_PATH" >> $GITHUB_OUTPUT
echo "apk_name=$APK_NAME" >> $GITHUB_OUTPUT
echo "app_config_path=$APP_CONFIG_PATH" >> $GITHUB_OUTPUT
echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT
echo "::notice::构建成功 — $APK_NAME (v$VERSION_NAME)"
- name: 上传 APK 为 Artifact
if: github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.manifest.outputs.apk_name }}
path: |
${{ steps.manifest.outputs.apk_path }}
${{ steps.manifest.outputs.app_config_path }}
if-no-files-found: error
retention-days: 30
- name: 创建 GitHub Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
files: |
${{ steps.manifest.outputs.apk_path }}
${{ steps.manifest.outputs.app_config_path }}
name: "Release ${{ github.ref_name }}"
body: |
**版本:** ${{ steps.manifest.outputs.version_name }}
此版本由 GitHub Actions 自动构建和发布。
prerelease: false
fail_on_unmatched_files: true
- name: 清理敏感文件
if: always()
run: rm -f app/release.jks app/gradle.properties app/build/outputs/build-manifest.json