Skip to content

Deploy to Play Store #245

Deploy to Play Store

Deploy to Play Store #245

name: Deploy to Play Store
on:
workflow_dispatch:
# Enable manual run
inputs:
lane:
description: "Fastlane lane to use (internal, beta, promote_to_production)"
required: true
default: "internal"
tag:
description: "GitHub tag"
required: true
default: "latest"
ref:
description: "GitHub ref, if not provided, will use the tag"
required: false
default: ""
workflow_run:
workflows:
- Add Artifacts for Release
- Add Artifacts for Release Candidate
types: [completed]
release:
# The prereleased type will not trigger for pre-releases published from
# draft releases, but the published type will trigger. If you want a
# workflow to run when stable and pre-releases publish, subscribe to
# published instead of released and prereleased.
types: [published]
jobs:
# Extract some useful variable
# 1. lane - Same as 'workflow_dispatch' inputs, auto generate from tag name
# 2. dev_build_number - extract number of RC
# 3. flavor - 'dev'(internal) or 'prod'(beta)
# 4. build_code - pubspec.yaml build code.
var:
name: Extracting variables
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
outputs:
ref: ${{ github.event.inputs.ref || steps.tag.outputs.result }}
lane: ${{ steps.lane.outputs.result }}
dev_build_number: ${{ steps.dev_build_number.outputs.result }}
flavor: ${{ steps.flavor.outputs.value }}
build_code: ${{ steps.build_code.outputs.value }}
steps:
- name: Get latest tag
id: tag
uses: actions/github-script@v7
with:
result-encoding: string
script: |
if (context.eventName === 'release') {
return context.payload.release.tag_name;
}
if (context.eventName === 'workflow_dispatch') {
if (context.payload.inputs.tag !== 'latest') {
return context.payload.inputs.tag;
}
}
const res = await github.rest.repos.listTags({
owner: 'evan361425',
repo: 'flutter-pos-system',
per_page: 1,
});
return res.data[0].name;
- name: Extract lane
id: lane
uses: actions/github-script@v7
with:
result-encoding: string
script: |
return context.eventName === 'workflow_dispatch'
? '${{ github.event.inputs.lane }}'
: context.eventName === 'release'
? 'promote_to_production'
: '${{ steps.tag.outputs.result }}'.includes('-rc')
? 'internal'
: 'beta';
- name: Extract Flavor
id: flavor
uses: haya14busa/action-cond@v1
with:
cond: ${{ steps.lane.outputs.result == 'internal' }}
if_true: dev
if_false: prod
- name: Checkout code
uses: actions/checkout@v4
with:
ref: "refs/tags/${{ steps.tag.outputs.result }}"
- name: Extract build code
id: build_code
run: |
ver=$(grep -m 1 '^version: ' pubspec.yaml | cut -d' ' -f2)
echo "value=$(echo "$ver" | cut -f2- -d"+")" >> $GITHUB_OUTPUT
- name: Extract build number
id: dev_build_number
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const ref = '${{ steps.tag.outputs.result }}';
return ref.includes('-rc')
? ref.substr(ref.indexOf('-rc') + 3)
: ''.concat(${{ steps.build_code.outputs.value }} % 100);
fastlane-deploy:
runs-on: ubuntu-20.04
needs: var
steps:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: "3.24.x"
cache: true
channel: "stable"
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.var.outputs.ref }}
# Setup Ruby, Bundler, and Gemfile dependencies
- name: Setup Fastlane
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
working-directory: android
- run: bundle exec fastlane --version
working-directory: android
# Get flutter dependencies.
- name: Build dependencies
run: flutter pub get
# Setup Java environment in order to build the Android app.
- uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: "17"
- name: Configure Google Services
run: echo "$GOOGLE_SERVICES_JSON" > google-services.json
env:
GOOGLE_SERVICES_JSON: |
${{ needs.var.outputs.lane == 'internal' && secrets.GOOGLE_SERVICES_JSON_DEV || secrets.GOOGLE_SERVICES_JSON }}
working-directory: android/app
- name: Configure Keystore
run: |
echo "$PLAY_STORE_UPLOAD_KEY" | base64 --decode > app/upload-keystore.jks
echo "storeFile=upload-keystore.jks" >> key.properties
echo "keyAlias=$KEYSTORE_KEY_ALIAS" >> key.properties
echo "storePassword=$KEYSTORE_STORE_PASSWORD" >> key.properties
echo "keyPassword=$KEYSTORE_KEY_PASSWORD" >> key.properties
env:
PLAY_STORE_UPLOAD_KEY: ${{ secrets.PLAY_STORE_UPLOAD_KEY }}
KEYSTORE_KEY_ALIAS: ${{ secrets.KEYSTORE_KEY_ALIAS }}
KEYSTORE_KEY_PASSWORD: ${{ secrets.KEYSTORE_KEY_PASSWORD }}
KEYSTORE_STORE_PASSWORD: ${{ secrets.KEYSTORE_STORE_PASSWORD }}
working-directory: android
# Build and deploy with Fastlane (by default, to internal track) 🚀.
# Naturally, promote_to_production only deploys.
- name: Fastlane building
run: |
bundle exec fastlane ${{ needs.var.outputs.lane }}
env:
SUPPLY_UPLOAD_MAX_RETRIES: 5
PLAY_STORE_CONFIG_JSON: ${{ secrets.PLAY_STORE_CONFIG_JSON }}
BUILD_NUMBER: ${{ needs.var.outputs.dev_build_number }}
VERSION_CODE: ${{ needs.var.outputs.build_code }}
working-directory: android