|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +concurrency: |
| 7 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 8 | + cancel-in-progress: true |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + changes: |
| 15 | + name: Detect affected packages |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + flutter: ${{ steps.detect.outputs.flutter }} |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Setup Dart |
| 26 | + uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c # v1.7.1 |
| 27 | + with: |
| 28 | + sdk: stable |
| 29 | + |
| 30 | + - name: Detect affected packages |
| 31 | + id: detect |
| 32 | + run: | |
| 33 | + set -euo pipefail |
| 34 | +
|
| 35 | + dart pub global activate melos |
| 36 | +
|
| 37 | + BASE="${{ github.event.pull_request.base.sha }}" |
| 38 | +
|
| 39 | + FORCE_ALL=false |
| 40 | + if [ -z "$BASE" ]; then |
| 41 | + FORCE_ALL=true |
| 42 | + elif git diff --name-only "$BASE...HEAD" \ |
| 43 | + | grep -qE '^(\.github/workflows/build\.yml|melos\.yaml|pubspec\.lock|infra/)'; then |
| 44 | + FORCE_ALL=true |
| 45 | + fi |
| 46 | +
|
| 47 | + if [ "$FORCE_ALL" = "true" ]; then |
| 48 | + echo "Running all packages." |
| 49 | + CHANGED=$(melos list --json | jq -r '.[].name') |
| 50 | + else |
| 51 | + CHANGED=$(melos list --json --diff="$BASE...HEAD" --include-dependents | jq -r '.[].name') |
| 52 | + fi |
| 53 | +
|
| 54 | + echo "Affected packages:" |
| 55 | + echo "$CHANGED" |
| 56 | +
|
| 57 | + if echo "$CHANGED" | grep -qx "supabase_flutter"; then |
| 58 | + echo "flutter=true" >> "$GITHUB_OUTPUT" |
| 59 | + else |
| 60 | + echo "flutter=false" >> "$GITHUB_OUTPUT" |
| 61 | + fi |
| 62 | +
|
| 63 | + build-flutter: |
| 64 | + name: Build on ${{ matrix.os }} |
| 65 | + needs: changes |
| 66 | + if: ${{ needs.changes.outputs.flutter == 'true' }} |
| 67 | + timeout-minutes: 30 |
| 68 | + strategy: |
| 69 | + fail-fast: false |
| 70 | + matrix: |
| 71 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 72 | + |
| 73 | + defaults: |
| 74 | + run: |
| 75 | + working-directory: packages/supabase_flutter |
| 76 | + |
| 77 | + runs-on: ${{ matrix.os }} |
| 78 | + |
| 79 | + steps: |
| 80 | + - name: Checkout repository |
| 81 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 82 | + |
| 83 | + - name: Setup Flutter |
| 84 | + uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 # v2.23.0 |
| 85 | + with: |
| 86 | + flutter-version: '3.x' |
| 87 | + channel: 'stable' |
| 88 | + # Caching 3.x (latest stable) is flaky: the cached SDK contains |
| 89 | + # runner-image-specific binaries that break silently when the runner |
| 90 | + # image is updated. |
| 91 | + cache: false |
| 92 | + |
| 93 | + - name: Show Flutter version |
| 94 | + run: flutter --version |
| 95 | + |
| 96 | + - name: Bootstrap workspace |
| 97 | + run: | |
| 98 | + cd ../../ |
| 99 | + dart pub global activate melos |
| 100 | + melos bootstrap |
| 101 | +
|
| 102 | + - name: Build web app |
| 103 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 104 | + run: | |
| 105 | + cd example |
| 106 | + flutter build web |
| 107 | +
|
| 108 | + - name: Build Linux app |
| 109 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 110 | + run: | |
| 111 | + sudo apt-get update |
| 112 | + sudo apt-get install -y libgtk-3-dev libblkid-dev liblzma-dev |
| 113 | + cd example |
| 114 | + flutter build linux |
| 115 | +
|
| 116 | + - name: Build Android app |
| 117 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 118 | + run: | |
| 119 | + cd example |
| 120 | + flutter build apk |
| 121 | +
|
| 122 | + - name: Build macOS app |
| 123 | + if: ${{ matrix.os == 'macos-latest' }} |
| 124 | + run: | |
| 125 | + cd example |
| 126 | + flutter build macos |
| 127 | +
|
| 128 | + - name: Build iOS app |
| 129 | + if: ${{ matrix.os == 'macos-latest' }} |
| 130 | + run: | |
| 131 | + cd example |
| 132 | + flutter build ios --no-codesign |
| 133 | +
|
| 134 | + - name: Build Windows app |
| 135 | + if: ${{ matrix.os == 'windows-latest' }} |
| 136 | + run: | |
| 137 | + cd example |
| 138 | + flutter build windows |
| 139 | +
|
| 140 | + build-result: |
| 141 | + name: Build result |
| 142 | + needs: [changes, build-flutter] |
| 143 | + if: ${{ always() }} |
| 144 | + runs-on: ubuntu-latest |
| 145 | + steps: |
| 146 | + - name: Verify all jobs succeeded |
| 147 | + run: | |
| 148 | + if ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}; then |
| 149 | + echo "One or more jobs failed or were cancelled." |
| 150 | + exit 1 |
| 151 | + fi |
| 152 | + echo "All required jobs passed or were skipped." |
0 commit comments