-
Notifications
You must be signed in to change notification settings - Fork 1
249 lines (216 loc) · 7.36 KB
/
build.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
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
name: Build app
on:
push:
paths:
- ".github/workflows/build.yaml"
- "android/**"
- "lib/**"
- "web/**"
- "analysis_options.yaml"
- "CHANGELOG.md"
- "pubspec.yaml"
- "pubspec.lock"
pull_request:
paths:
- ".github/workflows/build.yaml"
- "android/**"
- "lib/**"
- "web/**"
- "analysis_options.yaml"
- "pubspec.yaml"
- "pubspec.lock"
env:
JAVA_VERSION: "17"
JAVA_DISTRIBUTION: temurin
FLUTTER_CHANNEL: beta
permissions:
contents: read
jobs:
lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Java
uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
channel: ${{ env.FLUTTER_CHANNEL }}
cache: "true"
- name: Get Flutter dependencies
run: flutter pub get
- name: Generate missing files
run: dart run build_runner build
- name: Analyze code
run: flutter analyze
- name: Check formatting
run: >
find lib/ -name '*.dart' -not -name '*.g.dart'
| xargs dart format --set-exit-if-changed --output none --line-length=100
build-apk:
name: Build app for Android
runs-on: ubuntu-latest
needs:
- lint
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Java
uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: gradle
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
channel: ${{ env.FLUTTER_CHANNEL }}
cache: "true"
- name: Get Flutter dependencies
run: flutter pub get
- name: Generate missing files
run: dart run build_runner build
- name: Decode keystore file
env:
KEYSTORE_CONTENTS: ${{ secrets.KEYSTORE_CONTENTS }}
run: |
echo "$KEYSTORE_CONTENTS" | base64 -d >android/keystore.jks
- name: Build app for Android
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
BUILD_FLAVOR="dev"
if [[ "${GITHUB_REF}" == "refs/tags/v"* ]]; then
BUILD_FLAVOR="prod"
fi
flutter build apk --release --split-per-abi --flavor "${BUILD_FLAVOR?}"
- name: Upload APK artifact
uses: actions/upload-artifact@v4
with:
name: android-apks
if-no-files-found: error
path: |
build/app/outputs/flutter-apk/app-*.apk
build/app/outputs/flutter-apk/app-*.apk.sha1
- name: Send dev APK to testers Telegram group
if: "!startsWith(github.ref, 'refs/tags/v')"
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
actual_version="$(git describe --tags --always | sed -E 's/(-([0-9]+)-g([0-9a-f]+))?$/.r\2-\3/g')"
curl --silent --show-error --fail-with-body \
-F "chat_id=${TELEGRAM_CHAT_ID}" \
-F "document=@build/app/outputs/flutter-apk/app-arm64-v8a-dev-release.apk" \
-F "caption=New version: ${actual_version}" \
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument" \
>/dev/null
continue-on-error: true
build-web:
name: Build app for web
runs-on: ubuntu-latest
needs:
- lint
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Java
uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
channel: ${{ env.FLUTTER_CHANNEL }}
cache: true
- name: Get Flutter dependencies
run: flutter pub get
- name: Generate missing files
run: dart run build_runner build
- name: Build app for web
run: flutter build web
- name: Patch app name for web
run: |
jq -c '.app_name = "Mafia companion"' build/web/version.json >build/web/version.new.json
mv build/web/version{.new,}.json
- name: Upload web artifact
uses: actions/upload-pages-artifact@v3
with:
path: build/web/
publish-web:
name: Publish web build on GitHub Pages
runs-on: ubuntu-latest
needs:
- build-web
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Publish web on GitHub pages
id: deployment
uses: actions/deploy-pages@v4
create-release:
name: Create release
runs-on: ubuntu-latest
needs:
- build-apk
permissions:
contents: write
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download APK artifact
uses: actions/download-artifact@v4
with:
name: android-apks
path: build
- name: Generate release notes
id: release_notes
run: |
file="$(mktemp --suffix=.md)"
previous_tag="$(git describe --tags --abbrev=0 "${GITHUB_REF_NAME}^")"
start_line="$(grep -En "## \[v?$GITHUB_REF_NAME\]" CHANGELOG.md | cut -d ':' -f 1)"
end_line="$(grep -En "## \[v?$previous_tag\]" CHANGELOG.md | cut -d ':' -f 1)"
sed -n "$((${start_line} + 1)),$((${end_line} - 1))p" CHANGELOG.md >$file
sed -Ei 's/###/##/;1{/^\s*$/d}' $file
# ChatGPT-powered magic to remove trailing empty lines
sed -i ':l;/^\n*$/{$d;N;bl;}' $file
echo -ne '\n## Commits\n\n' >>$file
git log --format="- %h: %s (%aN)" "${previous_tag}..${GITHUB_REF_NAME}" >>$file
echo "$GITHUB_REF_NAME" | awk '{ print "prerelease=" (($1 ~ /v[0-9]+\.[0-9]+\.[0-9]+-.+/) ? "true" : "false"); }' >>$GITHUB_OUTPUT
echo "release_notes=$file" >>$GITHUB_OUTPUT
- name: Create a release
uses: softprops/action-gh-release@v2
with:
body_path: ${{ steps.release_notes.outputs.release_notes }}
prerelease: ${{ steps.release_notes.outputs.prerelease }}
files: |
build/app-*.apk
fail_on_unmatched_files: true
- name: Send release info to testers Telegram group
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
release_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${GITHUB_REF_NAME}"
curl --silent --show-error --fail-with-body \
-F "chat_id=${TELEGRAM_CHAT_ID}" \
-F "parse_mode=MarkdownV2" \
-F "text=New release: [${GITHUB_REF_NAME}](${release_url})" \
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
>/dev/null
continue-on-error: true