-
Notifications
You must be signed in to change notification settings - Fork 4
233 lines (196 loc) · 7.83 KB
/
ci.yml
File metadata and controls
233 lines (196 loc) · 7.83 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
222
223
224
225
226
227
228
229
230
231
232
233
name: CI Build
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- 'v*'
defaults:
run:
shell: bash
env:
RUST_TOOLCHAIN: "stable"
RUSTC_BOOTSTRAP: "1"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '25'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6
- name: Make gradlew executable
run: chmod +x gradlew
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: "x86_64-unknown-linux-gnu"
components: "rustfmt,clippy,rust-src"
- name: Setup Android NDK
uses: nttld/setup-ndk@v1
with:
ndk-version: r29
- name: Add Rust Android targets
run: |
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
rustup target add x86_64-linux-android
- uses: taiki-e/install-action@v2
with:
tool: cargo-ndk
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.9
- name: Cache Gradle dependencies
uses: actions/cache@v5
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Decode Keystore
if: github.event_name != 'pull_request'
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
run: |
echo "$KEYSTORE_BASE64" | base64 --decode > keystore.jks
- name: Get version info
if: github.event_name != 'pull_request'
id: version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
else
echo "version=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
fi
- name: Gen binding
run: |
touch local.properties
./gradlew assembleDebug -Prust-target=arm64
./gradlew clean
cd uniffi
cargo clean
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
- name: Build Debug APK
if: github.event_name == 'pull_request'
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
run: |
./gradlew assembleDebug
- name: Build Release APKs
if: github.event_name != 'pull_request'
env:
KEYSTORE_FILE: ${{ github.workspace }}/keystore.jks
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
ANDROID_SPLIT_ABI_ENABLE: true
ANDROID_SPLIT_ABI_UNIVERSAL_APK: true
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
run: |
rm -rf app/build/outputs/apk
./gradlew assembleRelease
- name: Organize APKs
if: github.event_name != 'pull_request'
run: |
mkdir -p output
VERSION="${{ steps.version.outputs.version }}"
# Copy and rename APKs
cp app/build/outputs/apk/release/*-arm64-v8a-release.apk output/clash-android-${VERSION}-arm64-v8a.apk || true
cp app/build/outputs/apk/release/*-armeabi-v7a-release.apk output/clash-android-${VERSION}-armeabi-v7a.apk || true
cp app/build/outputs/apk/release/*-x86-release.apk output/clash-android-${VERSION}-x86.apk || true
cp app/build/outputs/apk/release/*-x86_64-release.apk output/clash-android-${VERSION}-x86_64.apk || true
cp app/build/outputs/apk/release/*-universal-release.apk output/clash-android-${VERSION}-all.apk || true
ls -lh output/
- name: Create and publish release
if: github.event_name != 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || 'latest' }}
run: |
# Delete old latest release if creating a new latest release
if [ "$TAG_NAME" = "latest" ]; then
gh release delete "$TAG_NAME" --yes --cleanup-tag || true
fi
# Create draft release with changelog
if [[ "$TAG_NAME" == v* ]]; then
gh release create "$TAG_NAME" --draft --latest --title "$TAG_NAME"
else
gh release create "$TAG_NAME" --draft --title "测试构建"
fi
# Upload all package files
find ./output -type f -exec gh release upload "$TAG_NAME" {} \;
# Upload LICENSE file
gh release upload "$TAG_NAME" LICENSE
- name: Determine commit range for changelog
if: github.event_name != 'pull_request'
id: commit-range
run: |
# Check if this is a release (v* tag) or prerelease (push to main)
if [[ $GITHUB_REF == refs/tags/v* ]]; then
# For release: use previous v tag to current v tag
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
# Get the previous v* tag (use -F -x for fixed string exact matching)
PREVIOUS_TAG=$(git tag -l "v*" --sort=-version:refname | grep -F -x -v "${CURRENT_TAG}" | head -n 1)
if [ -z "$PREVIOUS_TAG" ]; then
# No previous tag found, use all commits up to current tag
echo "args=${CURRENT_TAG}" >> $GITHUB_OUTPUT
else
echo "args=${PREVIOUS_TAG}..${CURRENT_TAG}" >> $GITHUB_OUTPUT
fi
else
# For prerelease: use most recent v* tag to current commit
LATEST_TAG=$(git tag -l "v*" --sort=-version:refname | head -n 1)
if [ -z "$LATEST_TAG" ]; then
# No v* tag found, use all commits up to HEAD
echo "args=HEAD" >> $GITHUB_OUTPUT
else
echo "args=${LATEST_TAG}..HEAD" >> $GITHUB_OUTPUT
fi
fi
- name: Generate a changelog
if: github.event_name != 'pull_request'
uses: orhun/git-cliff-action@main
id: git-cliff
with:
config: .github/cliff.toml
args: ${{ steps.commit-range.outputs.args }} --strip header
env:
GITHUB_REPO: ${{ github.repository }}
OUTPUT: CHANGELOG.md
- name: Publish release
if: github.event_name != 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || 'latest' }}
run: |
# Publish the release (change from draft to published)
if [[ "$TAG_NAME" == v* ]]; then
gh release edit "$TAG_NAME" --draft=false --latest --notes-file CHANGELOG.md
else
gh release edit "$TAG_NAME" --draft=false --prerelease --notes-file CHANGELOG.md
fi