Skip to content

Commit 87d7da0

Browse files
committed
ci: secrets 不可用于 if 条件,改由 job env 布尔值判定 keystore 可用性
1 parent edf16ef commit 87d7da0

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ permissions:
1717
jobs:
1818
build:
1919
runs-on: ubuntu-26.04
20+
env:
21+
# secrets 不能出现在 if 条件中,先解析为 job 级环境变量布尔值
22+
HAS_KEYSTORE: ${{ secrets.KEYSTORE_GZ_B64 != '' }}
2023
steps:
2124
- name: 检出代码
2225
uses: actions/checkout@v7
@@ -31,7 +34,7 @@ jobs:
3134

3235
- name: 解密KeyStore
3336
# 无 secrets(如 fork 分支 push)跳过:release 不构建,只出 debug
34-
if: github.event_name != 'pull_request' && secrets.KEYSTORE_GZ_B64 != ''
37+
if: github.event_name != 'pull_request' && env.HAS_KEYSTORE == 'true'
3538
run: |
3639
echo "${{ secrets.KEYSTORE_GZ_B64 }}" \
3740
| base64 --decode \
@@ -49,7 +52,7 @@ jobs:
4952
KEY_PASS: ${{ secrets.KEY_PASS }}
5053
run: |
5154
./gradlew --build-cache :app:assembleDebug
52-
if [ "${{ github.event_name }}" != "pull_request" ] && [ -n "${{ secrets.KEYSTORE_GZ_B64 }}" ]; then
55+
if [ "${{ github.event_name }}" != "pull_request" ] && [ "$HAS_KEYSTORE" = "true" ]; then
5356
./gradlew --build-cache :app:assembleRelease
5457
fi
5558
@@ -62,7 +65,7 @@ jobs:
6265

6366
- name: 上传 Release APK
6467
# 仅在有 keystore 时才有产物
65-
if: github.event_name != 'pull_request' && secrets.KEYSTORE_GZ_B64 != ''
68+
if: github.event_name != 'pull_request' && env.HAS_KEYSTORE == 'true'
6669
uses: actions/upload-artifact@v7
6770
with:
6871
archive: false

0 commit comments

Comments
 (0)