Repository navigation
94 lines (83 loc) · 3.07 KB
/
Copy pathci.yml
File metadata and controls
94 lines (83 loc) · 3.07 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
name: 编译
on:
push:
# tag 推送由发布 workflow 负责(构建 + Maven Central + GitHub Release),此处只管分支
branches:
- '**'
paths-ignore:
- 'README.md'
- 'docs/**'
pull_request:
paths-ignore:
- 'README.md'
- 'docs/**'
workflow_dispatch:
concurrency:
# 同类事件同 ref 的最新 run 优先,取消旧 run;push 与 PR 分属不同组,
# 避免 PR 事件后来居上取消进行中的 push 构建
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-26.04
env:
# secrets 不能出现在 if 条件中,先解析为 job 级环境变量布尔值
HAS_KEYSTORE: ${{ secrets.KEYSTORE_GZ_B64 != '' }}
steps:
- name: 检出代码
uses: actions/checkout@v7
with:
submodules: recursive
- name: 配置 Gradle(依赖/构建缓存)
uses: gradle/actions/setup-gradle@v4
with:
# PR 只读缓存:避免未合并分支污染共享构建缓存
cache-read-only: ${{ github.event_name == 'pull_request' }}
- name: 解密KeyStore
# 无 secrets(如 fork 分支 push)跳过:release 不构建,只出 debug
if: github.event_name != 'pull_request' && env.HAS_KEYSTORE == 'true'
run: |
echo "${{ secrets.KEYSTORE_GZ_B64 }}" \
| base64 --decode \
| gunzip > app/release.keystore
ACTUAL_SHA=$(sha256sum app/release.keystore | awk '{print $1}')
EXPECTED_SHA=${{ secrets.KEYSTORE_EXPECTED_SHA256 }}
if [ "$ACTUAL_SHA" != "$EXPECTED_SHA" ]; then
exit 1
fi
- name: 单元测试
# 在编译前拦截回归:测试失败即中止,不浪费后续构建
run: ./gradlew --build-cache :libterminal:testDebugUnitTest
- name: 上传测试报告
# 仅测试失败时上传,便于离线排查
if: failure()
uses: actions/upload-artifact@v7
with:
archive: false
name: libterminal-test-report
path: libterminal/build/test-results/testDebugUnitTest
- name: 编译
env:
KEYSTORE_PASS: ${{ secrets.KEYSTORE_PASS }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASS: ${{ secrets.KEY_PASS }}
run: |
./gradlew --build-cache :app:assembleDebug
if [ "${{ github.event_name }}" != "pull_request" ] && [ "$HAS_KEYSTORE" = "true" ]; then
./gradlew --build-cache :app:assembleRelease
fi
- name: 上传 Debug APK
uses: actions/upload-artifact@v7
with:
archive: false
name: app-debug.apk
path: app/build/outputs/apk/debug/app-debug.apk
- name: 上传 Release APK
# 仅在有 keystore 时才有产物
if: github.event_name != 'pull_request' && env.HAS_KEYSTORE == 'true'
uses: actions/upload-artifact@v7
with:
archive: false
path: app/build/outputs/apk/release/app-release.apk