-
Notifications
You must be signed in to change notification settings - Fork 1
204 lines (176 loc) · 5.51 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
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@v3
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: Analyze code
run: flutter analyze
- name: Check formatting
run: dart format --set-exit-if-changed --output none --line-length=100 lib/
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@v3
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: 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: flutter build apk --release --split-per-abi
- name: Upload APK artifact
uses: actions/upload-artifact@v3
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
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@v3
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: 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@v2
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@v2
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@v3
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@v1
with:
body_path: ${{ steps.release_notes.outputs.release_notes }}
prerelease: ${{ steps.release_notes.outputs.prerelease }}
files: |
build/app-*.apk
fail_on_unmatched_files: true