Skip to content

Commit f47a849

Browse files
committed
ci: fetch versionCode in seperate job
1 parent 65f9b2c commit f47a849

File tree

3 files changed

+69
-37
lines changed

3 files changed

+69
-37
lines changed

.github/workflows/build.yml

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,53 @@ jobs:
8282
run: |
8383
test -e mobile/src/main/jniLibs/x86_64/libaw_server.so
8484
85+
# This needs to be a seperate job since fastlane update_version,
86+
# fails if run concurrently (such as in build apk/aab matrix),
87+
# thus we need to run it once and and reuse the results.
88+
# https://github.com/fastlane/fastlane/issues/13689#issuecomment-439217502
89+
get-versionCode:
90+
name: Get latest versionCode
91+
runs-on: ubuntu-latest
92+
outputs:
93+
versionCode: ${{ steps.versionCode.outputs.versionCode }}
94+
95+
steps:
96+
- uses: actions/checkout@v2
97+
with:
98+
submodules: 'recursive'
99+
100+
101+
# Ruby & Fastlane
102+
# version set by .ruby-version
103+
- name: Set up Ruby and install fastlane
104+
uses: ruby/setup-ruby@v1
105+
with:
106+
bundler-cache: true
107+
108+
# Needed for `fastlane update_version`
109+
- uses: adnsio/[email protected]
110+
- name: Load Fastlane secrets
111+
env:
112+
KEY_FASTLANE_API: ${{ secrets.KEY_FASTLANE_API }}
113+
run: |
114+
printf "$KEY_FASTLANE_API" > fastlane/api-8546008605074111507-287154-450dc77b365f.json.key
115+
cat fastlane/api-8546008605074111507-287154-450dc77b365f.json.age \
116+
| age -d -i fastlane/api-8546008605074111507-287154-450dc77b365f.json.key \
117+
-o fastlane/api-8546008605074111507-287154-450dc77b365f.json
118+
rm fastlane/api-8546008605074111507-287154-450dc77b365f.json.key
119+
120+
- name: Update versionCode
121+
run: bundle exec fastlane update_version
122+
123+
- name: Output versionCode
124+
id: versionCode
125+
run: |
126+
cat mobile/build.gradle | grep versionCode | sed 's/.*\s\([0-9]*\)$/versionCode=\1/' >> "$GITHUB_OUTPUT"
85127
86128
build-apk:
87129
name: Build ${{ matrix.type }}
88130
runs-on: ubuntu-20.04
89-
needs: [build-rust]
90-
env:
91-
SUPPLY_TRACK: production # used by fastlane to determine track to publish to
131+
needs: [build-rust, get-versionCode]
92132
strategy:
93133
fail-fast: true
94134
matrix:
@@ -108,19 +148,11 @@ jobs:
108148
run: |
109149
echo "${{ steps.version.outputs.full }} (stable: ${{ steps.version.outputs.is_stable }})"
110150
111-
- name: Set RELEASE and SUPPLY_TRACK
151+
- name: Set RELEASE
112152
run: |
113153
# Build in release mode if on a tag/release (longer build times)
114154
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
115155
116-
# Set SUPPLY_TRACK (used by fastlane) depending on is_stable
117-
if [[ "${{ steps.version.outputs.is_stable }}" == "true" ]]; then
118-
SUPPLY_TRACK="production"
119-
else
120-
SUPPLY_TRACK="internal"
121-
fi
122-
echo "SUPPLY_TRACK=${SUPPLY_TRACK}" >> $GITHUB_ENV
123-
124156
- name: Set up JDK
125157
uses: actions/setup-java@v1
126158
with:
@@ -136,16 +168,6 @@ jobs:
136168
ls $ANDROID_NDK_HOME
137169
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
138170
139-
# Ruby & Fastlane
140-
# version set by .ruby-version
141-
- name: Set up Ruby and install fastlane
142-
uses: ruby/setup-ruby@v1
143-
with:
144-
bundler-cache: true
145-
146-
- name: Install age
147-
uses: adnsio/[email protected]
148-
149171
# Restores jniLibs from cache
150172
# `actions/cache/restore` only restores, without saving back in a post-hook
151173
- uses: actions/cache/restore@v3
@@ -161,28 +183,21 @@ jobs:
161183
run: |
162184
test -e mobile/src/main/jniLibs/x86_64/libaw_server.so
163185
164-
# Needed for `fastlane update_version`
165-
- name: Load Fastlane secrets
166-
env:
167-
KEY_FASTLANE_API: ${{ secrets.KEY_FASTLANE_API }}
168-
run: |
169-
printf "$KEY_FASTLANE_API" > fastlane/api-8546008605074111507-287154-450dc77b365f.json.key
170-
cat fastlane/api-8546008605074111507-287154-450dc77b365f.json.age \
171-
| age -d -i fastlane/api-8546008605074111507-287154-450dc77b365f.json.key \
172-
-o fastlane/api-8546008605074111507-287154-450dc77b365f.json
173-
rm fastlane/api-8546008605074111507-287154-450dc77b365f.json.key
174-
175-
- name: Set version
186+
- name: Set versionName
176187
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
177188
run: |
178189
# Sets versionName, tail used to skip "v" at start of tag name
179190
SHORT_VERSION=$(echo "${{ github.ref_name }}" | tail -c +2 -)
180191
sed -i "s/versionName \".*\"/versionName \"$SHORT_VERSION\"/g" \
181192
mobile/build.gradle
182193
183-
- name: Update versionCode
184-
run: bundle exec fastlane update_version
194+
- name: Set versionCode
195+
run: |
196+
# Sets versionCode
197+
sed -i "s/versionCode .*/versionCode ${{needs.get-versionCode.outputs.versionCode}}" \
198+
mobile/build.gradle
185199
200+
- uses: adnsio/[email protected]
186201
- name: Load Android secrets
187202
if: env.KEY_ANDROID_JKS != null
188203
env:
@@ -496,7 +511,7 @@ jobs:
496511
echo "SUPPLY_TRACK=${SUPPLY_TRACK}" >> $GITHUB_ENV
497512
498513
- uses: adnsio/[email protected]
499-
- name: Load secrets
514+
- name: Load Android secrets
500515
env:
501516
KEY_FASTLANE_API: ${{ secrets.KEY_FASTLANE_API }}
502517
run: |

fastlane/Fastfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ platform :android do
4545
)
4646
end
4747

48+
desc "Set versionCode to a specific value"
49+
lane :set_version do |options|
50+
version = options[:version]
51+
increment_version_code(
52+
gradle_file_path: "mobile/build.gradle",
53+
version_code: version
54+
)
55+
end
56+
4857
desc "Deploy a new version to the Google Play"
4958
lane :deploy do
5059
gradle(task: "clean assembleRelease")

fastlane/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Build a new Beta build
3939

4040
Update versionCode to be one higher than the latest on Play Store
4141

42+
### android set_version
43+
44+
```sh
45+
[bundle exec] fastlane android set_version
46+
```
47+
48+
Set versionCode to a specific value
49+
4250
### android deploy
4351

4452
```sh

0 commit comments

Comments
 (0)