|
| 1 | +name: Build Flutter Desktop (Multi-Platform) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*.*.*'] # run only when a tag like v1.2.3 is pushed |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + flutter_version: |
| 9 | + description: 'Flutter version (or "latest")' |
| 10 | + required: false |
| 11 | + default: '3.32.2' |
| 12 | + |
| 13 | +env: |
| 14 | + FLUTTER_VERSION: '3.32.2' # Default Flutter version |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-desktop: |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - os: ubuntu-22.04 |
| 22 | + platform: linux |
| 23 | + build-command: flutter build linux --release |
| 24 | + artifact-path: build/linux/x64/release/bundle |
| 25 | + artifact-name: linux-x64.tar.gz |
| 26 | + package-command: tar -czf |
| 27 | + - os: macos-latest |
| 28 | + platform: macos |
| 29 | + build-command: flutter build macos --release |
| 30 | + artifact-path: build/macos/Build/Products/Release |
| 31 | + artifact-name: macos.zip |
| 32 | + package-command: zip -r |
| 33 | + - os: windows-latest |
| 34 | + platform: windows |
| 35 | + build-command: flutter build windows --release |
| 36 | + artifact-path: build/windows/x64/runner/Release |
| 37 | + artifact-name: windows-x64.zip |
| 38 | + package-command: Compress-Archive -Path * -DestinationPath |
| 39 | + fail-fast: false # Continue other builds even if one fails |
| 40 | + |
| 41 | + runs-on: ${{ matrix.os }} |
| 42 | + |
| 43 | + steps: |
| 44 | + # 1. Check-out source |
| 45 | + - name: Checkout repository |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + # 2. Install Flutter |
| 49 | + - name: Setup Flutter |
| 50 | + uses: subosito/flutter-action@v2 |
| 51 | + with: |
| 52 | + channel: stable |
| 53 | + flutter-version: ${{ inputs.flutter_version || env.FLUTTER_VERSION }} |
| 54 | + cache: true # Enable caching for faster builds |
| 55 | + |
| 56 | + # 3. Install Linux dependencies (Linux only) |
| 57 | + - name: Install Linux dependencies |
| 58 | + if: matrix.platform == 'linux' |
| 59 | + run: | |
| 60 | + sudo apt-get update -y |
| 61 | + sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev libsecret-1-dev |
| 62 | +
|
| 63 | + # 4. Configure Flutter |
| 64 | + - name: Configure Flutter |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + flutter config --no-analytics |
| 68 | + flutter config --enable-${{ matrix.platform }}-desktop |
| 69 | +
|
| 70 | + # 5. Accept SDK licenses non-interactively |
| 71 | + - name: Accept licenses (Windows) |
| 72 | + if: matrix.platform == 'windows' |
| 73 | + run: | |
| 74 | + $input = "y`n" * 100 |
| 75 | + $input | flutter doctor --android-licenses |
| 76 | + exit 0 |
| 77 | + shell: pwsh |
| 78 | + continue-on-error: true |
| 79 | + |
| 80 | + - name: Accept licenses (Linux/macOS) |
| 81 | + if: matrix.platform != 'windows' |
| 82 | + run: | |
| 83 | + yes | flutter doctor --android-licenses || true |
| 84 | + shell: bash |
| 85 | + continue-on-error: true |
| 86 | + |
| 87 | + # 6. Cache pub dependencies |
| 88 | + - name: Cache pub dependencies |
| 89 | + uses: actions/cache@v4 |
| 90 | + with: |
| 91 | + path: | |
| 92 | + ~/.pub-cache |
| 93 | + ${{ runner.os == 'Windows' && '%LOCALAPPDATA%\Pub\Cache' || '' }} |
| 94 | + key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }} |
| 95 | + restore-keys: | |
| 96 | + ${{ runner.os }}-pub- |
| 97 | +
|
| 98 | + # 7. Install project dependencies |
| 99 | + - name: Install dependencies |
| 100 | + run: flutter pub get |
| 101 | + |
| 102 | + # 8. Generate localization and other required files |
| 103 | + - name: Generate required files |
| 104 | + run: dart run build_runner build -d |
| 105 | + |
| 106 | + # 9. Extract version from pubspec.yaml |
| 107 | + - name: Extract version |
| 108 | + id: extract_version |
| 109 | + shell: bash |
| 110 | + run: | |
| 111 | + version=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r') |
| 112 | + if [[ -z "$version" ]]; then |
| 113 | + echo "ERROR: Could not extract version from pubspec.yaml" |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | + echo "VERSION=$version" >> $GITHUB_ENV |
| 117 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 118 | + echo "Version: $version" |
| 119 | +
|
| 120 | + # 10. Analyze code (optional) |
| 121 | + - name: Analyze code |
| 122 | + run: flutter analyze --fatal-infos |
| 123 | + continue-on-error: true |
| 124 | + |
| 125 | + # 11. Build for platform |
| 126 | + - name: Build ${{ matrix.platform }} release |
| 127 | + run: ${{ matrix.build-command }} |
| 128 | + |
| 129 | + # 12. Verify build output exists |
| 130 | + - name: Verify build output |
| 131 | + shell: bash |
| 132 | + run: | |
| 133 | + if [ ! -d "${{ matrix.artifact-path }}" ]; then |
| 134 | + echo "ERROR: Build output not found at ${{ matrix.artifact-path }}" |
| 135 | + exit 1 |
| 136 | + fi |
| 137 | + echo "✅ Build output verified at ${{ matrix.artifact-path }}" |
| 138 | +
|
| 139 | + # 13. Package Linux build |
| 140 | + - name: Package Linux build |
| 141 | + if: matrix.platform == 'linux' |
| 142 | + run: | |
| 143 | + mkdir -p ./dist |
| 144 | + tar -czf ./dist/mostro_mobile-${{ steps.extract_version.outputs.version }}-${{ matrix.artifact-name }} \ |
| 145 | + -C ${{ matrix.artifact-path }} . |
| 146 | +
|
| 147 | + # 14. Package build (macOS) |
| 148 | + - name: Package macOS build |
| 149 | + if: matrix.platform == 'macos' |
| 150 | + run: | |
| 151 | + mkdir -p ./dist |
| 152 | + find ${{ matrix.artifact-path }} -name "*.app" -type d | head -1 | xargs -I {} \ |
| 153 | + zip -r ./dist/mostro_mobile-${{ steps.extract_version.outputs.version }}-${{ matrix.artifact-name }} {} |
| 154 | +
|
| 155 | + # 15. Package build (Windows) |
| 156 | + - name: Package Windows build |
| 157 | + if: matrix.platform == 'windows' |
| 158 | + shell: pwsh |
| 159 | + run: | |
| 160 | + if (-not (Test-Path "./dist")) { New-Item -ItemType Directory -Path "./dist" | Out-Null } |
| 161 | + Compress-Archive -Path "${{ matrix.artifact-path }}/*" ` |
| 162 | + -DestinationPath "./dist/mostro_mobile-${{ steps.extract_version.outputs.version }}-${{ matrix.artifact-name }}" |
| 163 | + |
| 164 | + # 16. Upload as artifact |
| 165 | + - name: Upload ${{ matrix.platform }} artifact |
| 166 | + uses: actions/upload-artifact@v4 |
| 167 | + with: |
| 168 | + name: ${{ matrix.platform }}-release |
| 169 | + path: ./dist/mostro_mobile-${{ steps.extract_version.outputs.version }}-${{ matrix.artifact-name }} |
| 170 | + |
| 171 | + # 17. Create GitHub Release and upload |
| 172 | + - name: Create GitHub Release |
| 173 | + uses: ncipollo/release-action@v1 |
| 174 | + with: |
| 175 | + artifacts: "./dist/mostro_mobile-${{ steps.extract_version.outputs.version }}-${{ matrix.artifact-name }}" |
| 176 | + tag: v${{ steps.extract_version.outputs.version }} |
| 177 | + name: "Release v${{ steps.extract_version.outputs.version }}" |
| 178 | + body: | |
| 179 | + ## Desktop Builds - v${{ steps.extract_version.outputs.version }} |
| 180 | + |
| 181 | + **Platform**: ${{ matrix.platform }} |
| 182 | + **Flutter Version**: ${{ inputs.flutter_version || env.FLUTTER_VERSION }} |
| 183 | + **Build Date**: ${{ github.event.head_commit.timestamp }} |
| 184 | + allowUpdates: true |
| 185 | + omitBodyDuringUpdate: false |
| 186 | + replacesArtifacts: true |
| 187 | + draft: false |
| 188 | + prerelease: false |
| 189 | + |
0 commit comments