Skip to content

Commit 79274c4

Browse files
committed
Get version code from store
1 parent 0d0d7aa commit 79274c4

File tree

7 files changed

+124
-0
lines changed

7 files changed

+124
-0
lines changed

.github/actions/generate-version-code/action.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
name: Generate Version Code
22
description: Generates version code from GitHub run number
33

4+
inputs:
5+
official:
6+
type: boolean
7+
required: true
8+
os:
9+
type: string
10+
required: true
11+
FASTLANE_GOOGLE_SERVICE_ACCOUNT:
12+
type: string
13+
required: true
14+
APP_STORE_CONNECT_API_KEY_BASE64:
15+
type: string
16+
required: true
17+
418
outputs:
519
VERSIONCODE:
620
description: "Generated version code"
@@ -9,6 +23,46 @@ outputs:
923
runs:
1024
using: "composite"
1125
steps:
26+
- name: Set up Ruby and Bundler
27+
uses: ruby/setup-ruby@v1
28+
with:
29+
ruby-version: 2.7.7
30+
bundler-cache: true
31+
32+
- name: Install Fastlane
33+
if: ${{ inputs.os == 'android' }}
34+
working-directory: android
35+
run: |
36+
bundle install --path gems
37+
shell: bash
38+
39+
- name: Store the Google service account key
40+
if: ${{ inputs.os == 'android' }}
41+
working-directory: android
42+
run: |
43+
echo "${{ inputs.FASTLANE_GOOGLE_SERVICE_ACCOUNT }}" | base64 --decode > service_account.json
44+
shell: bash
45+
46+
- name: Decode p8
47+
if: ${{ inputs.os == 'ios' }}
48+
run: |
49+
echo ${{ inputs.APP_STORE_CONNECT_API_KEY_BASE64 }} | base64 --decode > ./ios/fastlane/app_store_connect_api_key.p8
50+
shell: bash
51+
52+
- name: Compute VERSIONCODE (iOS)
53+
if: ${{ inputs.os == 'ios' }}
54+
shell: bash
55+
run: |
56+
fastlane ios get_testflight_version
57+
working-directory: ios
58+
59+
- name: Compute VERSIONCODE (Android)
60+
if: ${{ inputs.os == 'android' }}
61+
shell: bash
62+
run: |
63+
fastlane android version_code
64+
working-directory: android
65+
1266
- name: Compute VERSIONCODE
1367
id: compute
1468
shell: bash

.github/workflows/build-android.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ jobs:
3737
- name: Generate Version Code
3838
id: version
3939
uses: ./.github/actions/generate-version-code
40+
with:
41+
official: false
42+
os: android
43+
FASTLANE_GOOGLE_SERVICE_ACCOUNT: ${{ secrets.FASTLANE_GOOGLE_SERVICE_ACCOUNT }}
4044

4145
- name: Build Android
4246
uses: ./.github/actions/build-android

.github/workflows/build-ios.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
- name: Generate Version Code
3636
id: version
3737
uses: ./.github/actions/generate-version-code
38+
with:
39+
official: false
40+
os: ios
41+
APP_STORE_CONNECT_API_KEY_BASE64: ${{ secrets.APP_STORE_CONNECT_API_KEY_BASE64 }}
3842

3943
- name: Build iOS
4044
uses: ./.github/actions/build-ios

.github/workflows/build-official-android.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ jobs:
3737
- name: Generate Version Code
3838
id: version
3939
uses: ./.github/actions/generate-version-code
40+
with:
41+
official: true
42+
os: android
43+
FASTLANE_GOOGLE_SERVICE_ACCOUNT: ${{ secrets.FASTLANE_GOOGLE_SERVICE_ACCOUNT }}
4044

4145
- name: Build Android
4246
uses: ./.github/actions/build-android

.github/workflows/build-official-ios.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
- name: Generate Version Code
3636
id: version
3737
uses: ./.github/actions/generate-version-code
38+
with:
39+
official: true
40+
os: ios
41+
APP_STORE_CONNECT_API_KEY_BASE64: ${{ secrets.APP_STORE_CONNECT_API_KEY_BASE64 }}
3842

3943
- name: Build iOS
4044
uses: ./.github/actions/build-ios

android/fastlane/Fastfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,44 @@
1616
default_platform(:android)
1717

1818
platform :android do
19+
desc 'Get the highest version code from all tracks'
20+
lane :version_code |options|
21+
production_versions = google_play_track_version_codes(
22+
package_name: options[:official] ? 'chat.rocket.android' : 'chat.rocket.reactnative',
23+
json_key: 'fastlane/play_store.json',
24+
track: 'production'
25+
)
26+
27+
beta_versions = google_play_track_version_codes(
28+
package_name: options[:official] ? 'chat.rocket.android' : 'chat.rocket.reactnative',
29+
json_key: 'fastlane/play_store.json',
30+
track: 'beta'
31+
)
32+
33+
alpha_versions = google_play_track_version_codes(
34+
package_name: options[:official] ? 'chat.rocket.android' : 'chat.rocket.reactnative',
35+
json_key: 'fastlane/play_store.json',
36+
track: 'alpha'
37+
)
38+
39+
internal_versions = google_play_track_version_codes(
40+
package_name: options[:official] ? 'chat.rocket.android' : 'chat.rocket.reactnative',
41+
json_key: 'fastlane/play_store.json',
42+
track: 'internal'
43+
)
44+
45+
all_versions = production_versions + beta_versions + alpha_versions + internal_versions
46+
highest_version = all_versions.max
47+
48+
UI.message("All: #{all_versions}")
49+
UI.success("Highest: #{highest_version}")
50+
UI.success("Highest + 1: #{highest_version + 1}")
51+
52+
next_version = highest_version + 1
53+
54+
puts next_version
55+
end
56+
1957
desc "Upload App to Play Store Internal (Circle CI)"
2058
lane :beta_circle_ci do |options|
2159
if options[:official]

ios/fastlane/Fastfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ platform :ios do
2525
)
2626
end
2727

28+
desc "Get testflight version"
29+
lane :get_testflight_version do |options|
30+
api_key = app_store_connect_api_key(
31+
key_id: ENV["APP_STORE_CONNECT_API_KEY_ID"],
32+
issuer_id: ENV["APP_STORE_CONNECT_API_KEY_ISSUER_ID"],
33+
key_filepath: 'fastlane/app_store_connect_api_key.p8',
34+
in_house: false
35+
)
36+
latest_version = latest_testflight_build_number(
37+
app_identifier: options[:official] ? 'chat.rocket.ios' : 'chat.rocket.reactnative'
38+
)
39+
40+
UI.message("Latest version: #{latest_version}")
41+
puts latest_version
42+
end
43+
2844
desc "Submit a new Beta Build to Apple TestFlight (Circle CI)"
2945
lane :beta_circle_ci do |options|
3046
api_key = app_store_connect_api_key(

0 commit comments

Comments
 (0)