forked from chen2he/orange-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (97 loc) · 3.6 KB
/
Copy pathsync-and-release.yml
File metadata and controls
111 lines (97 loc) · 3.6 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
name: Sync upstream and release
on:
schedule:
- cron: "0 */6 * * *"
workflow_dispatch:
inputs:
force_build:
description: "强制编译一次(忽略是否有新提交)"
type: boolean
default: false
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.merge.outputs.has_changes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Merge upstream
id: merge
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git remote add upstream https://github.com/chen2he/orange-cloud.git
git fetch upstream
BEFORE=$(git rev-parse HEAD)
git merge upstream/main --no-edit
AFTER=$(git rev-parse HEAD)
if [ "$BEFORE" != "$AFTER" ]; then
git push origin HEAD:main
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
build:
needs: sync
if: needs.sync.outputs.has_changes == 'true' || inputs.force_build == true
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/android
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Set up Android SDK
uses: android-actions/setup-android@v3
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Remove daemon JVM pin (CI has no JetBrains JBR)
run: rm -f gradle/gradle-daemon-jvm.properties
- name: Decode keystore
run: |
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > app/release.jks
cat > keystore.properties <<EOF
storeFile=release.jks
storePassword=${{ secrets.KEYSTORE_PASSWORD }}
keyAlias=${{ secrets.KEY_ALIAS }}
keyPassword=${{ secrets.KEY_PASSWORD }}
EOF
- name: Build OSS release APK
run: ./gradlew :app:assembleOssRelease -POAUTH_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }}
- name: Read version from build.gradle.kts
id: version
run: |
BASE_VERSION=$(grep -oP 'versionName\s*=\s*"\K[^"]+' app/build.gradle.kts | head -n1)
if [ -z "$BASE_VERSION" ]; then
echo "Could not find versionName in app/build.gradle.kts" >&2
exit 1
fi
# oss flavor 有 versionNameSuffix(如 "-oss"),拼到 base 版本号后面,
# 与实际打出来的 APK 版本号保持一致
OSS_SUFFIX=$(awk '/create\("oss"\)/,/^\s*}/' app/build.gradle.kts \
| grep -oP 'versionNameSuffix\s*=\s*"\K[^"]+' | head -n1)
echo "name=${BASE_VERSION}${OSS_SUFFIX}" >> "$GITHUB_OUTPUT"
- name: Compute tag
id: tag
run: echo "tag=oss-v${{ steps.version.outputs.name }}-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.tag }}
name: OSS build v${{ steps.version.outputs.name }}
files: apps/android/app/build/outputs/apk/oss/release/*.apk
body: |
自动同步自 chen2he/orange-cloud 上游更新,OSS 风味 release 签名构建。
版本: ${{ steps.version.outputs.name }}
Commit: ${{ github.sha }}