Skip to content

Commit e510726

Browse files
committed
ci: Optimize and consolidate CI/CD workflows
This commit introduces significant optimizations and consolidation to the GitHub Actions workflows to improve performance and maintainability. ### Key Changes: - **Consolidated CI Jobs:** - In `ci.yml`, the previous `build`, `lint`, and `assemble-release` jobs have been merged into a single, more efficient `build-and-test` job. - This new job now handles building, testing, linting, and assembling all APK variants (debug and release) in one unified process. - **Gradle Performance Optimizations:** - **Gradle Build Action:** Replaced `actions/setup-java` with `gradle/actions/setup-gradle@v4` for superior caching. This enables `gradle-home-cache-cleanup` to keep the cache lean. - **Parallel Execution:** Enabled the `--parallel` flag for all Gradle commands to speed up execution by running tasks concurrently. - **Build Cache:** Enabled the `--build-cache` flag to reuse outputs from previous builds, significantly reducing build times. - **Configuration Cache:** Enabled the `--configuration-cache` flag to speed up the configuration phase of Gradle builds. - **Dependency Pre-downloading:** A new "Pre-download dependencies" step (`./gradlew dependencies`) has been added to both `ci.yml` and `build-release.yml` to warm up the cache and make subsequent build steps faster. - **Workflow Enhancements:** - Removed the `--no-daemon` flag from Gradle commands, allowing the Gradle Daemon to be used for better performance. - The `build-and-test` job now uploads debug and release APKs as artifacts upon successful completion.
1 parent f5e7c92 commit e510726

File tree

2 files changed

+58
-79
lines changed

2 files changed

+58
-79
lines changed

.github/workflows/build-release.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ jobs:
4141
with:
4242
java-version: '17'
4343
distribution: 'temurin'
44-
cache: 'gradle'
44+
45+
- name: Setup Gradle
46+
uses: gradle/actions/setup-gradle@v4
47+
with:
48+
cache-read-only: false
49+
gradle-home-cache-cleanup: true
4550

4651
- name: Grant execute permission for gradlew
4752
run: chmod +x gradlew
@@ -50,14 +55,17 @@ jobs:
5055
run: |
5156
echo "${{ secrets.GOOGLE_SERVICES_JSON }}" | base64 -d > app/google-services.json
5257
58+
- name: Pre-download dependencies
59+
run: ./gradlew dependencies --parallel --configuration-cache
60+
5361
# ===========================
5462
# BUILD DEV RELEASE
5563
# ===========================
5664

5765
- name: Build Dev Release APK
5866
if: ${{ github.event.inputs.flavor == 'dev' || github.event.inputs.flavor == 'both' || github.event_name == 'push' }}
5967
run: |
60-
./gradlew assembleDevRelease --no-daemon --stacktrace
68+
./gradlew assembleDevRelease --parallel --build-cache --configuration-cache --stacktrace
6169
6270
- name: Upload Dev Release APK
6371
if: ${{ github.event.inputs.flavor == 'dev' || github.event.inputs.flavor == 'both' || github.event_name == 'push' }}
@@ -74,7 +82,7 @@ jobs:
7482
- name: Build Prod Release APK
7583
if: ${{ github.event.inputs.flavor == 'prod' || github.event.inputs.flavor == 'both' || github.event_name == 'push' }}
7684
run: |
77-
./gradlew assembleProdRelease --no-daemon --stacktrace
85+
./gradlew assembleProdRelease --parallel --build-cache --configuration-cache --stacktrace
7886
7987
- name: Upload Prod Release APK
8088
if: ${{ github.event.inputs.flavor == 'prod' || github.event.inputs.flavor == 'both' || github.event_name == 'push' }}

.github/workflows/ci.yml

Lines changed: 47 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ concurrency:
1313
cancel-in-progress: true
1414

1515
jobs:
16-
build:
17-
name: Build & Test
16+
build-and-test:
17+
name: Build, Test & Lint
1818
runs-on: ubuntu-latest
1919
timeout-minutes: 30
2020

@@ -27,7 +27,12 @@ jobs:
2727
with:
2828
java-version: '17'
2929
distribution: 'temurin'
30-
cache: 'gradle'
30+
31+
- name: Setup Gradle
32+
uses: gradle/actions/setup-gradle@v4
33+
with:
34+
cache-read-only: false
35+
gradle-home-cache-cleanup: true
3136

