-
Notifications
You must be signed in to change notification settings - Fork 0
317 lines (274 loc) · 9.2 KB
/
deploy.yml
File metadata and controls
317 lines (274 loc) · 9.2 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
name: Build and Release APK
on:
push:
branches:
- main
paths-ignore:
- '**/README.md'
- '**/LICENSE'
- '**/CONTRIBUTING.md'
- '.github/**'
- '.gitignore'
- '.editorconfig'
- '.vscode/**'
- '.idea/**'
workflow_dispatch:
concurrency:
group: ${{ github.actor != 'github-actions[bot]' && format('{0}-{1}', github.workflow, github.ref) || '' }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
packages: write
jobs:
setup:
runs-on: ubuntu-latest
name: Setup
steps:
- name: Create keystore
run: |
mkdir -p app
echo "${{ secrets.RELEASE_KEYSTORE_BASE64 }}" | base64 -d > app/keystore.jks
- name: Create play-services.json
run: |
echo "${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}" | base64 -d > app/play-services.json
- name: Upload config files
uses: actions/upload-artifact@v4
with:
name: config-files
path: |
app/keystore.jks
app/play-services.json
retention-days: 1
version-check:
needs: setup
name: Check Version
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.decision.outputs.should_build }}
version_code: ${{ steps.remote.outputs.versionCode }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Google API Client
run: pip install google-api-python-client google-auth google-auth-oauthlib google-auth-httplib2
- name: Download config files
uses: actions/download-artifact@v4
with:
name: config-files
path: ./app
- name: Get local versionCode
id: local
run: |
code=$(grep -oP 'versionCode\s+\K\d+' app/build.gradle)
echo "versionCode=$code" >> $GITHUB_OUTPUT
- name: Get latest Play Store versionCode
id: remote
run: |
version=$(python3 .github/scripts/check_playstore_version.py | grep "__version_code__" | cut -d '=' -f2)
echo "versionCode=$version" >> $GITHUB_OUTPUT
env:
GOOGLE_APPLICATION_CREDENTIALS: ./app/play-services.json
- name: Decide build or bump
id: decision
run: |
LOCAL=${{ steps.local.outputs.versionCode }}
REMOTE=${{ steps.remote.outputs.versionCode }}
echo "Local: $LOCAL, Play Store: $REMOTE"
if [ "$LOCAL" -gt "$REMOTE" ]; then
echo "should_build=true" >> $GITHUB_OUTPUT
else
echo "should_build=false" >> $GITHUB_OUTPUT
fi
build-apk:
needs: version-check
if: needs.version-check.outputs.should_build == 'true'
name: Build APK
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '17'
cache: gradle
- name: Download configs
uses: actions/download-artifact@v4
with:
name: config-files
path: ./app
- name: Export signing env vars
run: |
echo "RELEASE_STORE_PASSWORD=${{ secrets.RELEASE_STORE_PASSWORD }}" >> $GITHUB_ENV
echo "RELEASE_KEY_ALIAS=${{ secrets.RELEASE_KEY_ALIAS }}" >> $GITHUB_ENV
echo "RELEASE_KEY_PASSWORD=${{ secrets.RELEASE_KEY_PASSWORD }}" >> $GITHUB_ENV
- name: Build APK
run: |
chmod +x gradlew
./gradlew assembleRelease
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: apk-release
path: |
app/build/outputs/apk/release/app-release.apk
retention-days: 1
build-aab:
needs: version-check
if: needs.version-check.outputs.should_build == 'true'
name: Build AAB
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '17'
cache: gradle
- name: Download configs
uses: actions/download-artifact@v4
with:
name: config-files
path: ./app
- name: Export signing env vars
run: |
echo "RELEASE_STORE_PASSWORD=${{ secrets.RELEASE_STORE_PASSWORD }}" >> $GITHUB_ENV
echo "RELEASE_KEY_ALIAS=${{ secrets.RELEASE_KEY_ALIAS }}" >> $GITHUB_ENV
echo "RELEASE_KEY_PASSWORD=${{ secrets.RELEASE_KEY_PASSWORD }}" >> $GITHUB_ENV
- name: Build AAB
run: |
chmod +x gradlew
./gradlew bundleRelease
- name: Upload AAB
uses: actions/upload-artifact@v4
with:
name: aab-release
path: |
app/build/outputs/bundle/release/app-release.aab
app/play-services.json
retention-days: 1
update-version:
needs: version-check
if: needs.version-check.outputs.should_build == 'false'
runs-on: ubuntu-latest
name: Update Version
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Get short SHA
id: sha
run: echo "sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Bump versionCode and versionName
id: bump
run: |
local_code=$(grep -oP 'versionCode\s+\K\d+' app/build.gradle)
local_name=$(grep -oP 'versionName\s+"\K[^"]+' app/build.gradle)
remote_code=${{ needs.version-check.outputs.version_code }}
new_code=$((local_code + 1))
while [ $new_code -le $remote_code ]; do
new_code=$((new_code + 1))
done
new_name="1.0-${{ steps.sha.outputs.sha }}"
sed -i "s/versionCode $local_code/versionCode $new_code/" app/build.gradle
sed -i "s/versionName \"$local_name\"/versionName \"$new_name\"/" app/build.gradle
echo "new_code=$new_code" >> $GITHUB_OUTPUT
echo "new_name=$new_name" >> $GITHUB_OUTPUT
- name: Commit and push
run: |
new_code=${{ steps.bump.outputs.new_code }}
new_name=${{ steps.bump.outputs.new_name }}
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add app/build.gradle
git commit -m "chore: bump version code to $new_code and version name to $new_name"
git push
publish:
name: Publish to Play Store
needs: [ build-apk, build-aab ]
runs-on: ubuntu-latest
outputs:
version_name: ${{ steps.get_version_name.outputs.version_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download AAB (if any)
uses: actions/download-artifact@v4
with:
name: aab-release
path: ./app
- name: Get Version Name
id: get_version_name
run: |
version_name=$(grep -oP 'versionName\s+"\K[^"]+' app/build.gradle)
echo "version_name=$version_name" >> $GITHUB_OUTPUT
- name: Create Whats New
run: |
mkdir -p whats-new
echo "Bug fixes and improvements" > whats-new/whatsnew-en-US
echo "Исправления ошибок и улучшения" > whats-new/whatsnew-ru-RU
- name: Upload to Play Store
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJson: app/play-services.json
packageName: com.ByteMechanics.matscape
releaseFiles: app/build/outputs/bundle/release/app-release.aab
track: production
status: completed
releaseName: Release ${{ steps.get_version_name.outputs.version_name }}
whatsNewDirectory: whats-new/
release:
name: Create Release
needs: publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get build artifact
uses: actions/download-artifact@v4
with:
name: apk-release
path: ./app
- name: Get Last Tag
id: get_last_tag
run: |
git fetch --tags
LAST_TAG=$(git describe --abbrev=0 --tags || echo "none")
echo "last_tag=${LAST_TAG}" >> $GITHUB_OUTPUT
- name: Generate New Tag
id: generate_new_tag
run: |
echo "new_tag=${{ needs.publish.outputs.version_name }}" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.generate_new_tag.outputs.new_tag }}
name: "Release ${{ steps.generate_new_tag.outputs.new_tag }}"
generate_release_notes: true
draft: false
prerelease: false
files: |
app/app-release.apk