Skip to content

Commit 9f2f530

Browse files
committed
refactor: Improve GitHub Actions workflow for Android builds
This commit refactors the Android build workflow in `.github/workflows/android.yml` with the following improvements: - **Secrets Handling:** - Secrets (keystore and Google Play JSON) are now downloaded as artifacts in the `build` job instead of being decoded in each job. This reduces redundancy and improves security by minimizing exposure of secrets. - The `setup` job now uploads secrets as artifacts. - **Dependency on `setup`:** - The `unit-test` and `code-analysis` jobs now explicitly depend on the `setup` job, ensuring secrets are available before these jobs run. - **Workflow Optimization:** - Added `fetch-depth: 1` and `persist-credentials: false` to `actions/checkout@v3` for faster checkouts and improved security. - Renamed "Setup Ruby" step to "Setup Ruby & Dependencies" for clarity. - **Path Correction:** - Corrected the path for `KEYSTORE_FILE` in `local.properties` to point to the root level where it's downloaded. - **Cleanup:** - Removed debugging steps for `ls -la app` and `cat local.properties`.
1 parent 8f2babc commit 9f2f530

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

.github/workflows/android.yml

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
steps:
2424
- name: Checkout Repository
2525
uses: actions/checkout@v3
26+
with:
27+
fetch-depth: 1
28+
persist-credentials: false
2629

2730
- name: Setup JDK 17
2831
uses: actions/setup-java@v3
@@ -33,7 +36,7 @@ jobs:
3336
- name: Setup Android SDK
3437
uses: android-actions/setup-android@v3
3538

36-
- name: Setup Ruby
39+
- name: Setup Ruby & Dependencies
3740
uses: ruby/setup-ruby@v1
3841
with:
3942
ruby-version: '3.1'
@@ -51,12 +54,20 @@ jobs:
5154
bundle install
5255
5356
- name: Decode Keystore File
54-
run: echo "${{ secrets.KEYSTORE_FILE }}" | base64 -d > app/${{ env.KEYSTORE_FILE }}
57+
run: echo "${{ secrets.KEYSTORE_FILE }}" | base64 -d > ${{ env.KEYSTORE_FILE }}
5558

5659
- name: Create Google Service Account JSON
5760
run: |
5861
mkdir -p app
59-
echo "${{ secrets.GOOGLE_PLAY_JSON }}" | base64 --decode > ${{ env.GOOGLE_PLAY_JSON_PATH }}
62+
echo "${{ secrets.GOOGLE_PLAY_JSON }}" | base64 -d > ${{ env.GOOGLE_PLAY_JSON_PATH }}
63+
64+
- name: Upload Secrets
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: secrets
68+
path: |
69+
${{ env.KEYSTORE_FILE }}
70+
${{ env.GOOGLE_PLAY_JSON_PATH }}
6071
6172
build:
6273
name: Build AAB
@@ -65,14 +76,17 @@ jobs:
6576

6677
steps:
6778
- uses: actions/checkout@v3
79+
with:
80+
fetch-depth: 1
81+
persist-credentials: false
6882

6983
- name: Setup JDK 17
7084
uses: actions/setup-java@v3
7185
with:
7286
java-version: '17'
7387
distribution: 'temurin'
7488

75-
- name: Setup Ruby
89+
- name: Setup Ruby & Dependencies
7690
uses: ruby/setup-ruby@v1
7791
with:
7892
ruby-version: '3.1'
@@ -89,27 +103,18 @@ jobs:
89103
bundle config set path 'vendor/bundle'
90104
bundle install
91105
92-
- name: Decode Keystore File
93-
run: echo "${{ secrets.KEYSTORE_FILE }}" | base64 -d > app/${{ env.KEYSTORE_FILE }}
94-
95-
- name: Debug keystore file
96-
run: ls -la app
106+
- name: Download Secrets
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: secrets
97110

98111
- name: Write local.properties
99112
run: |
100113
echo "sdk.dir=$ANDROID_HOME" > local.properties
101-
echo "KEYSTORE_FILE=app/${{ env.KEYSTORE_FILE }}" >> local.properties
114+
echo "KEYSTORE_FILE=${{ env.KEYSTORE_FILE }}" >> local.properties
102115
echo "KEYSTORE_PASSWORD=${{ env.KEYSTORE_PASSWORD }}" >> local.properties
103116
echo "KEY_ALIAS=${{ env.KEY_ALIAS }}" >> local.properties
104117
echo "KEY_PASSWORD=${{ env.KEY_PASSWORD }}" >> local.properties
105-
106-
- name: Debug local.properties
107-
run: cat local.properties
108-
109-
- name: Create Google Service Account JSON
110-
run: |
111-
mkdir -p app
112-
echo "${{ secrets.GOOGLE_PLAY_JSON }}" | base64 --decode > ${{ env.GOOGLE_PLAY_JSON_PATH }}
113118
114119
- name: Grant execute permission for gradlew
115120
run: chmod +x ./gradlew
@@ -125,10 +130,12 @@ jobs:
125130
unit-test:
126131
name: Unit Tests
127132
runs-on: ubuntu-latest
128-
needs: build
133+
needs: setup
129134

130135
steps:
131136
- uses: actions/checkout@v3
137+
with:
138+
fetch-depth: 1
132139

133140
- uses: ruby/setup-ruby@v1
134141
with:
@@ -149,10 +156,12 @@ jobs:
149156
code-analysis:
150157
name: Lint & Check
151158
runs-on: ubuntu-latest
152-
needs: build
159+
needs: setup
153160

154161
steps:
155162
- uses: actions/checkout@v3
163+
with:
164+
fetch-depth: 1
156165

157166
- uses: actions/setup-java@v3
158167
with:
@@ -177,17 +186,23 @@ jobs:
177186

178187
steps:
179188
- uses: actions/checkout@v3
189+
with:
190+
fetch-depth: 1
191+
180192
- uses: ruby/setup-ruby@v1
181193
with:
182194
ruby-version: '3.1'
183195
bundler-cache: true
196+
184197
- uses: actions/cache@v4
185198
with:
186199
path: vendor/bundle
187200
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
201+
188202
- run: |
189203
bundle config set path 'vendor/bundle'
190204
bundle install
205+
191206
- run: bundle exec fastlane deployRelease
192207

193208
deploy-beta:
@@ -198,17 +213,23 @@ jobs:
198213

199214
steps:
200215
- uses: actions/checkout@v3
216+
with:
217+
fetch-depth: 1
218+
201219
- uses: ruby/setup-ruby@v1
202220
with:
203221
ruby-version: '3.1'
204222
bundler-cache: true
223+
205224
- uses: actions/cache@v4
206225
with:
207226
path: vendor/bundle
208227
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
228+
209229
- run: |
210230
bundle config set path 'vendor/bundle'
211231
bundle install
232+
212233
- run: bundle exec fastlane deployBeta
213234

214235
deploy-firebase-internal:
@@ -219,15 +240,21 @@ jobs:
219240

220241
steps:
221242
- uses: actions/checkout@v3
243+
with:
244+
fetch-depth: 1
245+
222246
- uses: ruby/setup-ruby@v1
223247
with:
224248
ruby-version: '3.1'
225249
bundler-cache: true
250+
226251
- uses: actions/cache@v4
227252
with:
228253
path: vendor/bundle
229254
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
255+
230256
- run: |
231257
bundle config set path 'vendor/bundle'
232258
bundle install
259+
233260
- run: bundle exec fastlane deployFirebase --verbose

0 commit comments

Comments
 (0)