1- name : Build
1+ name : Buildon
22
33on :
44 workflow_dispatch :
1010 Premium :
1111 description : ' Premium'
1212 required : true
13- default : ' false '
13+ default : ' true '
1414 Foss :
1515 description : ' Foss'
1616 required : true
17- default : ' false '
17+ default : ' true '
1818 release_type :
1919 description : ' Release Type'
2020 required : true
2727 description : ' Version Name (e.g., 2.0.13-S3)'
2828 required : false
2929 default : ' '
30- version_code :
31- description : ' Version Code (e.g., 3501200)'
32- required : false
33- default : ' '
3430
3531jobs :
3632 build :
3733 name : " Build APKs"
3834 runs-on : ubuntu-latest
39-
4035 permissions :
4136 contents : write
42-
4337 timeout-minutes : 60
44-
4538 steps :
4639 - name : Checkout
4740 uses : actions/checkout@v4
4841 with :
49- ref : feature/restic-integration # 指定使用 s3 分支
42+ ref : feature/restic-integration
43+ fetch-depth : 0 # 获取完整提交历史以统计 commit 数量
5044
5145 - name : Validate gradle wrapper
5246 uses : gradle/wrapper-validation-action@v1
@@ -60,26 +54,34 @@ jobs:
6054 - name : Setup gradle
6155 uses : gradle/gradle-build-action@v2
6256
63- - name : Change to source directory
64- run : cd source
65-
66- - name : Setup gradlew
67- run : chmod +x gradlew
68- working-directory : source
69-
70- - name : Check build-logic
71- run : ./gradlew check -p build-logic
57+ - name : Calculate Dynamic Version
58+ id : calc_version
59+ run : |
60+ # 核心逻辑:基础 30000 + Commit 总数
61+ COMMITS=$(git rev-list --count HEAD)
62+ BASE_CODE=30000
63+ DYNAMIC_CODE=$((BASE_CODE + COMMITS))
64+ echo "code=$DYNAMIC_CODE" >> $GITHUB_OUTPUT
65+
66+ # 确定版本名称
67+ if [ -n "${{ github.event.inputs.version_name }}" ]; then
68+ VERSION_NAME="${{ github.event.inputs.version_name }}"
69+ else
70+ VERSION_NAME=$(grep "versionName" gradle/libs.versions.toml | cut -d'"' -f2)
71+ fi
72+ echo "name=$VERSION_NAME" >> $GITHUB_OUTPUT
73+
74+ echo "Final Version Code: $DYNAMIC_CODE"
75+ echo "Final Version Name: $VERSION_NAME"
7276 working-directory : source
7377
74- - name : Build with gradle (Skip signing )
78+ - name : Build with gradle (Dynamic Version Injection )
7579 id : gradle
7680 env :
7781 BUILD_ALPHA : ${{ github.event.inputs.Alpha }}
7882 BUILD_PREMIUM : ${{ github.event.inputs.Premium }}
7983 BUILD_FOSS : ${{ github.event.inputs.Foss }}
8084 run : |
81- echo "Building without signing - using debug variants"
82-
8385 TASKS=""
8486 if [ "${BUILD_ALPHA}" = 'true' ]; then
8587 TASKS="$TASKS assembleArm64-v8aAlphaDebug assembleArmeabi-v7aAlphaDebug assembleX86AlphaDebug assembleX86_64AlphaDebug"
@@ -90,77 +92,54 @@ jobs:
9092 if [ "${BUILD_FOSS}" = 'true' ]; then
9193 TASKS="$TASKS assembleArm64-v8aFossDebug assembleArmeabi-v7aFossDebug assembleX86FossDebug assembleX86_64FossDebug"
9294 fi
95+
9396 if [ -z "${TASKS}" ]; then
9497 TASKS="assembleDebug"
9598 fi
9699
97- echo "Running tasks: $TASKS"
98- ./gradlew $TASKS --daemon --parallel
100+ chmod +x gradlew
101+ # 注入版本参数,对应 build.gradle.kts 中的 project.hasProperty 逻辑
102+ ./gradlew $TASKS \
103+ -PversionCode=${{ steps.calc_version.outputs.code }} \
104+ -PversionName="${{ steps.calc_version.outputs.name }}" \
105+ --daemon --parallel
99106 working-directory : source
100107
101108 - name : Move APKs to root
102109 run : |
103- # 在 source 目录创建 APKs 目录并移动文件
104110 mkdir -p ../build-output
105111 find . -name "*.apk" -exec mv {} ../build-output/ \;
106- echo "APK files in root build-output :"
107- ls -la ../build-output/
112+ echo "Collected APKs :"
113+ ls -R ../build-output/
108114 working-directory : source
109115
110116 - name : Upload APKs
111117 uses : actions/upload-artifact@v4
112118 with :
113- name : APKs
119+ name : APKs-v${{ steps.calc_version.outputs.name }}-b${{ steps.calc_version.outputs.code }}
114120 path : build-output/*.apk
115121
116- - name : Get version name
117- id : version
118- run : |
119- if [ -n "${{ github.event.inputs.version_name }}" ]; then
120- VERSION="${{ github.event.inputs.version_name }}"
121- else
122- VERSION=$(grep "versionName" gradle/libs.versions.toml | cut -d'"' -f2)
123- fi
124- echo "version=$VERSION" >> $GITHUB_OUTPUT
125-
126- if [ -n "${{ github.event.inputs.version_code }}" ]; then
127- CODE="${{ github.event.inputs.version_code }}"
128- else
129- CODE=$(grep "versionCode" gradle/libs.versions.toml | cut -d'"' -f2)
130- fi
131- echo "code=$CODE" >> $GITHUB_OUTPUT
132- working-directory : source
133-
134122 - name : Create Release
135123 if : github.event.inputs.release_type != ''
136124 uses : softprops/action-gh-release@v1
137125 with :
138- tag_name : v${{ steps.version .outputs.version }}
139- name : v${{ steps.version .outputs.version }}
126+ tag_name : v${{ steps.calc_version .outputs.name }}.${{ steps.calc_version.outputs.code }}
127+ name : v${{ steps.calc_version .outputs.name }} (Build ${{ steps.calc_version.outputs.code }})
140128 prerelease : ${{ github.event.inputs.release_type == 'pre-release' }}
141129 files : build-output/*.apk
142130 body : |
143- ## What's New in v${{ steps.version.outputs.version }}
144-
145- ### Version Info
146- - Version Name: ${{ steps.version.outputs.version }}
147- - Version Code: ${{ steps.version.outputs.code }}
131+ ## Release Info
132+ - **Version:** `${{ steps.calc_version.outputs.name }}`
133+ - **Build Code:** `${{ steps.calc_version.outputs.code }}` (Base 30000 + Commits)
134+ - **Branch:** `feature/restic-integration`
148135
149- ### Features
150- - Build type: ${{ github.event.inputs.release_type }}
136+ ### Included Variants
151137 - Alpha: ${{ github.event.inputs.Alpha }}
152138 - Premium: ${{ github.event.inputs.Premium }}
153139 - Foss: ${{ github.event.inputs.Foss }}
154- - Branch: s3 (S3-specific features)
155140
156141 ### Note
157- ⚠️ This is a DEBUG build without signing, for testing purposes only.
158-
159- ### Download
160- Choose the APK file matching your device architecture:
161- - arm64-v8a (recommended for most modern devices)
162- - armeabi-v7a (for older 32-bit ARM devices)
163- - x86_64 (for x86 64-bit devices)
164- - x86 (for x86 32-bit devices)
142+ ⚠️ This is a **DEBUG** build without formal signing, created for testing purposes.
143+ All ABIs in this build share the same Version Code.
165144 env :
166145 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments