-
Notifications
You must be signed in to change notification settings - Fork 14
455 lines (396 loc) · 14.8 KB
/
build.yml
File metadata and controls
455 lines (396 loc) · 14.8 KB
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
name: Build and Release
on:
release:
types: [created]
workflow_dispatch:
inputs:
version:
description: "Version to build (e.g., 1.0.11, leave empty for pubspec.yaml)"
required: false
default: ""
build_android:
description: "Build Android APKs"
required: false
default: true
type: boolean
build_ios:
description: "Build iOS IPA"
required: false
default: true
type: boolean
build_windows:
description: "Build Windows EXE"
required: false
default: true
type: boolean
build_linux:
description: "Build Linux (tar.gz + AppImage)"
required: false
default: true
type: boolean
build_flatpak:
description: "Build Flatpak bundle"
required: false
default: false
type: boolean
skip_tests:
description: "Skip running tests"
required: false
default: false
type: boolean
env:
FLUTTER_VERSION: "3.38.6"
jobs:
# Shared setup job to prepare version info
prepare:
name: Prepare Build
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
build_number: ${{ steps.version.outputs.build_number }}
is_release: ${{ github.event_name == 'release' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Determine version
id: version
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
TAG_VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//')
elif [[ -n "${{ inputs.version }}" ]]; then
TAG_VERSION="${{ inputs.version }}"
else
TAG_VERSION=$(grep "^version:" pubspec.yaml | sed 's/^version: //' | cut -d'+' -f1)
fi
# Ensure semantic version format
if [[ "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then
TAG_VERSION="${TAG_VERSION}.0"
fi
if [[ ! "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format: $TAG_VERSION"
exit 1
fi
BUILD_NUMBER=${{ github.run_number }}
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
echo "build_number=$BUILD_NUMBER" >> $GITHUB_OUTPUT
echo "Version: $TAG_VERSION+$BUILD_NUMBER"
# Android Build Job
build-android:
name: Build Android
needs: prepare
if: ${{ github.event_name == 'release' || inputs.build_android }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('android/**/*.gradle*', 'android/**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Decode Keystore
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
if [ -n "$KEYSTORE_BASE64" ]; then
echo "$KEYSTORE_BASE64" | base64 --decode > android/app/upload-keystore.jks
cat > android/key.properties << EOF
storeFile=${{ github.workspace }}/android/app/upload-keystore.jks
keyAlias=$KEY_ALIAS
storePassword=$STORE_PASSWORD
keyPassword=$KEY_PASSWORD
EOF
fi
- name: Get dependencies
run: flutter pub get
- name: Update version
run: |
sed -i "s/^version: .*/version: ${{ needs.prepare.outputs.version }}+${{ needs.prepare.outputs.build_number }}/" pubspec.yaml
- name: Build APKs
run: |
flutter build apk --release
flutter build apk --split-per-abi --release
- name: Prepare artifacts
run: |
mkdir -p artifacts
# Naming convention: contains "android" and architecture keywords for update_checker detection
cp build/app/outputs/flutter-apk/app-release.apk artifacts/openlibextended-android-universal-${{ needs.prepare.outputs.version }}.apk
cp build/app/outputs/flutter-apk/app-arm64-v8a-release.apk artifacts/openlibextended-android-arm64-${{ needs.prepare.outputs.version }}.apk
cp build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk artifacts/openlibextended-android-armeabi-v7a-${{ needs.prepare.outputs.version }}.apk
cp build/app/outputs/flutter-apk/app-x86_64-release.apk artifacts/openlibextended-android-x86_64-${{ needs.prepare.outputs.version }}.apk || true
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: android-builds
path: artifacts/*.apk
retention-days: 7
# iOS Build Job
build-ios:
name: Build iOS
needs: prepare
if: ${{ github.event_name == 'release' || inputs.build_ios }}
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
- name: Cache CocoaPods
uses: actions/cache@v4
with:
path: ios/Pods
key: pods-${{ runner.os }}-${{ hashFiles('ios/Podfile.lock') }}
restore-keys: |
pods-${{ runner.os }}-
- name: Get dependencies
run: flutter pub get
- name: Update version
run: |
sed -i '' "s/^version: .*/version: ${{ needs.prepare.outputs.version }}+${{ needs.prepare.outputs.build_number }}/" pubspec.yaml
- name: Build iOS (no codesign)
run: flutter build ios --release --no-codesign
- name: Create IPA
run: |
mkdir -p artifacts
mkdir -p Payload
cp -r build/ios/iphoneos/Runner.app Payload/
zip -r artifacts/openlibextended-ios-${{ needs.prepare.outputs.version }}.ipa Payload
rm -rf Payload
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ios-builds
path: artifacts/*.ipa
retention-days: 7
# Windows Build Job
build-windows:
name: Build Windows
needs: prepare
if: ${{ github.event_name == 'release' || inputs.build_windows }}
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
- name: Get dependencies
run: flutter pub get
- name: Update version
run: |
(Get-Content pubspec.yaml) -replace '^version: .*', "version: ${{ needs.prepare.outputs.version }}+${{ needs.prepare.outputs.build_number }}" | Set-Content pubspec.yaml
- name: Build Windows
run: flutter build windows --release
- name: Create installer with Inno Setup
run: |
# Download Inno Setup
choco install innosetup -y
# Create Inno Setup script
@"
[Setup]
AppName=OpenlibExtended
AppVersion=${{ needs.prepare.outputs.version }}
AppPublisher=warreth
DefaultDirName={autopf}\OpenlibExtended
DefaultGroupName=OpenlibExtended
OutputDir=artifacts
OutputBaseFilename=openlibextended-windows-x64-${{ needs.prepare.outputs.version }}
Compression=lzma
SolidCompression=yes
ArchitecturesInstallIn64BitMode=x64compatible
[Files]
Source: "build\windows\x64\runner\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
[Icons]
Name: "{group}\OpenlibExtended"; Filename: "{app}\OpenlibExtended.exe"
Name: "{commondesktop}\OpenlibExtended"; Filename: "{app}\OpenlibExtended.exe"
[Run]
Filename: "{app}\OpenlibExtended.exe"; Description: "Launch OpenlibExtended"; Flags: nowait postinstall skipifsilent
"@ | Out-File -FilePath "installer.iss" -Encoding UTF8
mkdir artifacts
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" installer.iss
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: windows-builds
path: artifacts/*.exe
retention-days: 7
# Linux Build Job
build-linux:
name: Build Linux
needs: prepare
if: ${{ github.event_name == 'release' || inputs.build_linux }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev libfuse2 libwebkit2gtk-4.1-dev
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
- name: Build Linux
run: |
flutter pub get
sed -i "s/^version: .*/version: ${{ needs.prepare.outputs.version }}+${{ needs.prepare.outputs.build_number }}/" pubspec.yaml
flutter build linux --release
- name: Create AppImage
run: |
mkdir -p artifacts
# Download appimagetool
wget -q https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
chmod +x appimagetool-x86_64.AppImage
# Create AppDir structure
mkdir -p AppDir/usr/{bin,lib,share/applications,share/icons/hicolor/256x256/apps}
cp -r build/linux/x64/release/bundle/* AppDir/usr/bin/
# Rename the binary in AppDir if created with old case, mostly for safety but check build output first
if [ -f "AppDir/usr/bin/OpenlibExtended" ]; then
mv AppDir/usr/bin/OpenlibExtended AppDir/usr/bin/openlibextended
fi
cp assets/icons/appIcon.png AppDir/usr/share/icons/hicolor/256x256/apps/openlibextended.png
cp assets/icons/appIcon.png AppDir/openlibextended.png
# Create desktop entry
cat > AppDir/openlibextended.desktop << 'EOF'
[Desktop Entry]
Name=OpenlibExtended
Comment=Download and read books from shadow library
Exec=openlibextended
Icon=openlibextended
Type=Application
Categories=Education;Literature;
Keywords=books;library;epub;pdf;reader;
EOF
cp AppDir/openlibextended.desktop AppDir/usr/share/applications/
# Create AppRun
cat > AppDir/AppRun << 'EOF'
#!/bin/bash
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
export PATH="${HERE}/usr/bin/:${PATH}"
export LD_LIBRARY_PATH="${HERE}/usr/lib/:${LD_LIBRARY_PATH}"
exec "${HERE}/usr/bin/openlibextended" "$@"
EOF
chmod +x AppDir/AppRun
# Build AppImage
ARCH=x86_64 ./appimagetool-x86_64.AppImage --no-appstream AppDir artifacts/openlibextended-linux-x64-${{ needs.prepare.outputs.version }}.AppImage
- name: Create tar.gz archive
run: |
cd build/linux/x64/release/bundle
tar -czvf ${{ github.workspace }}/artifacts/openlibextended-linux-x64-${{ needs.prepare.outputs.version }}.tar.gz *
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: linux-builds
path: artifacts/*
retention-days: 7
# Flatpak Build Job (optional, complex)
build-flatpak:
name: Build Flatpak
needs: [prepare, build-linux]
if: ${{ inputs.build_flatpak == true && inputs.build_linux == true }}
runs-on: ubuntu-latest
container:
image: bilelmoussaoui/flatpak-github-actions:freedesktop-24.08
options: --privileged
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Linux build artifacts
uses: actions/download-artifact@v4
with:
name: linux-builds
path: linux-artifacts
- name: Extract Linux bundle
run: |
mkdir -p build/linux/x64/release/bundle
tar -xzf linux-artifacts/openlibextended-linux-x64-${{ needs.prepare.outputs.version }}.tar.gz -C build/linux/x64/release/bundle
- name: Create Flatpak manifest
run: |
cat > dev.wath.openlibextended.yml << EOF
app-id: dev.wath.openlibextended
runtime: org.freedesktop.Platform
runtime-version: '24.08'
sdk: org.freedesktop.Sdk
command: openlibextended
finish-args:
- --share=ipc
- --socket=fallback-x11
- --socket=wayland
- --device=dri
- --share=network
- --filesystem=home
modules:
- name: openlibextended
buildsystem: simple
build-commands:
- cp -r bundle /app/
- ln -s /app/bundle/OpenlibExtended /app/bin/openlibextended
sources:
- type: dir
path: build/linux/x64/release/bundle
dest: bundle
EOF
- name: Build Flatpak
uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
bundle: openlibextended-linux-${{ needs.prepare.outputs.version }}.flatpak
manifest-path: dev.wath.openlibextended.yml
cache-key: flatpak-builder-${{ github.sha }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: flatpak-builds
path: "*.flatpak"
retention-days: 7
# Release job - uploads artifacts to GitHub release
release:
name: Upload to Release
needs: [prepare, build-android, build-ios, build-windows, build-linux]
if: ${{ always() && github.event_name == 'release' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: List artifacts
run: ls -la artifacts/ || echo "No artifacts found"
- name: Upload to Release
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}