This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
260 lines (219 loc) · 8.23 KB
/
build-and-publish.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
name: Build-And-Publish
# when to run this job
on:
# manual build
workflow_dispatch:
# new tag
push:
tags:
- '*'
# job configuration
env:
target_repo: Tenshiorg/Tenshi
target_ref: senpai
extension_ref: senpai
jobs:
# don't run if already released this tag
check_tag:
runs-on: ubuntu-latest
steps:
# check out repo without submodules
- name: Checkout Repo
uses: actions/checkout@v2
with:
repository: ${{ env.target_repo }}
ref: ${{ env.target_ref }}
fetch-depth: 0
# get the last release
- name: Get last release
id: last_release
uses: InsonusK/[email protected]
with:
myToken: ${{ github.token }}
exclude_types: "draft|prerelease"
view_top: 1
# get difference between last release and current release
- name: compare last release with current
id: compare_releases
shell: bash
run: |
set -x
# get current tag name and commit sha
currentTag=$(git describe --abbrev=0 --tags)
currentSha=$(git rev-parse --short tags/$currentTag)
# get latest release commit sha
lastTag=${{ steps.last_release.outputs.tag_name }}
lastSha=$(git rev-parse --short tags/$lastTag || true)
# write info to log
echo "Current tag is $currentTag with SHA $currentSha"
echo "Last release is $lastTag with SHA $lastSha"
# compare sha and tag name
if [ "$currentSha" == "$lastSha" ] || [ "$currentTag" == "$lastTag" ]; then
echo "Current SHA or Tag is equal to previous release."
echo "❌ There is nothing new to build, so we skip the run"
echo ::set-output name=ABORT_RUN::true
else
echo "Current SHA and Tag are not equal to previous release."
echo "✔ We have a new release, lets start building!"
echo ::set-output name=ABORT_RUN::false
fi
# cancel run
- name: Cancel run if no changes
if: steps.compare_releases.outputs.ABORT_RUN == 'true'
uses: andymckay/[email protected]
# build the apk for release
build:
needs: check_tag
runs-on: ubuntu-latest
steps:
# check out repo with submodules
- name: Checkout Repo
uses: actions/checkout@v2
with:
repository: ${{ env.target_repo }}
ref: ${{ env.target_ref }}
fetch-depth: 0
submodules: recursive
# switch extensionlib to senpai (production) branch
- name: Checkout ExtensionLib senpai
shell: bash
run: |
git submodule update --init --recursive --remote
cd Extensions-Lib
git checkout ${{ env.extension_ref }}
cd ..
# setup jdk
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
# prepare build.properties
- name: Prepare build and signing config
shell: bash
run: |
# write keystore
# path here is relative to repository root
echo "${{ secrets.SIGNING_KEY }}" | base64 -d > ./keystore.jks
# write build.properties
cat <<EOT > ./app/build.properties
# enable preview builds
# on preview builds, the versionCode is set to the commit count
# and versionName is set to the current commit SHA
PREVIEW_BUILD=false
# MyAnimeList.net client ID
# If you don't already have one, you can create it here: https://myanimelist.net/apiconfig
MAL_CLIENT_ID=${{ secrets.MAL_CLIENT_ID }}
# OAUTH response redirect url to use (for MAL)
# This has to match the value you set in your API client config
OAUTH_REDIRECT_URL=tenshiapp://tenshi.app.auth.mal/
# signing config for assembleRelease
# keystore file, may be relative (to /app directory, that is) like so: ..\\Your-KeyStore.jks
SIGN_STORE_FILE=../keystore.jks
# password of the keystore
SIGN_STORE_PASSWORD=${{ secrets.KEY_STORE_PASSWORD}}
# key alias to use for signing the release
SIGN_KEY_ALIAS=${{ secrets.ALIAS }}
# password for the key
SIGN_KEY_PASSWORD=${{ secrets.KEY_PASSWORD }}
EOT
# make gradlew executeable
- name: Make Gradle Executable
run: chmod +x ./gradlew
# build app
- name: Build App
uses: eskatos/gradle-command-action@v1
with:
arguments: assembleRelease
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
# rename apk for generic artifact upload
- name: Rename APK
run: mv ./app/build/outputs/apk/release/app-release.apk ./app.apk
# upload apk as artifact
- name: Upload APK Artifact
uses: actions/upload-artifact@v2
with:
name: apk
path: ./app.apk
# create a new release and attach the built APK
upload_github:
needs: build
runs-on: ubuntu-latest
steps:
# check out repo without submodules
- name: Checkout Repo
uses: actions/checkout@v2
with:
repository: ${{ env.target_repo }}
ref: ${{ env.target_ref }}
fetch-depth: 0
# get difference between last release and current release
- name: Prepare Build Details
id: build_details
shell: bash
run: |
set -x
# get current tag name and commit sha
currentTag=$(git describe --abbrev=0 --tags)
currentSha=$(git rev-parse --short tags/$currentTag)
# write to outputs and log
echo ::set-output name=CURRENT_TAG::$currentTag
echo ::set-output name=CURRENT_SHA::$currentSha
echo "Current tag is $currentTag with SHA $currentSha"
# get previous tag name and commit sha
# use --always since it otherwise fails with only one tag in the repo
previousSha=$(git rev-parse --short tags/$currentTag^)
previousTag=$(git describe --abbrev=0 --tags $previousSha --always)
# write to outputs and log
echo ::set-output name=PREV_TAG::$previousTag
echo ::set-output name=PREV_SHA::$previousSha
echo "Previous tag is $previousTag with SHA $previousSha"
# get diff url
diffUrl="https://github.com/${{ env.target_repo }}/compare/$previousTag...$currentTag"
echo ::set-output name=DIFF_URL::$diffUrl
echo "DIFF url is $diffUrl"
# build filename
apkPath="./tenshi_release_$currentTag.apk"
echo ::set-output name=APK_PATH::$apkPath
echo "APK path is $apkPath"
# download built apk artifact
- name: Get APK Artifact
id: download_artifact
uses: actions/download-artifact@v2
with:
name: apk
path: ./
# rename the apk artifact
- name: Rename APK
shell: bash
run: mv ./app.apk ${{ steps.build_details.outputs.APK_PATH }}
# generate apk checksum
- name: "Generate APK Checksum"
id: apk_hash
shell: bash
run: |
fileHash=$(sha256sum ${{ steps.build_details.outputs.APK_PATH }})
echo ::set-output name=SHA::$fileHash
# create new release
- name: Create the Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.build_details.outputs.CURRENT_TAG }}
name: Tenshi Release ${{ steps.build_details.outputs.CURRENT_TAG }}
body: |
[Changes since Release ${{ steps.build_details.outputs.PREV_TAG }}](${{ steps.build_details.outputs.DIFF_URL }})
APK SHA256: ${{ steps.apk_hash.outputs.SHA }}
> 🤖 this release was created automatically
files: |
${{ steps.build_details.outputs.APK_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# remove old releases (PREVIEW)
#- name: Purge old releases
# uses: dev-drprasad/[email protected]
# with:
# keep_latest: 10
# delete_tags: true
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}