Skip to content

Commit 37c2408

Browse files
committed
build: split build and deploy for flipcash to optimize CI
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 7ddfdcd commit 37c2408

2 files changed

Lines changed: 121 additions & 65 deletions

File tree

.github/workflows/build-fcash-upload-android.yml

Lines changed: 111 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ env:
44
main_project_module: apps:flipcash:app
55
playstore_name: Flipcash
66

7+
# Cancel in-progress workflow runs if a job fails
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.inputs.track }}-${{ github.event.inputs.release_status }}
10+
cancel-in-progress: true
11+
712
on:
813
workflow_dispatch:
914
inputs:
@@ -83,22 +88,26 @@ jobs:
8388
fileDir: ./apps/flipcash/app/key
8489
encodedString: ${{ secrets.UPLOAD_KEY_STORE }}
8590

86-
- name: Setup BugSnag API Key
87-
run: echo BUGSNAG_API_KEY=\"${{ secrets.FLIPCASH_BUGSNAG_API_KEY }}\" > ./local.properties
88-
89-
- name: Setup Google Cloud Project Number
90-
run: echo GOOGLE_CLOUD_PROJECT_NUMBER=${{ secrets.GOOGLE_CLOUD_PROJECT_NUMBER }} >> ./local.properties
91-
92-
- name: Setup Mixpanel API Key
93-
run: echo MIXPANEL_API_KEY=\"${{ secrets.FLIPCASH_MIXPANEL_API_KEY }}\" >> ./local.properties
94-
9591
- name: Cache Gradle
9692
uses: actions/cache@v3
9793
with:
98-
path: ~/.gradle/caches
99-
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties') }}
94+
path: |
95+
~/.gradle/caches
96+
~/.gradle/wrapper
97+
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties', '**/gradle/wrapper/*') }}
10098
restore-keys: gradle-
10199

100+
- name: Upload Setup Artifacts
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: setup-files
104+
path: |
105+
${{ steps.google_services_json_file.outputs.filePath }}
106+
${{ steps.service_account_json_file.outputs.filePath }}
107+
${{ steps.signing_key.outputs.filePath }}
108+
code-android-app/apps/flipcash/app/key/key
109+
if-no-files-found: error
110+
102111
tests:
103112
needs: setup
104113
runs-on: ubuntu-latest
@@ -107,74 +116,129 @@ jobs:
107116
with:
108117
fetch-depth: 0
109118

119+
- name: Setup Ruby env
120+
uses: ruby/setup-ruby@v1
121+
with:
122+
ruby-version: 2.7.2
123+
bundler-cache: true
124+
110125
- name: Restore Gradle Cache
111126
uses: actions/cache/restore@v3
112127
with:
113-
path: ~/.gradle/caches
114-
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties') }}
128+
path: |
129+
~/.gradle/caches
130+
~/.gradle/wrapper
131+
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties', '**/gradle/wrapper/*') }}
115132
restore-keys: gradle-
116133

134+
- name: Download Setup Artifacts
135+
uses: actions/download-artifact@v4
136+
with:
137+
name: setup-files
138+
path: setup-files/
139+
117140
- name: Copy Setup Files
118141
run: |
119142
mkdir -p ./apps/flipcash/app/src
120-
mkdir -p ./key
121-
mkdir -p ./apps/flipcash/app/key
122-
cp ${{ needs.setup.outputs.google_services_json }} ./apps/flipcash/app/src/google-services.json
123-
cp ${{ needs.setup.outputs.service_account_json }} ./serviceAccount.json
124-
cp ${{ needs.setup.outputs.signing_key }} ./key/key
125-
cp ${{ needs.setup.outputs.signing_key }} ./apps/flipcash/app/key/key
126-
echo BUGSNAG_API_KEY=\"${{ secrets.FLIPCASH_BUGSNAG_API_KEY }}\" > ./local.properties
127-
echo GOOGLE_CLOUD_PROJECT_NUMBER=${{ secrets.GOOGLE_CLOUD_PROJECT_NUMBER }} >> ./local.properties
128-
echo MIXPANEL_API_KEY=\"${{ secrets.FLIPCASH_MIXPANEL_API_KEY }}\" >> ./local.properties
143+
cp ./setup-files/code-android-app/apps/flipcash/app/src/google-services.json ./apps/flipcash/app/src/google-services.json || echo "Failed to copy google-services.json"
144+
145+
146+
- name: Setup local.properties
147+
id: local_properties
148+
run: |
149+
cat << EOF > ./local.properties
150+
BUGSNAG_API_KEY="${{ secrets.FLIPCASH_BUGSNAG_API_KEY }}"
151+
GOOGLE_CLOUD_PROJECT_NUMBER=${{ secrets.GOOGLE_CLOUD_PROJECT_NUMBER }}
152+
MIXPANEL_API_KEY="${{ secrets.FLIPCASH_MIXPANEL_API_KEY }}"
153+
EOF
129154
130155
- name: Run tests
131156
run: bundle exec fastlane android flipcash_tests
132157

133-
deploy:
158+
build:
134159
needs: setup
135160
runs-on: ubuntu-latest
136161
steps:
137162
- uses: actions/checkout@v4
138163
with:
139164
fetch-depth: 0
140165

166+
- name: Setup Ruby env
167+
uses: ruby/setup-ruby@v1
168+
with:
169+
ruby-version: 2.7.2
170+
bundler-cache: true
171+
141172
- name: Restore Gradle Cache
142173
uses: actions/cache/restore@v3
143174
with:
144-
path: ~/.gradle/caches
145-
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties') }}
175+
path: |
176+
~/.gradle/caches
177+
~/.gradle/wrapper
178+
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties', '**/gradle/wrapper/*') }}
146179
restore-keys: gradle-
147180

181+
- name: Download Setup Artifacts
182+
uses: actions/download-artifact@v4
183+
with:
184+
name: setup-files
185+
path: setup-files/
186+
148187
- name: Copy Setup Files
149188
run: |
150189
mkdir -p ./apps/flipcash/app/src
151-
mkdir -p ./key
152-
mkdir -p ./apps/flipcash/app/key
153-
cp ${{ needs.setup.outputs.google_services_json }} ./apps/flipcash/app/src/google-services.json
154-
cp ${{ needs.setup.outputs.service_account_json }} ./serviceAccount.json
155-
cp ${{ needs.setup.outputs.signing_key }} ./key/key
156-
cp ${{ needs.setup.outputs.signing_key }} ./apps/flipcash/app/key/key
157-
echo BUGSNAG_API_KEY=\"${{ secrets.FLIPCASH_BUGSNAG_API_KEY }}\" > ./local.properties
158-
echo GOOGLE_CLOUD_PROJECT_NUMBER=${{ secrets.GOOGLE_CLOUD_PROJECT_NUMBER }} >> ./local.properties
159-
echo MIXPANEL_API_KEY=\"${{ secrets.FLIPCASH_MIXPANEL_API_KEY }}\" >> ./local.properties
160-
161-
- name: Build & deploy Android release
162-
run: bundle exec fastlane android deploy_flipcash
190+
cp ./setup-files/code-android-app/apps/flipcash/app/src/google-services.json ./apps/flipcash/app/src/google-services.json || echo "Failed to copy google-services.json"
191+
192+
- name: Setup local.properties
193+
id: local_properties
194+
run: |
195+
cat << EOF > ./local.properties
196+
BUGSNAG_API_KEY="${{ secrets.FLIPCASH_BUGSNAG_API_KEY }}"
197+
GOOGLE_CLOUD_PROJECT_NUMBER=${{ secrets.GOOGLE_CLOUD_PROJECT_NUMBER }}
198+
MIXPANEL_API_KEY="${{ secrets.FLIPCASH_MIXPANEL_API_KEY }}"
199+
EOF
200+
201+
- name: Build Android release
202+
run: bundle exec fastlane android build_flipcash
163203
env:
164-
STORE_FILE: ${{ needs.setup.outputs.signing_key }}
204+
STORE_FILE: ${{ needs.setup.outputs.signing_key.outputs.filePath }}
165205
STORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
166206
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
167207
KEY_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
168-
SERVICE_ACCOUNT_KEY_JSON: ${{ needs.setup.outputs.service_account_json }}
169-
PACKAGE_NAME: com.flipcash.android.app
170-
PLAYSTORE_TRACK: ${{ github.event.inputs.track }}
171-
RELEASE_STATUS: ${{ github.event.inputs.release_status }}
172208

173-
- name: Upload build artifacts
209+
- name: Upload Build Artifacts
174210
uses: actions/upload-artifact@v4
175-
if: always()
176211
with:
177-
name: assets
212+
name: build-assets
178213
path: |
179-
${{ github.workspace }}/apps/flipcash/app/build/outputs/bundle/release
180-
${{ github.workspace }}/apps/flipcash/app/build/outputs/apk/release
214+
${{ github.workspace }}/artifacts/*.aab
215+
${{ github.workspace }}/artifacts/*.txt
216+
if-no-files-found: error
217+
218+
deploy:
219+
needs: [tests, build]
220+
runs-on: ubuntu-latest
221+
steps:
222+
- uses: actions/checkout@v4
223+
with:
224+
fetch-depth: 0
225+
226+
- name: Setup Ruby env
227+
uses: ruby/setup-ruby@v1
228+
with:
229+
ruby-version: 2.7.2
230+
bundler-cache: true
231+
232+
- name: Download Build Artifacts
233+
uses: actions/download-artifact@v4
234+
with:
235+
name: build-assets
236+
path: artifacts/
237+
238+
- name: Deploy to Play Store
239+
run: bundle exec fastlane android deploy_to_play_store
240+
env:
241+
SERVICE_ACCOUNT_KEY_JSON: ${{ needs.setup.outputs.service_account_json_file.outputs.filePath }}
242+
PACKAGE_NAME: com.flipcash.android.app
243+
PLAYSTORE_TRACK: ${{ github.event.inputs.track }}
244+
RELEASE_STATUS: ${{ github.event.inputs.release_status }}

fastlane/Fastfile

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,45 +114,37 @@ platform :android do
114114
)
115115
end
116116

117-
desc "Build and Deploy a new version of Flipcash to the Google Play Store"
118-
lane :deploy_flipcash do
117+
desc "Build a new version of Flipcash"
118+
lane :build_flipcash do
119119
gradle(
120-
task: "clean apps:flipcash:app:bundle", #"clean app:bundleRelease",
120+
task: "clean apps:flipcash:app:bundle",
121121
build_type: "release",
122122
properties: {
123-
#"versionPatch" => ENV["BUILD_NUMBER"],
124123
"android.injected.signing.store.file" => ENV["STORE_FILE"],
125124
"android.injected.signing.store.password" => ENV["STORE_PASSWORD"],
126125
"android.injected.signing.key.alias" => ENV["KEY_ALIAS"],
127126
"android.injected.signing.key.password" => ENV["KEY_PASSWORD"]
128127
}
129128
)
130129

131-
bundletool(
132-
ks_path: ENV["STORE_FILE"],
133-
ks_password: ENV["STORE_PASSWORD"],
134-
ks_key_alias: ENV["KEY_ALIAS"],
135-
ks_key_alias_password: ENV["KEY_PASSWORD"],
136-
bundletool_version: '1.10.0',
137-
aab_path: Actions.lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH],
138-
apk_output_path: "apps/flipcash/app/build/outputs/apk/release",
139-
verbose: true,
140-
)
130+
sh("mkdir -p ../artifacts && cp #{Actions.lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]} ../artifacts/")
131+
sh("cp #{Actions.lane_context[SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH]} ../artifacts/") if File.exist?(Actions.lane_context[SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH])
132+
end
141133

134+
desc "Deploy a new version of Flipcash to the Google Play Store"
135+
lane :deploy_to_play_store do
142136
validate_play_store_json_key(
143137
json_key: ENV["SERVICE_ACCOUNT_KEY_JSON"]
144138
)
145-
146139
upload_to_play_store(
147140
track: ENV["PLAYSTORE_TRACK"],
148141
release_status: ENV["RELEASE_STATUS"],
149-
aab: Actions.lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH],
142+
aab: "../artifacts/#{File.basename(Actions.lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])}",
150143
skip_upload_apk: true,
151144
skip_upload_changelogs: true,
152145
skip_upload_images: true,
153146
package_name: ENV["PACKAGE_NAME"],
154-
mapping: Actions.lane_context[SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH]
155-
# mapping: mapping_file_exists() ? Actions.lane_context[SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH] : nil
147+
mapping: File.exist?("../artifacts/#{File.basename(Actions.lane_context[SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH])}") ? "../artifacts/#{File.basename(Actions.lane_context[SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH])}" : nil
156148
)
157149
end
158150
end

0 commit comments

Comments
 (0)