-
-
Notifications
You must be signed in to change notification settings - Fork 57
180 lines (163 loc) · 6.54 KB
/
Copy pathAndroid.yml
File metadata and controls
180 lines (163 loc) · 6.54 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
name: Android Release Build
on:
push:
tags:
- 'v*.*.*'
- 'V*.*.*'
workflow_dispatch:
permissions:
contents: write
actions: read
jobs:
# ===== 最终构建 =====
build:
name: Build Release APK
runs-on: ubuntu-latest
defaults:
run:
working-directory: "Monica for Android"
steps:
- uses: actions/checkout@v6
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: '17'
distribution: 'temurin'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v6
with:
cache-read-only: false
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Decode keystore
run: echo "${{ secrets.DEBUG_KEYSTORE_BASE64 }}" | base64 -d > $GITHUB_WORKSPACE/release.jks
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
- name: Build Release APK (signed & obfuscated)
run: |
./gradlew :app:assembleRelease --stacktrace \
-Pandroid.injected.signing.store.file=$GITHUB_WORKSPACE/release.jks \
-Pandroid.injected.signing.store.password=${{ secrets.DEBUG_STORE_PASSWORD }} \
-Pandroid.injected.signing.key.alias=${{ secrets.DEBUG_KEY_ALIAS }} \
-Pandroid.injected.signing.key.password=${{ secrets.DEBUG_KEY_PASSWORD }}
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
- name: Generate checksums
run: |
cd app/build/outputs/apk/release
apk_list="$(find . -maxdepth 1 -type f \( -iname '*.apk' \) -printf '%f\n' | sort)"
apk_count="$(printf '%s\n' "$apk_list" | sed '/^$/d' | wc -l | tr -d ' ')"
if [ "$apk_count" = "0" ]; then
echo "No release APK found for checksums"
ls -la
exit 1
fi
: > checksums.txt
printf '%s\n' "$apk_list" | sed '/^$/d' | while IFS= read -r apk_name; do
sha256sum "$apk_name" >> checksums.txt
done
- name: Upload APK
uses: actions/upload-artifact@v7
with:
name: release-apk-obfuscated
path: |
${{ github.workspace }}/Monica for Android/app/build/outputs/apk/release/*.apk
${{ github.workspace }}/Monica for Android/app/build/outputs/apk/release/*.APK
${{ github.workspace }}/Monica for Android/app/build/outputs/apk/release/checksums.txt
retention-days: 14
if-no-files-found: error
- name: Upload ProGuard/R8 mapping
uses: actions/upload-artifact@v7
with:
name: mapping-release
path: ${{ github.workspace }}/Monica for Android/app/build/outputs/mapping/release/mapping.txt
retention-days: 30
if-no-files-found: error
- name: Upload APKs to GitHub Release
if: startsWith(github.ref, 'refs/tags/')
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
output_dir="app/build/outputs/apk/release"
mapfile -d '' release_files < <(
find "$output_dir" -maxdepth 1 -type f \
\( -iname '*.apk' -o -name 'checksums.txt' \) \
-print0
)
if [ "${#release_files[@]}" -eq 0 ]; then
echo "::error title=Release assets missing::No APK or checksum files were generated."
exit 1
fi
if ! gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
gh release create "$GITHUB_REF_NAME" \
--verify-tag \
--title "$GITHUB_REF_NAME" \
--generate-notes
fi
gh release upload "$GITHUB_REF_NAME" "${release_files[@]}" --clobber
- name: Notify documentation repository about release
if: startsWith(github.ref, 'refs/tags/')
continue-on-error: true
uses: actions/github-script@v9
env:
DOCS_REPOSITORY: ${{ vars.DOCS_REPOSITORY }}
RELEASE_TAG: ${{ github.ref_name }}
with:
github-token: ${{ secrets.DOCS_REPO_TOKEN }}
script: |
const configuredRepository = process.env.DOCS_REPOSITORY?.trim();
const repository = configuredRepository?.replace(/[\u2010-\u2015\u2212]/g, "-");
if (repository && repository !== configuredRepository) {
core.warning(`Normalized DOCS_REPOSITORY from '${configuredRepository}' to '${repository}'.`);
}
if (!repository || !/^[^/]+\/[^/]+$/.test(repository)) {
core.warning("DOCS_REPOSITORY is not configured as owner/repository; skipping docs release sync.");
return;
}
const [owner, repo] = repository.split("/", 2);
await github.rest.repos.createDispatchEvent({
owner,
repo,
event_type: "monica-release-published",
client_payload: {
source_repository: `${context.repo.owner}/${context.repo.repo}`,
release_tag: process.env.RELEASE_TAG,
},
});
- name: Send arm64 APK to Telegram
if: startsWith(github.ref, 'refs/tags/')
shell: bash
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
set -euo pipefail
if [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then
echo "::error title=Telegram secrets missing::TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID is empty."
exit 1
fi
arm64_apk="$(
find app/build/outputs/apk/release -maxdepth 1 -type f \
-iname '*arm64*.apk' \
-print \
| sort \
| head -n 1
)"
if [ -z "$arm64_apk" ]; then
echo "::error title=arm64 APK missing::No arm64 APK was generated."
find app/build/outputs/apk/release -maxdepth 1 -type f -print || true
exit 1
fi
caption="🚀 新版本 ${GITHUB_REF_NAME} 已发布!
架构:arm64
仓库:${GITHUB_REPOSITORY}
下载页面:https://github.com/${GITHUB_REPOSITORY}/releases/tag/${GITHUB_REF_NAME}"
curl --fail-with-body --show-error --silent \
--retry 3 \
--retry-all-errors \
--form-string "chat_id=${TELEGRAM_CHAT_ID}" \
--form-string "caption=${caption}" \
--form "document=@${arm64_apk}" \
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument"