-
Notifications
You must be signed in to change notification settings - Fork 0
295 lines (248 loc) · 12.8 KB
/
build_app.yml
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
name: Remote Dispatch Build Preview App
on:
# Dispatch or Manual triggers
workflow_dispatch:
inputs:
git-ref:
description: Git Ref to build ('master' for standard preview release, any other for dev preview pre-release)
required: false
dry-run:
description: Creates a draft release (any value would create a draft)
required: false
concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.git-ref }}
cancel-in-progress: true
jobs:
prepare-build:
if: github.event.inputs.git-ref != ''
runs-on: ubuntu-latest
outputs:
CURRENT_SHA: ${{ steps.current_commit.outputs.CURRENT_SHA }}
PREV_RELEASE_SHA: ${{ steps.previous_commit.outputs.PREV_RELEASE_SHA }}
COMMIT_LOGS: ${{ steps.commit_logs.outputs.COMMIT_LOGS }}
ARTIFACTS_PREFIX: ${{ steps.prepare_env.outputs.ARTIFACTS_PREFIX }}
BUILD_TYPE_NAME: ${{ steps.prepare_env.outputs.BUILD_TYPE_NAME }}
CHANGELOG: ${{ steps.set_changelog.outputs.CHANGELOG }}
TAG_NAME: ${{ steps.prepare_env.outputs.TAG_NAME }}
PREV_TAG_NAME: ${{ steps.previous_commit.outputs.PREV_TAG_NAME }}
steps:
- name: Clone Repository (${{ github.event.inputs.git-ref }})
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'komikku-app/komikku'
fetch-depth: 0
ref: ${{ github.event.inputs.git-ref }}
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@d156388eb19639ec20ade50009f3d199ce1e2808 # v4
- name: Get previous release
id: last_release
uses: InsonusK/get-latest-release@7a9ff16c8c6b7ead5d71c0f1cc61f2703170eade # v1.1.0
with:
myToken: ${{ github.token }}
exclude_types: "draft"
view_top: 1
- name: Curren commit
id: current_commit
run: |
set -e
commit_count=$(git rev-list --count HEAD)
echo "COMMIT_COUNT=$commit_count"
echo "COMMIT_COUNT=$commit_count" >> $GITHUB_OUTPUT
current_sha=$(git rev-parse --short HEAD)
echo "CURRENT_SHA=$current_sha"
echo "CURRENT_SHA=$current_sha" >> $GITHUB_OUTPUT
- name: Previous commit
id: previous_commit
run: |
set -e
commit_count_diff=$(git rev-list --count "${{ steps.last_release.outputs.tag_name }}"..HEAD)
# Fake at least 1 commits (to avoid no changes)
if [ "${commit_count_diff}" -eq 0 ]; then
commit_count_diff=1
fi
echo "commit_count_diff=$commit_count_diff"
prev_release_sha=$(git rev-parse --short HEAD~$commit_count_diff)
echo "PREV_RELEASE_SHA=$prev_release_sha"
echo "PREV_RELEASE_SHA=$prev_release_sha" >> $GITHUB_OUTPUT
echo "PREV_TAG_NAME=${{ steps.last_release.outputs.tag_name }}" >> $GITHUB_OUTPUT
- name: Prepare env
id: prepare_env
run: |
set -e
if [ "${{ github.event.inputs.git-ref }}" = "master" ]; then
tag_prefix=r
artifacts_prefix=standard/preview/app-standard
build_type_name=Preview
else
tag_prefix=d
artifacts_prefix=dev/preview/app-dev
build_type_name="Dev build"
fi
echo "${tag_prefix}${{ steps.current_commit.outputs.COMMIT_COUNT }}"
echo "TAG_NAME=${tag_prefix}${{ steps.current_commit.outputs.COMMIT_COUNT }}" >> $GITHUB_OUTPUT
echo "ARTIFACTS_PREFIX=$artifacts_prefix" >> $GITHUB_OUTPUT
echo "BUILD_TYPE_NAME=$build_type_name" >> $GITHUB_OUTPUT
- name: Commit logs
id: commit_logs
run: |
set -e
echo "COMMIT_LOGS<<{delimiter}
$(curl -H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/komikku-app/komikku/compare/${{ steps.previous_commit.outputs.PREV_RELEASE_SHA }}...${{ steps.current_commit.outputs.CURRENT_SHA }}" \
| jq '[.commits[]|{message:(.commit.message | split("\n")), username:.author.login}]' \
| jq -r '.[]|"- \(.message | first) (@\(.username))"')
{delimiter}" >> $GITHUB_OUTPUT
- name: Set CHANGELOG
id: set_changelog
if: github.event.inputs.git-ref != 'master'
run: |
changelog="$(git log ${{ steps.previous_commit.outputs.PREV_RELEASE_SHA }}..${{ steps.current_commit.outputs.CURRENT_SHA }} --pretty=format:'{{changelogtext}}%s (@%an){{!changelogtext}}')"
changelog="${changelog//$'%'/%25}"
changelog="${changelog//$'\n'/}"
changelog="${changelog//$'\r'/}"
changelog="${changelog//$'<'/}"
changelog="${changelog//$'>'/}"
changelog="${changelog//$'&'/}"
changelog="$(echo $changelog | sed -e 's/{{changelogtext}}/<changelogtext>/g')"
changelog="$(echo $changelog | sed -e 's/{{!changelogtext}}/<\/changelogtext>/g')"
changelog="<?xml version=\"1.0\" encoding=\"utf-8\"?><changelog bulletedList=\"true\"><changelogversion versionName=\"${{ steps.current_commit.outputs.TAG_NAME }}\" changeDate=\"\">$changelog</changelogversion></changelog>"
echo "CHANGELOG=$changelog" >> $GITHUB_OUTPUT
build-app:
runs-on: ubuntu-latest
needs: prepare-build
steps:
- name: Clone Repository (${{ github.event.inputs.git-ref }} - ${{ needs.prepare-build.outputs.TAG_NAME }})
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'komikku-app/komikku'
fetch-depth: 0
ref: ${{ github.event.inputs.git-ref }}
- name: Setup Android SDK
run: |
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "build-tools;29.0.3"
- name: Set up JDK
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
with:
java-version: 17
distribution: temurin
# Overwrite changelog with commits log if it's not a preview build
- name: Write changelog_preview.xml
uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 # v1.3
if: github.event.inputs.git-ref != 'master'
with:
path: app/src/main/res/raw/changelog_preview.xml
contents: "${{ needs.prepare-build.outputs.CHANGELOG }}"
write-mode: overwrite
- name: Write google-services.json
uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 # v1.3
if: github.event.inputs.git-ref == 'master'
with:
path: app/google-services.json
contents: ${{ secrets.GOOGLE_SERVICES_JSON }}
write-mode: overwrite
- name: Write client_secrets.json
uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 # v1.3
if: github.event.inputs.git-ref == 'master'
with:
path: app/src/main/assets/client_secrets.json
contents: ${{ secrets.GOOGLE_CLIENT_SECRETS_JSON }}
write-mode: overwrite
- name: Set up gradle
uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4
# - name: Build app and run unit tests
# uses: gradle/gradle-command-action@v2
# with:
# arguments: detekt assembleStandardPreview testStandardPreviewUnitTest testReleaseUnitTest
- name: Build standard app and run unit tests
if: github.event.inputs.git-ref == 'master'
run: ./gradlew assembleStandardPreview testStandardPreviewUnitTest testReleaseUnitTest -Pandroid.signingConfig=debug --stacktrace
- name: Build dev app and run unit tests
if: github.event.inputs.git-ref != 'master'
run: ./gradlew assembleDevPreview testDevPreviewUnitTest testReleaseUnitTest -Pandroid.signingConfig=debug --stacktrace
- name: Upload artifacts
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
path: "**/*.apk"
retention-days: 1
release-app:
runs-on: ubuntu-latest
needs:
- prepare-build
- build-app
steps:
- name: Download artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
merge-multiple: true
- name: Setup Android SDK
run: |
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager "build-tools;29.0.3"
- name: Sign APK
uses: r0adkll/sign-android-release@349ebdef58775b1e0d8099458af0816dc79b6407 # v1
with:
releaseDirectory: app/build/outputs/apk/standard/preview
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}
- name: Get SHA & clean up build artifacts
id: get_sha
run: |
set -e
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-universal-preview-unsigned-signed.apk Komikku-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
sha=`sha256sum Komikku-${{ needs.prepare-build.outputs.TAG_NAME }}.apk | awk '{ print $1 }'`
echo "APK_UNIVERSAL_SHA=$sha" >> $GITHUB_OUTPUT
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-arm64-v8a-preview-unsigned-signed.apk Komikku-arm64-v8a-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
sha=`sha256sum Komikku-arm64-v8a-${{ needs.prepare-build.outputs.TAG_NAME }}.apk | awk '{ print $1 }'`
echo "APK_ARM64_V8A_SHA=$sha" >> $GITHUB_OUTPUT
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-armeabi-v7a-preview-unsigned-signed.apk Komikku-armeabi-v7a-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
sha=`sha256sum Komikku-armeabi-v7a-${{ needs.prepare-build.outputs.TAG_NAME }}.apk | awk '{ print $1 }'`
echo "APK_ARMEABI_V7A_SHA=$sha" >> $GITHUB_OUTPUT
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-x86-preview-unsigned-signed.apk Komikku-x86-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
sha=`sha256sum Komikku-x86-${{ needs.prepare-build.outputs.TAG_NAME }}.apk | awk '{ print $1 }'`
echo "APK_X86_SHA=$sha" >> $GITHUB_OUTPUT
mv app/build/outputs/apk/${{ needs.prepare-build.outputs.ARTIFACTS_PREFIX }}-x86_64-preview-unsigned-signed.apk Komikku-x86_64-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
sha=`sha256sum Komikku-x86_64-${{ needs.prepare-build.outputs.TAG_NAME }}.apk | awk '{ print $1 }'`
echo "APK_X86_64_SHA=$sha" >> $GITHUB_OUTPUT
- name: Create release
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8
with:
tag_name: ${{ needs.prepare-build.outputs.TAG_NAME }}
name: Komikku ${{ needs.prepare-build.outputs.BUILD_TYPE_NAME }} ${{ needs.prepare-build.outputs.TAG_NAME }}
body: |
#### What's Changed
##### New
##### Improve
##### Fix
${{ needs.prepare-build.outputs.COMMIT_LOGS }}
**Full Changelog**: [komikku-app/komikku@${{ needs.prepare-build.outputs.PREV_TAG_NAME }}...${{ needs.prepare-build.outputs.TAG_NAME }}](https://github.com/komikku-app/komikku/compare/${{ needs.prepare-build.outputs.PREV_TAG_NAME }}...${{ needs.prepare-build.outputs.TAG_NAME }})
---
### Checksums
| Variant | SHA-256 |
| ------- | ------- |
| Universal | ${{ steps.get_sha.outputs.APK_UNIVERSAL_SHA }} |
| arm64-v8a | ${{ steps.get_sha.outputs.APK_ARM64_V8A_SHA }} |
| armeabi-v7a | ${{ steps.get_sha.outputs.APK_ARMEABI_V7A_SHA }} |
| x86 | ${{ steps.get_sha.outputs.APK_X86_SHA }} |
| x86_64 | ${{ steps.get_sha.outputs.APK_X86_64_SHA }} |
### If you are unsure which apk to download then go with `Komikku-${{ needs.prepare-build.outputs.TAG_NAME }}.apk`
files: |
Komikku-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
Komikku-arm64-v8a-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
Komikku-armeabi-v7a-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
Komikku-x86-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
Komikku-x86_64-${{ needs.prepare-build.outputs.TAG_NAME }}.apk
draft: ${{ github.event.inputs.dry-run != '' || github.event.inputs.git-ref == 'master'}}
prerelease: ${{ github.event.inputs.git-ref != 'master'}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
cleaning-repo:
runs-on: ubuntu-latest
steps:
- name: Prune old releases
uses: dev-drprasad/delete-older-releases@dfbe6be2a006e9475dfcbe5b8d201f1824c2a9fe # v0.3.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
keep_latest: 28
delete_tags: true