Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 9635bd9

Browse files
authored
[BWA-33]: Publish release bundles to Play Store when requested (#303)
1 parent 8dd9ba6 commit 9635bd9

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ jobs:
138138
az storage blob download --account-name $ACCOUNT_NAME --container-name $CONTAINER_NAME \
139139
--name authenticator_play_firebase-creds.json --file ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json --output none
140140
141+
- name: Download Play Store credentials
142+
if: ${{ inputs.publish-to-play-store }}
143+
env:
144+
ACCOUNT_NAME: bitwardenci
145+
CONTAINER_NAME: mobile
146+
run: |
147+
mkdir -p ${{ github.workspace }}/secrets
148+
149+
az storage blob download --account-name $ACCOUNT_NAME --container-name $CONTAINER_NAME \
150+
--name authenticator_play_store-creds.json --file ${{ github.workspace }}/secrets/authenticator_play_store-creds.json --output none
151+
152+
- name: Verify Play Store credentials
153+
if: ${{ inputs.publish-to-play-store }}
154+
run: |
155+
bundle exec fastlane run validate_play_store_json_key
156+
141157
- name: Validate Gradle wrapper
142158
uses: gradle/actions/wrapper-validation@cc4fc85e6b35bafd578d5ffbc76a5518407e1af0 # v4.2.1
143159

@@ -167,14 +183,19 @@ jobs:
167183
java-version: ${{ env.JAVA_VERSION }}
168184

169185
- name: Increment version
170-
env:
171-
FIREBASE_CREDS_PATH: ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json
172186
run: |
173187
DEFAULT_VERSION_CODE=$GITHUB_RUN_NUMBER
188+
VERSION_CODE="${{ inputs.version-code || '$DEFAULT_VERSION_CODE' }}"
174189
bundle exec fastlane setBuildVersionInfo \
175-
serviceCredentialsFile:${{ env.FIREBASE_CREDS_PATH }} \
176-
versionCode:${{ inputs.version-code || '$DEFAULT_VERSION_CODE' }} \
177-
versionName:${{ inputs.version-name }}
190+
versionCode:$VERSION_CODE \
191+
versionName:${{ inputs.version-name || '' }}
192+
193+
regex='versionName = "([^"]+)"'
194+
if [[ "$(cat app/build.gradle.kts)" =~ $regex ]]; then
195+
VERSION_NAME="${BASH_REMATCH[1]}"
196+
fi
197+
echo "Version Name: ${VERSION_NAME}" >> $GITHUB_STEP_SUMMARY
198+
echo "Version Number: $VERSION_CODE" >> $GITHUB_STEP_SUMMARY
178199
179200
- name: Generate release Play Store bundle
180201
if: ${{ matrix.variant == 'aab' }}
@@ -255,7 +276,7 @@ jobs:
255276
- name: Publish release bundle to Google Play Store
256277
if: ${{ inputs.publish-to-play-store && matrix.variant == 'aab' }}
257278
env:
258-
PLAY_STORE_CREDS_FILE: ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json
279+
PLAY_STORE_CREDS_FILE: ${{ github.workspace }}/secrets/authenticator_play_store-creds.json
259280
run: |
260281
bundle exec fastlane publishReleaseToGooglePlayStore \
261282
serviceCredentialsFile:${{ env.PLAY_STORE_CREDS_FILE }} \

fastlane/Appfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
json_key_file("secrets/authenticator_play_store-creds.json")
12
package_name("com.bitwarden.authenticator")

fastlane/Fastfile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,37 @@ platform :android do
3232
buildConfigText = buildConfigFile.read
3333
buildConfigFile.close
3434

35+
currentVersionCode = buildConfigText.match(/versionCode = (\d+)/).captures[0]
36+
currentVersionName = buildConfigText.match(/versionName = "(.+)"/).captures[0]
37+
3538
if options[:versionName].nil? or options[:versionName].to_s.empty?
36-
# Use the latest version name in Firebase as the default version name.
37-
latestRelease = firebase_app_distribution_get_latest_release(
38-
app: "1:867301491091:android:50b626dba42a361651e866",
39-
service_credentials_file:options[:serviceCredentialsFile]
40-
)
41-
nextVersionName = latestRelease[:displayVersion]
39+
puts "Fetching latest tags from origin..."
40+
`git fetch --prune --no-recurse-submodules --filter=tree:0 --depth=1 --tags origin`
41+
puts "Getting latest version name from previous git tag..."
42+
latestTag = `git describe --tags $(git rev-list --tags --max-count=1)`.chomp()
43+
puts "Using tag #{latestTag} to calculate version name..."
44+
latestTag.slice!(0)
45+
puts "Current version name resolved to #{latestTag}."
46+
47+
versionParts = latestTag.split(".")
48+
currentMajor = versionParts[0]
49+
currentMinor = versionParts[1]
50+
currentRevision = versionParts[2]
51+
52+
currentDate = Time.new
53+
major = currentDate.year.to_s
54+
minor = currentDate.strftime "%-m"
55+
56+
revision = 0
57+
if currentMajor == major and currentMinor == minor
58+
revision = currentRevision.to_i + 1
59+
end
60+
nextVersionName = "#{major}.#{minor}.#{revision}"
4261
else
4362
nextVersionName = options[:versionName].to_s
4463
end
4564

4665
# Replace version information.
47-
currentVersionCode = buildConfigText.match(/versionCode = (\d+)/).captures[0]
48-
currentVersionName = buildConfigText.match(/versionName = "(.+)"/).captures[0]
4966
puts "Setting version code to #{options[:versionCode]}."
5067
buildConfigText.gsub!("versionCode = #{currentVersionCode}", "versionCode = #{options[:versionCode]}")
5168
puts "Setting version name to #{nextVersionName}."

0 commit comments

Comments
 (0)