-
-
Notifications
You must be signed in to change notification settings - Fork 156
319 lines (266 loc) · 10.9 KB
/
linux.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
name: Build for Linux
on:
# Enable manual run
workflow_dispatch:
push:
tags:
- '**'
branches:
- '**'
paths:
- .github/workflows/linux.yml
jobs:
build-flutter-app-x86_64:
name: Build Flutter app (x86_64)
runs-on: ubuntu-latest
permissions:
contents: write
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install apt dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libgtk-3-dev libx11-dev pkg-config cmake ninja-build libblkid-dev libsecret-1-dev libjsoncpp-dev ghostscript libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libunwind-dev webkit2gtk-4.1-dev
version: 1.0
execute_install_scripts: true
- name: Setup cache
uses: actions/cache@v4
with:
path: |
build
key: ${{ runner.OS }}-saber-${{ hashFiles('**/pubspec.lock') }}-${{ hashFiles('**/*.dart') }}
restore-keys: |
${{ runner.OS }}-saber-
- name: Remove proprietary dependencies
run: ./patches/remove_proprietary_dependencies.sh
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:'
- name: Disable Flutter CLI animations
run: flutter config --no-cli-animations
- run: flutter pub get
- name: Build Linux (x86_64)
run: |
flutter build linux \
--dart-define=DIRTY=$DIRTY
env:
DIRTY: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Compress Flutter build
id: compress
run: |
buildName=$(grep -oP "(?<=buildName = ').*(?=')" lib/data/version.dart)
archiveName="Saber_v${buildName}_Linux_x86_64.tar.gz"
echo "archiveName=$archiveName" >> $GITHUB_OUTPUT
mkdir -p AppDir
mv build/linux/x64/release/bundle/* AppDir
chmod +x AppDir/saber
install -Dm644 flatpak/com.adilhanney.saber.metainfo.xml -t AppDir/share/metainfo/
install -Dm644 flatpak/com.adilhanney.saber.metainfo.xml -t AppDir/usr/share/metainfo/
install -Dm644 assets/icon/icon.svg AppDir/share/icons/hicolor/scalable/apps/com.adilhanney.saber.svg
install -Dm644 assets/icon/icon.svg AppDir/usr/share/icons/hicolor/scalable/apps/com.adilhanney.saber.svg
install -Dm644 flatpak/com.adilhanney.saber.desktop -t AppDir/share/applications/
tar -C AppDir -cvf $archiveName .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: Saber-Archive-x86_64
path: ${{ steps.compress.outputs.archiveName }}
- name: Upload to GitHub release
uses: svenstaro/upload-release-action@v2
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ steps.compress.outputs.archiveName }}
build-flutter-app-arm64:
name: Build Flutter app (arm64)
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
timeout-minutes: 120
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup cache
uses: actions/cache@v4
with:
path: |
build
key: ${{ runner.OS }}-saberarm64-${{ hashFiles('**/pubspec.lock') }}-${{ hashFiles('**/*.dart') }}
restore-keys: |
${{ runner.OS }}-saberarm64-
- name: Build Linux (arm64)
uses: uraimo/run-on-arch-action@v2
with:
arch: aarch64
distro: ubuntu_latest
githubToken: ${{ github.token }}
setup: |
mkdir -p "${PWD}/AppDir"
mkdir -p "${PWD}/build/pub_cache"
dockerRunArgs: |
--volume "${PWD}/AppDir:/AppDir"
install: |
quiet () {
output=`"$@" 2>&1` || echo $output
}
unsudo () {
sudo -u nonroot env "PATH=$PATH" "CARGO_HOME=$CARGO_HOME" "RUSTUP_HOME=$RUSTUP_HOME" PUB_CACHE="$PUB_CACHE" "$@"
}
echo Installing dependencies
quiet apt-get update -qq -y
quiet apt-get install -qq -y \
sudo \
bash curl file git unzip xz-utils zip \
clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev \
libsecret-1-dev libjsoncpp-dev webkit2gtk-4.1-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libunwind-dev
echo Creating nonroot user
useradd -m -d /home/nonroot -s /bin/bash nonroot
echo 'export PATH="$PATH:/opt/flutter/bin"' >> /home/nonroot/.bashrc
echo 'export PATH="$PATH:/opt/cargo/bin"' >> /home/nonroot/.bashrc
echo 'export CARGO_HOME=/opt/cargo' >> /home/nonroot/.bashrc
echo 'export RUSTUP_HOME=/opt/rustup' >> /home/nonroot/.bashrc
echo 'export PUB_CACHE=build/pub_cache' >> /home/nonroot/.bashrc
export PATH="$PATH:/opt/flutter/bin"
export PATH="$PATH:/opt/cargo/bin"
export CARGO_HOME=/opt/cargo
export RUSTUP_HOME=/opt/rustup
export PUB_CACHE=build/pub_cache
echo Installing Flutter
if [ -z "$(which flutter)" ]; then
echo Flutter not installed, installing...
mkdir -p /opt/flutter
chown -R nonroot /opt/flutter
unsudo git clone https://github.com/flutter/flutter.git -b stable --depth 1 /opt/flutter
else
echo Flutter already installed, updating...
chown -R nonroot /opt/flutter
unsudo flutter upgrade
fi
echo flutter doctor
unsudo flutter doctor -v
echo Precaching Flutter
unsudo flutter precache --no-universal --linux
echo Installing Rust
mkdir -p $CARGO_HOME
mkdir -p $RUSTUP_HOME
mkdir -p "$RUSTUP_HOME/tmp"
chown -R nonroot $CARGO_HOME
chown -R nonroot $RUSTUP_HOME
unsudo curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y
chmod -R a+rw $CARGO_HOME
chmod -R a+rw $RUSTUP_HOME
unsudo ls -l $CARGO_HOME/bin
unsudo which rustup
run: |
unsudo () {
sudo -u nonroot env "PATH=$PATH" "CARGO_HOME=$CARGO_HOME" "RUSTUP_HOME=$RUSTUP_HOME" PUB_CACHE="$PUB_CACHE" "$@"
}
echo Setting up environment
chown -R nonroot .
chown -R nonroot /opt/flutter
chown -R nonroot /opt/cargo
export PATH="$PATH:/opt/flutter/bin"
export PATH="$PATH:/opt/cargo/bin"
export CARGO_HOME=/opt/cargo
export RUSTUP_HOME=/opt/rustup
export PUB_CACHE=build/pub_cache
echo Removing proprietary dependencies
./patches/remove_proprietary_dependencies.sh
echo Disabling Flutter CLI animations
unsudo flutter config --no-cli-animations
echo flutter pub get
unsudo flutter pub get
echo Verifying that rustup is installed
unsudo which rustup
echo Building
unsudo flutter build linux \
--target-platform linux-arm64 \
--dart-define=DIRTY=${{ !startsWith(github.ref, 'refs/tags/') }}
mv build/linux/arm64/release/bundle/* /AppDir/
chown -R nonroot /AppDir/
chmod -R a+rw /AppDir/
chmod a+x /AppDir/saber
- name: Compress Flutter build
id: compress
run: |
buildName=$(grep -oP "(?<=buildName = ').*(?=')" lib/data/version.dart)
archiveName="Saber_v${buildName}_Linux_arm64.tar.gz"
echo "archiveName=$archiveName" >> $GITHUB_OUTPUT
sudo chown -R $USER:$USER .
install -Dm644 flatpak/com.adilhanney.saber.metainfo.xml -t AppDir/share/metainfo/
install -Dm644 flatpak/com.adilhanney.saber.metainfo.xml -t AppDir/usr/share/metainfo/
install -Dm644 assets/icon/icon.svg AppDir/share/icons/hicolor/scalable/apps/com.adilhanney.saber.svg
install -Dm644 assets/icon/icon.svg AppDir/usr/share/icons/hicolor/scalable/apps/com.adilhanney.saber.svg
install -Dm644 flatpak/com.adilhanney.saber.desktop -t AppDir/share/applications/
tar -C AppDir -cvf $archiveName .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: Saber-Archive-arm64
path: ${{ steps.compress.outputs.archiveName }}
- name: Upload to GitHub release
uses: svenstaro/upload-release-action@v2
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ steps.compress.outputs.archiveName }}
build-appimage:
name: Build AppImage
needs: build-flutter-app-x86_64
runs-on: ubuntu-latest
permissions:
contents: write
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install AppImage dependencies
run: |
sudo add-apt-repository universe
sudo apt install libfuse2
- name: Download app archive
uses: actions/download-artifact@v4
with:
name: Saber-Archive-x86_64
- name: Rename app archive
run: |
mv Saber_*.tar.gz Saber-Linux-Portable.tar.gz
- name: Download appimage-builder
working-directory: appimage
run: |
wget -O appimage-builder-x86_64.AppImage https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage
chmod +x appimage-builder-x86_64.AppImage
- name: Prepare build files
working-directory: appimage
run: |
mkdir AppDir
tar -xvf ../Saber-Linux-Portable.tar.gz -C AppDir
- name: Set AppImage version
working-directory: appimage
run: |
# replace line with "version: latest" with "version: $buildName"
buildName=$(grep -oP "(?<=buildName = ').*(?=')" ../lib/data/version.dart)
sed -i "s/version: latest/version: ${buildName}/" AppImageBuilder.yml
- name: Build AppImage
working-directory: appimage
run: |
./appimage-builder-x86_64.AppImage --skip-test
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: AppImage artifact
path: appimage/Saber-*-x86_64.AppImage*
- name: Upload to GitHub release
uses: svenstaro/upload-release-action@v2
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: appimage/Saber-*-x86_64.AppImage*
file_glob: true