-
Notifications
You must be signed in to change notification settings - Fork 36
183 lines (165 loc) · 6.14 KB
/
deploy-to-playstore.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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.22.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