Skip to content

Commit 1dafbec

Browse files
authored
update build workflow with upload option for releases
Added option to upload artifacts to GitHub Release based on tag existence.
1 parent c0abfab commit 1dafbec

1 file changed

Lines changed: 22 additions & 31 deletions

File tree

.github/workflows/build.yml

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ on:
3939
required: false
4040
default: false
4141
type: boolean
42+
upload_to_release:
43+
description: "Upload artifacts to GitHub Release (if tag exists)"
44+
required: false
45+
default: false
46+
type: boolean
4247

4348
env:
4449
FLUTTER_VERSION: "3.38.6"
4550

4651
jobs:
47-
# Shared setup job to prepare version info
4852
prepare:
4953
name: Prepare Build
5054
runs-on: ubuntu-latest
@@ -72,7 +76,8 @@ jobs:
7276
TAG_VERSION="${TAG_VERSION}.0"
7377
fi
7478
75-
if [[ ! "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
79+
# Accept prereleases like 1.4.1-beta1
80+
if [[ ! "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
7681
echo "Error: Invalid version format: $TAG_VERSION"
7782
exit 1
7883
fi
@@ -82,7 +87,6 @@ jobs:
8287
echo "build_number=$BUILD_NUMBER" >> $GITHUB_OUTPUT
8388
echo "Version: $TAG_VERSION+$BUILD_NUMBER"
8489
85-
# Android Build Job
8690
build-android:
8791
name: Build Android
8892
needs: prepare
@@ -125,11 +129,11 @@ jobs:
125129
if [ -n "$KEYSTORE_BASE64" ]; then
126130
echo "$KEYSTORE_BASE64" | base64 --decode > android/app/upload-keystore.jks
127131
cat > android/key.properties << EOF
128-
storeFile=${{ github.workspace }}/android/app/upload-keystore.jks
129-
keyAlias=$KEY_ALIAS
130-
storePassword=$STORE_PASSWORD
131-
keyPassword=$KEY_PASSWORD
132-
EOF
132+
storeFile=${{ github.workspace }}/android/app/upload-keystore.jks
133+
keyAlias=$KEY_ALIAS
134+
storePassword=$STORE_PASSWORD
135+
keyPassword=$KEY_PASSWORD
136+
EOF
133137
fi
134138

135139
- name: Get dependencies
@@ -147,7 +151,6 @@ jobs:
147151
- name: Prepare artifacts
148152
run: |
149153
mkdir -p artifacts
150-
# Naming convention: contains "android" and architecture keywords for update_checker detection
151154
cp build/app/outputs/flutter-apk/app-release.apk artifacts/openlibextended-android-universal-${{ needs.prepare.outputs.version }}.apk
152155
cp build/app/outputs/flutter-apk/app-arm64-v8a-release.apk artifacts/openlibextended-android-arm64-${{ needs.prepare.outputs.version }}.apk
153156
cp build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk artifacts/openlibextended-android-armeabi-v7a-${{ needs.prepare.outputs.version }}.apk
@@ -160,7 +163,6 @@ jobs:
160163
path: artifacts/*.apk
161164
retention-days: 7
162165

163-
# iOS Build Job
164166
build-ios:
165167
name: Build iOS
166168
needs: prepare
@@ -210,7 +212,6 @@ jobs:
210212
path: artifacts/*.ipa
211213
retention-days: 7
212214

213-
# Windows Build Job
214215
build-windows:
215216
name: Build Windows
216217
needs: prepare
@@ -239,10 +240,7 @@ jobs:
239240

240241
- name: Create installer with Inno Setup
241242
run: |
242-
# Download Inno Setup
243243
choco install innosetup -y
244-
245-
# Create Inno Setup script
246244
@"
247245
[Setup]
248246
AppName=OpenlibExtended
@@ -266,7 +264,6 @@ jobs:
266264
[Run]
267265
Filename: "{app}\OpenlibExtended.exe"; Description: "Launch OpenlibExtended"; Flags: nowait postinstall skipifsilent
268266
"@ | Out-File -FilePath "installer.iss" -Encoding UTF8
269-
270267
mkdir artifacts
271268
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" installer.iss
272269
@@ -277,7 +274,6 @@ jobs:
277274
path: artifacts/*.exe
278275
retention-days: 7
279276

280-
# Linux Build Job
281277
build-linux:
282278
name: Build Linux
283279
needs: prepare
@@ -308,23 +304,15 @@ jobs:
308304
- name: Create AppImage
309305
run: |
310306
mkdir -p artifacts
311-
312-
# Download appimagetool
313307
wget -q https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
314308
chmod +x appimagetool-x86_64.AppImage
315-
316-
# Create AppDir structure
317309
mkdir -p AppDir/usr/{bin,lib,share/applications,share/icons/hicolor/256x256/apps}
318310
cp -r build/linux/x64/release/bundle/* AppDir/usr/bin/
319-
# Rename the binary in AppDir if created with old case, mostly for safety but check build output first
320311
if [ -f "AppDir/usr/bin/OpenlibExtended" ]; then
321312
mv AppDir/usr/bin/OpenlibExtended AppDir/usr/bin/openlibextended
322313
fi
323-
324314
cp assets/icons/appIcon_foreground.png AppDir/usr/share/icons/hicolor/256x256/apps/openlibextended.png
325315
cp assets/icons/appIcon_foreground.png AppDir/openlibextended.png
326-
327-
# Create desktop entry
328316
cat > AppDir/openlibextended.desktop << 'EOF'
329317
[Desktop Entry]
330318
Name=OpenlibExtended
@@ -336,8 +324,6 @@ jobs:
336324
Keywords=books;library;epub;pdf;reader;
337325
EOF
338326
cp AppDir/openlibextended.desktop AppDir/usr/share/applications/
339-
340-
# Create AppRun
341327
cat > AppDir/AppRun << 'EOF'
342328
#!/bin/bash
343329
SELF=$(readlink -f "$0")
@@ -347,8 +333,6 @@ jobs:
347333
exec "${HERE}/usr/bin/openlibextended" "$@"
348334
EOF
349335
chmod +x AppDir/AppRun
350-
351-
# Build AppImage
352336
ARCH=x86_64 ./appimagetool-x86_64.AppImage --no-appstream AppDir artifacts/openlibextended-linux-x64-${{ needs.prepare.outputs.version }}.AppImage
353337
354338
- name: Create tar.gz archive
@@ -363,7 +347,6 @@ jobs:
363347
path: artifacts/*
364348
retention-days: 7
365349

366-
# Flatpak Build Job (optional, complex)
367350
build-flatpak:
368351
name: Build Flatpak
369352
needs: [prepare, build-linux]
@@ -428,11 +411,10 @@ jobs:
428411
path: "*.flatpak"
429412
retention-days: 7
430413

431-
# Release job - uploads artifacts to GitHub release
432414
release:
433415
name: Upload to Release
434416
needs: [prepare, build-android, build-ios, build-windows, build-linux]
435-
if: ${{ always() && github.event_name == 'release' }}
417+
if: ${{ (github.event_name == 'release') || (inputs.upload_to_release == true) }}
436418
runs-on: ubuntu-latest
437419
permissions:
438420
contents: write
@@ -446,7 +428,16 @@ jobs:
446428
- name: List artifacts
447429
run: ls -la artifacts/ || echo "No artifacts found"
448430

431+
- name: Check if tag exists
432+
id: tagcheck
433+
run: |
434+
tag="v${{ needs.prepare.outputs.version }}"
435+
if git ls-remote --tags origin | grep -q "refs/tags/$tag"; then
436+
echo "upload_ok=true" >> $GITHUB_OUTPUT
437+
else
438+
echo "upload_ok=false" >> $GITHUB_OUTPUT
449439
- name: Upload to Release
440+
if: steps.tagcheck.outputs.upload_ok == 'true'
450441
uses: softprops/action-gh-release@v2
451442
with:
452443
files: |

0 commit comments

Comments
 (0)