[BWA-12] Update workflow to accept custom inputs (#96)

This commit is contained in:
Patrick Honkonen 2024-05-17 10:57:00 -04:00 committed by GitHub
parent 2529ed3fb9
commit 6fae5b8b77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 42 deletions

View File

@ -9,6 +9,20 @@ on:
paths-ignore: paths-ignore:
- ".github/workflows/**" - ".github/workflows/**"
workflow_dispatch: workflow_dispatch:
inputs:
version-name:
description: 'Optional. Version string to use, in X.Y.Z format. Overrides default in the project.'
required: false
type: string
version-code:
description: 'Optional. Build number to use. Overrides default of GitHub run number.'
required: false
type: number
publish-to-play-store:
description: 'Optional. Deploy bundle artifact to Google Play Store'
required: false
default: false
type: boolean
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@ -164,8 +178,11 @@ jobs:
env: env:
FIREBASE_CREDS_PATH: ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json FIREBASE_CREDS_PATH: ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json
run: | run: |
DEFAULT_VERSION_CODE=$GITHUB_RUN_NUMBER
bundle exec fastlane setBuildVersionInfo \ bundle exec fastlane setBuildVersionInfo \
serviceCredentialsFile:${{ env.FIREBASE_CREDS_PATH }} serviceCredentialsFile:${{ env.FIREBASE_CREDS_PATH }} \
versionCode:${{ inputs.version-code || '$DEFAULT_VERSION_CODE' }} \
versionName:${{ inputs.version-name }}
shell: bash shell: bash
- name: Assemble Release APK - name: Assemble Release APK
@ -204,7 +221,7 @@ jobs:
if: ${{ github.ref_name == 'main' }} if: ${{ github.ref_name == 'main' }}
run: bundle exec fastlane add_plugin firebase_app_distribution run: bundle exec fastlane add_plugin firebase_app_distribution
- name: Publish release APK to Firebase - name: Distribute release APK to Firebase
if: ${{ github.ref_name == 'main' && matrix.variant == 'apk' }} if: ${{ github.ref_name == 'main' && matrix.variant == 'apk' }}
env: env:
FIREBASE_CREDS_PATH: ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json FIREBASE_CREDS_PATH: ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json
@ -255,11 +272,13 @@ jobs:
serviceCredentialsFile:${{ env.FIREBASE_CREDS_PATH }} serviceCredentialsFile:${{ env.FIREBASE_CREDS_PATH }}
shell: bash shell: bash
# - name: Publish release AAB to Google Play Store # Only publish bundles to Play Store when `publish-to-play-store` is true while building
# if: ${{ github.ref_name == 'main' && matrix.variant == 'aab'}} # bundles
# env: - name: Publish release AAB to Google Play Store
# PLAY_STORE_CREDS_FILE: ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json if: ${{ inputs.publish-to-play-store && matrix.variant == 'aab' }}
# run: | env:
# bundle exec fastlane publishReleaseToGooglePlayStore \ PLAY_STORE_CREDS_FILE: ${{ github.workspace }}/secrets/authenticator_play_firebase-creds.json
# serviceCredentialsFile:${{ env.PLAY_STORE_CREDS_FILE }} \ run: |
# shell: bash bundle exec fastlane publishReleaseToGooglePlayStore \
serviceCredentialsFile:${{ env.PLAY_STORE_CREDS_FILE }} \
shell: bash

View File

@ -26,45 +26,30 @@ platform :android do
fastlane_require "time" fastlane_require "time"
lane :setBuildVersionInfo do |options| lane :setBuildVersionInfo do |options|
latestRelease = firebase_app_distribution_get_latest_release( # Read-in app build config file.
app: "1:867301491091:android:50b626dba42a361651e866",
service_credentials_file:options[:serviceCredentialsFile]
)
currentVersionName = latestRelease[:displayVersion]
# Gather current version information
versionParts = currentVersionName.split(".")
currentMajor = versionParts[0]
currentMinor = versionParts[1]
currentRevision = versionParts[2]
# Current date used to derive next version name.
currentDate = Time.new
major = currentDate.year.to_s
minor = currentDate.strftime "%m"
# Determine the next revision number to apply.
revision = 0
if currentMajor == major and currentMinor == minor
revision = currentRevision.to_i + 1
end
# Cache next version information
nextVersionName = major.to_s + "." + minor.to_s + "." + revision.to_s
nextVersionCode = latestRelease[:buildVersion].to_i + 1
# Read in app build config file.
buildConfigPath = "../app/build.gradle.kts" buildConfigPath = "../app/build.gradle.kts"
buildConfigFile = File.open(buildConfigPath) buildConfigFile = File.open(buildConfigPath)
buildConfigText = buildConfigFile.read buildConfigText = buildConfigFile.read
buildConfigFile.close buildConfigFile.close
if options[:versionName].nil? or options[:versionName].to_s.empty?
# Use the latest version name in Firebase as the default version name.
latestRelease = firebase_app_distribution_get_latest_release(
app: "1:867301491091:android:50b626dba42a361651e866",
service_credentials_file:options[:serviceCredentialsFile]
)
nextVersionName = latestRelease[:displayVersion]
else
nextVersionName = options[:versionName].to_s
end
# Replace version information. # Replace version information.
puts "Setting version code to #{nextVersionCode}." currentVersionCode = buildConfigText.match(/versionCode = (\d+)/).captures[0]
buildConfigText.gsub!("versionCode = 1", "versionCode = #{nextVersionCode}") currentVersionName = buildConfigText.match(/versionName = "(.+)"/).captures[0]
puts "Setting version code to #{options[:versionCode]}."
buildConfigText.gsub!("versionCode = #{currentVersionCode}", "versionCode = #{options[:versionCode]}")
puts "Setting version name to #{nextVersionName}." puts "Setting version name to #{nextVersionName}."
buildConfigText.gsub!("versionName = \"1.0\"", "versionName = \"#{nextVersionName}\"") buildConfigText.gsub!("versionName = \"#{currentVersionName}\"", "versionName = \"#{nextVersionName}\"")
# Save changes # Save changes
File.open(buildConfigPath, "w") { |buildConfigFile| buildConfigFile << buildConfigText } File.open(buildConfigPath, "w") { |buildConfigFile| buildConfigFile << buildConfigText }