-
Notifications
You must be signed in to change notification settings - Fork 9
221 lines (196 loc) · 7.95 KB
/
Copy pathbuild.yml
File metadata and controls
221 lines (196 loc) · 7.95 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
name: Build APK
on:
workflow_dispatch:
inputs:
release_tag:
description: 'Release Tag (Optional)'
required: false
type: string
build_type:
description: 'Build Type'
required: true
default: 'test'
type: choice
options:
- test
- release
upload_telegram:
description: 'Upload APK to Telegram?'
required: true
default: false
type: boolean
commit_shas:
description: 'Commit SHAs to upload (one per line or comma-separated; empty sends all history)'
required: false
default: ''
type: string
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
env:
BUILD_TYPE: ${{ github.event.inputs.build_type == 'release' && 'release' || 'releaseTesting' }}
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
submodules: 'recursive'
fetch-depth: '0'
- name: Prepare commit metadata
id: commit_metadata
shell: bash
env:
EVENT_BEFORE: ${{ github.event.before }}
SELECTED_COMMIT_SHAS: ${{ inputs.commit_shas }}
CURRENT_SHA: ${{ github.sha }}
run: |
echo "message=$(git log -1 --pretty=%s)" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_OUTPUT"
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
if [[ -n "${EVENT_BEFORE}" \
&& "${EVENT_BEFORE}" != "0000000000000000000000000000000000000000" \
&& "${EVENT_BEFORE}" != "${CURRENT_SHA}" ]] \
&& git cat-file -e "${EVENT_BEFORE}^{commit}" 2>/dev/null; then
echo "range=${EVENT_BEFORE}..${CURRENT_SHA}" >> "$GITHUB_OUTPUT"
else
echo "range=${CURRENT_SHA}" >> "$GITHUB_OUTPUT"
fi
else
echo "range=${CURRENT_SHA}" >> "$GITHUB_OUTPUT"
fi
- name: Setup Android SDK
uses: android-actions/setup-android@v4
with:
log-accepted-android-sdk-licenses: false
cmdline-tools-version: '14742923'
packages: 'platforms;android-37.0 build-tools;37.0.0 platform-tools'
- name: Install NDK
run: |
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager \
--channel=0 \
--install "ndk;29.0.14206865"
echo "NDK_HOME=$ANDROID_HOME/ndk/29.0.14206865" >> $GITHUB_ENV
- name: Restore cached libhevtun
id: cache-libhevtun-restore
uses: actions/cache/restore@v6
with:
path: ${{ github.workspace }}/libs
key: libhevtun-${{ runner.os }}-${{ env.NDK_HOME }}-${{ hashFiles('.git/modules/hev-socks5-tunnel/HEAD') }}-${{ hashFiles('compile-hevtun.sh') }}
- name: Build libhevtun
if: steps.cache-libhevtun-restore.outputs.cache-hit != 'true'
run: |
bash compile-hevtun.sh
- name: Save libhevtun
if: steps.cache-libhevtun-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
with:
path: ${{ github.workspace }}/libs
key: libhevtun-${{ runner.os }}-${{ env.NDK_HOME }}-${{ hashFiles('.git/modules/hev-socks5-tunnel/HEAD') }}-${{ hashFiles('compile-hevtun.sh') }}
- name: Copy libhevtun
run: |
cp -r ${{ github.workspace }}/libs ${{ github.workspace }}/MikuRay/app
- name: Fetch AndroidLibXrayLite tag
run: |
pushd AndroidLibXrayLite
CURRENT_TAG=$(git describe --tags --abbrev=0)
echo "Current tag in this repo: $CURRENT_TAG"
echo "CURRENT_TAG=$CURRENT_TAG" >> $GITHUB_ENV
popd
- name: Download libv2ray
uses: robinraju/release-downloader@v1.13
with:
repository: '2dust/AndroidLibXrayLite'
tag: ${{ env.CURRENT_TAG }}
fileName: 'libv2ray.aar'
out-file-path: MikuRay/app/libs/
- name: Setup Java
uses: actions/setup-java@v5.7.0
with:
distribution: 'temurin'
java-version: '21'
- name: Decode Keystore
uses: timheuer/base64-to-file@v2.0.0
id: android_keystore
with:
fileName: "android_keystore.jks"
encodedString: ${{ secrets.APP_KEYSTORE_BASE64 }}
- name: Build APK (${{ env.BUILD_TYPE }})
run: |
cd ${{ github.workspace }}/MikuRay
echo "sdk.dir=${ANDROID_HOME}" > local.properties
chmod 755 gradlew
if [ "${{ env.BUILD_TYPE }}" == "releaseTesting" ]; then
echo "Starting TEST build process with R8..."
./gradlew assembleReleaseTesting --console=plain \
-PKS_PATH="${{ steps.android_keystore.outputs.filePath }}" \
-PKS_PASS="${{ secrets.APP_KEYSTORE_PASSWORD }}" \
-PKS_ALIAS="${{ secrets.APP_KEYSTORE_ALIAS }}" \
-PKEY_PASS="${{ secrets.APP_KEY_PASSWORD }}"
else
echo "Starting RELEASE build process with R8..."
./gradlew assembleRelease --console=plain \
-PKS_PATH="${{ steps.android_keystore.outputs.filePath }}" \
-PKS_PASS="${{ secrets.APP_KEYSTORE_PASSWORD }}" \
-PKS_ALIAS="${{ secrets.APP_KEYSTORE_ALIAS }}" \
-PKEY_PASS="${{ secrets.APP_KEY_PASSWORD }}"
fi
- name: Upload arm64-v8a APK
uses: actions/upload-artifact@v7
if: ${{ success() }}
with:
name: arm64-v8a-${{ env.BUILD_TYPE }}
path: ${{ github.workspace }}/MikuRay/app/build/outputs/apk/${{ env.BUILD_TYPE }}/*arm64-v8a*.apk
- name: Upload armeabi-v7a APK
uses: actions/upload-artifact@v7
if: ${{ success() }}
with:
name: armeabi-v7a-${{ env.BUILD_TYPE }}
path: ${{ github.workspace }}/MikuRay/app/build/outputs/apk/${{ env.BUILD_TYPE }}/*armeabi-v7a*.apk
- name: Upload x86 APK
uses: actions/upload-artifact@v7
if: ${{ success() }}
with:
name: x86-apk-${{ env.BUILD_TYPE }}
path: ${{ github.workspace }}/MikuRay/app/build/outputs/apk/${{ env.BUILD_TYPE }}/*x86*.apk
- name: Check Telegram configuration
id: telegram-config
if: ${{ success() && env.BUILD_TYPE == 'releaseTesting' && github.event_name == 'workflow_dispatch' && inputs.upload_telegram == true }}
shell: bash
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
if [[ -n "${TELEGRAM_BOT_TOKEN}" && -n "${TELEGRAM_CHAT_ID}" ]]; then
echo "configured=true" >> "$GITHUB_OUTPUT"
else
echo "configured=false" >> "$GITHUB_OUTPUT"
echo "Telegram upload skipped: Telegram secrets are not configured."
fi
- name: Upload APKs to Telegram
if: ${{ env.BUILD_TYPE == 'releaseTesting' && github.event_name == 'workflow_dispatch' && inputs.upload_telegram == true && steps.telegram-config.outputs.configured == 'true' }}
shell: bash
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
APK_DIR: ${{ github.workspace }}/MikuRay/app/build/outputs/apk/${{ env.BUILD_TYPE }}
BUILD_TYPE: ${{ env.BUILD_TYPE }}
TELEGRAM_COMMIT_MESSAGE: ${{ steps.commit_metadata.outputs.message }}
TELEGRAM_COMMIT_SHA: ${{ steps.commit_metadata.outputs.sha }}
TELEGRAM_COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}
TELEGRAM_COMMIT_RANGE: ${{ steps.commit_metadata.outputs.range }}
TELEGRAM_COMMIT_SHAS: ${{ inputs.commit_shas }}
TELEGRAM_REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
run: bash ./scripts/upload-apks-to-telegram.sh
- name: Upload to release
uses: svenstaro/upload-release-action@v2
if: github.event.inputs.release_tag != ''
with:
repo_token: ${{ secrets.MY_PERSONAL_TOKEN }}
file: ${{ github.workspace }}/MikuRay/app/build/outputs/apk/${{ env.BUILD_TYPE }}/*.apk
tag: ${{ github.event.inputs.release_tag }}
file_glob: true
prerelease: true