3237
- name: Grant execute permission for gradlew
3338
run: chmod +x gradlew
@@ -36,101 +41,67 @@ jobs:
3641
run: |
3742
echo "${{ secrets.GOOGLE_SERVICES_JSON }}" | base64 -d > app/google-services.json
3843
39-
- name: Build with Gradle
40-
run: ./gradlew build --no-daemon --stacktrace
44+
- name: Pre-download dependencies
45+
run: ./gradlew dependencies --parallel --configuration-cache
4146

42-
- name: Run unit tests
43-
run: ./gradlew test --no-daemon --stacktrace
47+
- name: Build, Test, Lint & Detekt
48+
run: ./gradlew build test detekt lint --parallel --build-cache --configuration-cache --stacktrace
4449

45-
- name: Run Detekt
46-
run: ./gradlew detekt --no-daemon --stacktrace
50+
- name: Assemble Debug APKs
51+
run: ./gradlew assembleDevDebug assembleProdDebug --parallel --build-cache --configuration-cache --stacktrace
4752

48-
- name: Upload build reports
49-
if: failure()
53+
- name: Assemble Release APKs
54+
run: ./gradlew assembleDevRelease assembleProdRelease --parallel --build-cache --configuration-cache --stacktrace
55+
56+
- name: Upload Dev Debug APK
57+
if: success()
5058
uses: actions/upload-artifact@v4
5159
with:
52-
name: build-reports
53-
path: |
54-
**/build/reports/
55-
**/build/test-results/
60+
name: dev-debug-apk
61+
path: app/build/outputs/apk/dev/debug/*.apk
5662
retention-days: 7
5763

58-
lint:
59-
name: Lint Check
60-
runs-on: ubuntu-latest
61-
timeout-minutes: 15
62-
63-
steps:
64-
- name: Checkout code
65-
uses: actions/checkout@v4
66-
67-
- name: Set up JDK 17
68-
uses: actions/setup-java@v4
69-
with:
70-
java-version: '17'
71-
distribution: 'temurin'
72-
cache: 'gradle'
73-
74-
- name: Grant execute permission for gradlew
75-
run: chmod +x gradlew
76-
77-
- name: Create google-services.json
78-
run: |
79-
echo "${{ secrets.GOOGLE_SERVICES_JSON }}" | base64 -d > app/google-services.json
80-
81-
- name: Run Android Lint
82-
run: ./gradlew lint --no-daemon --stacktrace
83-
84-
- name: Upload lint reports
85-
if: always()
64+
- name: Upload Prod Debug APK
65+
if: success()
8666
uses: actions/upload-artifact@v4
8767
with:
88-
name: lint-reports
89-
path: |
90-
**/build/reports/lint-results*.html
91-
**/build/reports/lint-results*.xml
68+
name: prod-debug-apk
69+
path: app/build/outputs/apk/prod/debug/*.apk
9270
retention-days: 7
9371

94-
assemble-release:
95-
name: Assemble Release Build
96-
runs-on: ubuntu-latest
97-
timeout-minutes: 20
98-
99-
steps:
100-
- name: Checkout code
101-
uses: actions/checkout@v4
102-
103-
- name: Set up JDK 17
104-
uses: actions/setup-java@v4
105-
with:
106-
java-version: '17'
107-
distribution: 'temurin'
108-
cache: 'gradle'
109-
110-
- name: Grant execute permission for gradlew
111-
run: chmod +x gradlew
112-
113-
- name: Create google-services.json
114-
run: |
115-
echo "${{ secrets.GOOGLE_SERVICES_JSON }}" | base64 -d > app/google-services.json
116-
117-
- name: Assemble Dev Release APK
118-
run: ./gradlew assembleDevRelease --no-daemon --stacktrace
119-
120-
- name: Assemble Prod Release APK
121-
run: ./gradlew assembleProdRelease --no-daemon --stacktrace
122-
12372
- name: Upload Dev Release APK
73+
if: success()
12474
uses: actions/upload-artifact@v4
12575
with:
12676
name: dev-release-apk
12777
path: app/build/outputs/apk/dev/release/*.apk
12878
retention-days: 14
12979

13080
- name: Upload Prod Release APK
81+
if: success()
13182
uses: actions/upload-artifact@v4
13283
with:
13384
name: prod-release-apk
13485
path: app/build/outputs/apk/prod/release/*.apk
13586
retention-days: 14
13687

88+
- name: Upload lint reports
89+
if: always()
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: lint-reports
93+
path: |
94+
**/build/reports/lint-results*.html
95+
**/build/reports/lint-results*.xml
96+
retention-days: 7
97+
98+
- name: Upload build reports
99+
if: failure()
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: build-reports
103+
path: |
104+
**/build/reports/
105+
**/build/test-results/
106+
retention-days: 7
107+

0 commit comments

Comments
 (0)