Skip to content

Instantly share code, notes, and snippets.

@mikemilla
Created October 1, 2024 03:15
Show Gist options
  • Select an option

  • Save mikemilla/4224408b500bd4cf491f8ff0920214aa to your computer and use it in GitHub Desktop.

Select an option

Save mikemilla/4224408b500bd4cf491f8ff0920214aa to your computer and use it in GitHub Desktop.

Revisions

  1. mikemilla created this gist Oct 1, 2024.
    54 changes: 54 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/bin/bash

    # Ask which version to build πŸ€”
    read -p "Which version do you want to build? (1 for dev, 2 for prod): " version_choice
    case $version_choice in
    1) version="dev" ;;
    2) version="prod" ;;
    *)
    while [[ "$version_choice" != "1" && "$version_choice" != "2" ]]; do
    read -p "❌ Invalid input. Please enter '1' for dev or '2' for prod: " version_choice
    done
    case $version_choice in
    1) version="dev" ;;
    2) version="prod" ;;
    esac
    ;;
    esac

    # Function to increment build number πŸ”’
    increment_build_number() {
    local pubspec_file="pubspec.yaml"
    local current_version=$(grep 'version:' $pubspec_file | awk '{print $2}')
    local version_parts=(${current_version//./ })
    local build_number=${version_parts[2]#*+}
    local new_build_number=$((build_number + 1))
    local new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]%%+*}+$new_build_number"

    sed -i '' "s/^version: .*/version: $new_version/" $pubspec_file
    echo "πŸŽ‰ Build number incremented to $new_build_number πŸŽ‰"
    }

    # Increment build number
    increment_build_number

    # Ask which apps to build πŸ“±
    read -p "Build iOS app? (y/n): " build_ios
    read -p "Build Android app? (y/n): " build_android

    # Build selected apps πŸš€
    if [[ "$build_ios" == "y" ]]; then
    echo "🍎 Building iOS app for $version..."
    flutter build ipa --release --flavor $version --target lib/main_$version.dart
    echo "πŸ“‚ Opening Xcode Organizer..."
    open build/ios/archive/Runner.xcarchive
    fi

    if [[ "$build_android" == "y" ]]; then
    echo "πŸ€– Building Android app for $version..."
    flutter build appbundle --release --flavor $version --target lib/main_$version.dart
    echo "πŸ“‚ Opening Android build folder..."
    open build/app/outputs/bundle/$version"Release"
    fi

    echo "🎊 Build process completed! 🎊"