Skip to content

Commit

Permalink
Update GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer committed Dec 7, 2024
1 parent 402bc3b commit 270e9e9
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 17 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/main.yml → .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# SPDX-License-Identifier: MIT
#

name: Main
name: Deployment

on:
push:
Expand All @@ -24,14 +24,24 @@ on:
- internal
- staging
- production
version:
description: |
The semantic version of the app that should be released.
required: true
type: string
workflow_call:
inputs:
environment:
description: |
The GitHub deployment environment.
required: false
type: string
default: internal
default: staging
version:
description: |
The semantic version of the app that should be released.
required: true
type: string

concurrency:
group: main
Expand All @@ -50,7 +60,7 @@ jobs:
id: determineenvironment
run: |
if [[ -z "${{ inputs.environment }}" ]]; then
echo "environment=internal" >> $GITHUB_OUTPUT
echo "environment=staging" >> $GITHUB_OUTPUT
else
echo "environment=${{ inputs.environment }}" >> $GITHUB_OUTPUT
fi
Expand All @@ -61,15 +71,23 @@ jobs:
environment: ${{ needs.determineenvironment.outputs.environment }}
outputs:
appidentifier: ${{ vars.APP_IDENTIFIER }}
version: ${{ steps.vars.outputs.version }}
steps:
- uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
- run: |
echo "Injecting Environment Variables In Deployment Workflow:"
echo "appidentifier: ${{ vars.APP_IDENTIFIER }}"
if [[ -z "${{ inputs.version }}" ]]; then
echo "version=${{ steps.get-latest-tag.outputs.tag }}" >> $GITHUB_OUTPUT
else
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
fi
buildtestandanalyze:
uses: ./.github/workflows/build-test-analyze.yml
secrets: inherit
googleplayinternal:
name: Upload App to Google Play - Internal
name: Upload App to Google Play
runs-on: ubuntu-latest
needs: [buildtestandanalyze, determineenvironment, vars]
environment: ${{ needs.determineenvironment.outputs.environment }}
Expand Down Expand Up @@ -105,4 +123,4 @@ jobs:
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
SERVICE_ACCOUNT_JSON_KEY: ${{ secrets.SERVICE_ACCOUNT_JSON_KEY }}
run: bundle exec fastlane internal environment:"${{ needs.determineenvironment.outputs.environment }}" applicationid:"${{ needs.vars.outputs.appidentifier }}"
run: bundle exec fastlane internal environment:"${{ needs.determineenvironment.outputs.environment }}" applicationid:"${{ needs.vars.outputs.appidentifier }}" versionname:"${{ needs.vars.outputs.version }}"
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# This source file is part of the Stanford Spezi open-source project
#
# SPDX-FileCopyrightText: 2024 Stanford University
#
# SPDX-License-Identifier: MIT
#

name: Release

on:
release:
types: [published]

concurrency:
group: production
cancel-in-progress: false

jobs:
build-and-test:
name: Build and Test
uses: ./.github/workflows/deployment.yml
permissions:
contents: read
checks: write
actions: read
security-events: write
secrets: inherit
with:
environment: production
version: ${{ github.event.release.tag_name }}
37 changes: 25 additions & 12 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

default_platform(:android)

APP_CONFIG = {
default_environment: "staging",
default_application_id: "edu.stanford.bdh.engagehf",
default_version_name: "2.0.0",
signing: {
store_file: "keystore.jks",
store_password: ENV['KEY_PASSWORD'],
key_alias: ENV['KEY_ALIAS'],
key_password: ENV['KEY_PASSWORD']
},
json_key_data: ENV['SERVICE_ACCOUNT_JSON_KEY']
}.freeze

platform :android do
desc "Runs all unit tests"
lane :test do
Expand All @@ -21,18 +34,19 @@ platform :android do

desc "Deploy a new version to the Google Play (Internal)"
lane :internal do |options|
environment = options[:environment] || "staging"
applicationid = options[:applicationid] || "edu.stanford.bdh.engagehf"
track = environment == "production" ? 'production' : 'internal'
environment = options[:environment].to_s.strip.empty? ? APP_CONFIG[:default_environment] : options[:environment]
applicationid = options[:applicationid].to_s.strip.empty? ? APP_CONFIG[:default_application_id] : options[:applicationid]
version_name = options[:versionname].to_s.strip.empty? ? APP_CONFIG[:default_version_name] : options[:versionname]

UI.message("Using environment: #{environment}")
UI.message("Using application id: #{applicationid}")
UI.message("Using version name: #{version_name}")

def fetch_max_version_code(track, applicationid)
version_codes = google_play_track_version_codes(
package_name: applicationid,
track: track,
json_key_data: ENV['SERVICE_ACCOUNT_JSON_KEY']
json_key_data: APP_CONFIG[:json_key_data]
)

if version_codes.nil? || version_codes.empty?
Expand All @@ -57,19 +71,18 @@ platform :android do
properties: {
"android.injected.application.id" => applicationid,
"android.injected.version.code" => current_version_code,
"android.injected.version.name" => "2.0.0",
"android.injected.signing.store.file" => "keystore.jks",
"android.injected.signing.store.password" => ENV['KEY_PASSWORD'],
"android.injected.signing.key.alias" => ENV['KEY_ALIAS'],
"android.injected.signing.key.password" => ENV['KEY_PASSWORD'],
"android.injected.version.name" => version_name,
"android.injected.signing.store.file" => APP_CONFIG[:signing][:store_file],
"android.injected.signing.store.password" => APP_CONFIG[:signing][:store_password],
"android.injected.signing.key.alias" => APP_CONFIG[:signing][:key_alias],
"android.injected.signing.key.password" => APP_CONFIG[:signing][:key_password],
}
)

upload_to_play_store(
package_name: applicationid,
track: track,
json_key_data: ENV['SERVICE_ACCOUNT_JSON_KEY'],
release_status: completed
track: environment == "production" ? 'production' : 'internal',
json_key_data: APP_CONFIG[:json_key_data]
)
end
end

0 comments on commit 270e9e9

Please sign in to comment.