Skip to content

Flutter Build

Flutter Build #2

Workflow file for this run

name: Flutter Build
on:
workflow_dispatch:
push:
branches-ignore:
- main
paths:
- 'lib/**'
env:
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
STORE_FILE: '../keystore.jks'
jobs:
update_version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Update version in pubspec.yaml
run: |
# Read the current version from pubspec.yaml
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //;s/+.*//')
echo "Current Version: $VERSION"
# Split the version into major, minor, and patch components
IFS='.' read -r major minor patch <<< "$VERSION"
# Check if the patch version is 9
if [ "$patch" -eq 9 ]; then
# If yes, increment the minor version and reset the patch version to 0
new_minor=$((minor + 1))
new_version="$major.$new_minor.0"
else
# Otherwise, simply increment the patch version
new_patch=$((patch + 1))
new_version="$major.$minor.$new_patch"
fi
echo "New Version: $new_version"
# Update pubspec.yaml with the new version
sed -i "s/^version: .*/version: $new_version/" pubspec.yaml
# Update msix_version in the msix_config section
msix_version="$new_version.0"
sed -i "s/msix_version: .*/msix_version: $msix_version/" pubspec.yaml
# Indicate that the versions have been updated
echo "The version in pubspec.yaml has been updated to $new_version and msix_version to $msix_version."
- name: Commit changes
if: github.ref == 'refs/heads/main'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add pubspec.yaml
git commit -m "Update version to $new_version"
git push
build-ubuntu:
runs-on: ubuntu-latest
needs: [update_version]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y wget curl xz-utils git>=2.0 bash unzip bash zip
- name: Install Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- name: Install jq
run: |
wget -O jq https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64
chmod +x ./jq
mv jq /usr/local/bin
- name: Install Android SDK Command Line Tools
run: |
wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O commandlinetools.zip
mkdir -p $HOME/android-sdk/cmdline-tools/latest
unzip commandlinetools.zip -d $HOME/android-sdk/cmdline-tools/latest
mv $HOME/android-sdk/cmdline-tools/latest/cmdline-tools/* $HOME/android-sdk/cmdline-tools/latest/
export ANDROID_HOME=$HOME/android-sdk
echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$PATH
echo "PATH=$PATH" >> $GITHUB_ENV
- name: Accept Android SDK Licenses
run: |
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses || true
- name: Install Android SDK Packages
run: |
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.2" || true
- name: Add exception
run: git config --global --add safe.directory /opt/hostedtoolcache/flutter/*
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.27.1
- name: Install Flutter dependencies
run: flutter pub get
- name: Build Flutter web
run: flutter build web --release
- name: Zip the web directory
run: |
zip -r web-release.zip build/web/
- name: Change base href for GitHub Pages
run: |
sed -i 's|<base href="/">|<base href="/abs_flutter/">|' build/web/index.html
- name: upload page artifact
uses: actions/upload-pages-artifact@v3
with:
path: build/web
- name: Setup Keystore
run: echo "${{ secrets.STORE }}" | base64 -d > android/keystore.jks
- name: Build APK
run: flutter build apk --release
- name: Build AppBundle
run: flutter build appbundle --release
- name: Move APK and AAB files
run: |
mv build/app/outputs/flutter-apk/app-release.apk app-release.apk
mv build/app/outputs/bundle/release/app-release.aab app-release.aab
- name: Upload APK, AAB, and Web Artifacts
uses: actions/upload-artifact@v4
with:
name: ubuntu-build-artifacts
path: |
app-release.apk
app-release.aab
web-release.zip
- name: Upload single APK file
uses: actions/upload-artifact@v4
with:
name: android-apk
path: app-release.apk
- name: Clean up
if: always()
run: |
sudo rm -rf build
sudo rm -rf android/keystore.jks
build-windows:
runs-on: windows-latest
needs: [update_version]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.27.1
- name: Extract version from pubspec.yaml
id: extract_version
shell: pwsh
run: |
$versionLine = Get-Content pubspec.yaml | Select-String -Pattern '^version:'
$version = $versionLine -replace 'version: ', '' -replace '\+.*', ''
echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install Flutter dependencies
run: flutter pub get
- name: Build Flutter Windows
run: flutter build windows --release
- name: Zip the Release folder
run: |
Compress-Archive -Path "build/windows/x64/runner/Release" -DestinationPath "windows-Release-${{ env.VERSION }}.zip"
- name: Create MSIX package
run: dart run msix:create
- name: Move MSIX file
run: |
$sourcePath = "build/windows/x64/runner/Release/abs_flutter.msix"
$destinationPath = "windows-installer-release-${{ env.VERSION }}.msix"
Move-Item -Path $sourcePath -Destination $destinationPath
shell: pwsh
- name: Create MSIX package (Store)
run: dart run msix:create --store
- name: Move MSIX file
run: |
$sourcePath = "build/windows/x64/runner/Release/abs_flutter.msix"
$destinationPath = "windows-installer-release-${{ env.VERSION }}-store.msix"
Move-Item -Path $sourcePath -Destination $destinationPath
shell: pwsh
- name: Upload Windows Build and MSIX Artifacts
uses: actions/upload-artifact@v4
with:
name: windows-build-artifacts
path: |
windows-Release-${{ env.VERSION }}.zip
windows-installer-release-${{ env.VERSION }}.msix
windows-installer-release-${{ env.VERSION }}-store.msix
- name: Upload single MSIX file
uses: actions/upload-artifact@v4
with:
name: windows-msix
path: windows-installer-release-${{ env.VERSION }}.msix
- name: Upload single MSIX file
uses: actions/upload-artifact@v4
with:
name: windows-zip
path: windows-Release-${{ env.VERSION }}.zip
build-linux:
runs-on: ubuntu-latest
needs: [update_version]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.27.1
- name: Install Flutter dependencies
run: flutter pub get
- name: Install linux dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y curl git unzip xz-utils zip libglu1-mesa
sudo apt-get install -y libayatana-appindicator3-dev
sudo apt-get install -y ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswresample-dev
sudo apt-get install -y libmpv-dev mpv
sudo apt-get install -y clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev
sudo apt-get install -y fuse libfuse2
sudo apt-get install -y libsecret-1-dev xdg-user-dirs
sudo modprobe fuse
sudo groupadd fuse || true
sudo usermod -a -G fuse $USER
- name: Build Flutter linux
run: flutter build linux --release
- name: Zip the linux build directory
run: |
cd build/linux/x64/release/bundle
zip -r linux-release.zip .
mv linux-release.zip ../../../../../
cd ../../../../../
- name: Extract version from pubspec.yaml
id: extract_version
run: |
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //;s/+.*//')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Download AppImage builder
run: |
wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O appimagetool
chmod +x appimagetool
- name: Prepare AppDir
run: |
mkdir -p AppDir/usr/bin
mkdir -p AppDir/usr/share/applications
mkdir -p AppDir/usr/share/icons/hicolor/256x256/apps
mkdir -p AppDir/usr/lib
cp -r build/linux/x64/release/bundle/* AppDir/usr/bin/
cp /usr/lib/x86_64-linux-gnu/libsecret-1.so* AppDir/usr/lib/ || true
cp assets/images/logo/logo_blue_big_abs.png AppDir/usr/share/icons/hicolor/256x256/apps/io.github.vito0912.abs_flutter.png
cp assets/images/logo/logo_blue_big_abs.png AppDir/io.github.vito0912.abs_flutter.png
cat > AppDir/io.github.vito0912.abs_flutter.desktop << EOL
[Desktop Entry]
Name=Buchable
Comment=Enjoy hearing self-hosted audiobooks.
Exec=buchable
Type=Application
Icon=io.github.vito0912.abs_flutter.png
Terminal=false
Keywords=Audiobook,Player,Audiobookshelf,Listen;
Categories=Audio;AudioVideo;Player;
MimeType=audio/*;video/*;
X-GNOME-UsesNotifications=true
StartupWMClass=buchable
EOL
cp AppDir/io.github.vito0912.abs_flutter.desktop AppDir/usr/share/applications/
cat > AppDir/AppRun << EOL
#!/bin/sh
SELF=\$(readlink -f "\$0")
HERE=\${SELF%/*}
export PATH="\${HERE}/usr/bin:\${PATH}"
export LD_LIBRARY_PATH="\${HERE}/usr/lib:\${LD_LIBRARY_PATH}"
export XDG_DATA_DIRS="\${HERE}/usr/share:\${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
export XDG_CONFIG_DIRS="\${HERE}/etc/xdg:\${XDG_CONFIG_DIRS:-/etc/xdg}"
exec "\${HERE}/usr/bin/abs_flutter" "\$@"
EOL
chmod +x AppDir/AppRun
- name: Build AppImage
run: |
# Extract appimagetool first to avoid FUSE requirement
./appimagetool --appimage-extract
ARCH=x86_64 ./squashfs-root/AppRun AppDir buchable-${{ env.VERSION }}-x86_64.AppImage
- name: Upload Linux build artifacts
uses: actions/upload-artifact@v4
with:
name: linux-build-artifacts
path: |
linux-release.zip
buchable-${{ env.VERSION }}-x86_64.AppImage
create-release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
needs: [build-ubuntu, build-windows, build-linux]
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Ubuntu Artifacts
uses: actions/download-artifact@v4
with:
name: ubuntu-build-artifacts
path: ./ubuntu-artifacts
- name: Download Windows Artifacts
uses: actions/download-artifact@v4
with:
name: windows-build-artifacts
path: ./windows-artifacts
- name: Download Linux Artifacts
uses: actions/download-artifact@v4
with:
name: linux-build-artifacts
path: ./linux-artifacts
- name: Extract version from pubspec.yaml
id: extract_version
run: |
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //;s/+.*//')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Rename app-release.apk
run: |
mv ubuntu-artifacts/app-release.apk ubuntu-artifacts/android-release-${{ env.VERSION }}.apk
mv ubuntu-artifacts/app-release.aab ubuntu-artifacts/android-release-${{ env.VERSION }}.aab
mv ubuntu-artifacts/web-release.zip ubuntu-artifacts/web-release-${{ env.VERSION }}.zip
mv linux-artifacts/linux-release.zip linux-artifacts/linux-release.zip
mv linux-artifacts/buchable-${{ env.VERSION }}-x86_64.AppImage linux-artifacts/buchable-${{ env.VERSION }}-x86_64.AppImage || true
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ env.VERSION }}
name: Release v${{ env.VERSION }}
draft: false
generate_release_notes: true
prerelease: true
files: |
ubuntu-artifacts/android-release-${{ env.VERSION }}.apk
ubuntu-artifacts/android-release-${{ env.VERSION }}.aab
ubuntu-artifacts/web-release-${{ env.VERSION }}.zip
windows-artifacts/windows-Release-${{ env.VERSION }}.zip
windows-artifacts/windows-installer-release-${{ env.VERSION }}.msix
windows-artifacts/windows-installer-release-${{ env.VERSION }}-store.msix
linux-artifacts/linux-release.zip
linux-artifacts/buchable-${{ env.VERSION }}-x86_64.AppImage
publish-release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
needs: [create-release]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Ubuntu Artifacts
uses: actions/download-artifact@v4
with:
name: ubuntu-build-artifacts
path: ./ubuntu-build-artifacts
- name: Move AAB file
run: |
mv ubuntu-build-artifacts/app-release.aab app-release.aab
- name: Extract version from pubspec.yaml
id: extract_version
run: |
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //;s/+.*//')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Publish to Play Store
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
packageName: de.vito.absapp.abs_flutter
releaseFiles: app-release.aab
track: beta
status: completed
releaseName: v${{ env.VERSION }}
inAppUpdatePriority: 2
whatsNewDirectory: android/whatsnew
continue-on-error: true
deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
needs: build-ubuntu
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4