Skip to content

Commit

Permalink
Merge pull request #2236 from get10101/chore/fvm
Browse files Browse the repository at this point in the history
chore: introduce fvm (flutter version manager)
  • Loading branch information
bonomat authored Mar 18, 2024
2 parents 1c879e3 + 228c112 commit e76604e
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 67 deletions.
45 changes: 45 additions & 0 deletions .github/actions/setup-fvm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Setup Flutter FVM Environment
description: "Setup FVM, Flutter for building Flutter apps."

inputs:
fvm_config:
description: "Path to fvm config file."
required: false
working_dir:
description: "The directory to run these steps in"
required: false

runs:
using: composite
steps:
- uses: kuhnroyal/flutter-fvm-config-action@v2
id: fvm-config-action
with:
path: ${{ inputs.fvm_config }}

- uses: subosito/flutter-action@v2
with:
cache: true
flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }}
channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }}

- name: install fvm (linux)
if: runner.os == 'Linux'
shell: bash
working-directory: ${{inputs.working_dir}}
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew tap leoafarias/fvm
brew install fvm
echo "/home/linuxbrew/.linuxbrew/bin" >> $GITHUB_PATH
fvm install
- name: install fvm (macos)
if: runner.os == 'macOS'
shell: bash
working-directory: ${{inputs.working_dir}}
run: |
brew tap leoafarias/fvm
brew install fvm
echo "/opt/homebrew/bin" >> $GITHUB_PATH
fvm install
12 changes: 3 additions & 9 deletions .github/workflows/android-fastlane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ on:
description: "The public key of the oracle. Must match with the public key returned at http://${oracle_endpoint}/oracle/publickey"
type: string

env:
FLUTTER_VERSION: "3.19.1"

jobs:
build:
runs-on: macos-latest
Expand All @@ -76,13 +73,10 @@ jobs:
- name: List used Xcode version
run: /usr/bin/xcodebuild -version

- uses: subosito/flutter-action@v2
- uses: ./.github/actions/setup-fvm
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
cache-key: flutter-${{ env.FLUTTER_VERSION }}-macos-latest
cache-path: ${{ runner.tool_cache }}/flutter
fvm_config: ./mobile/.fvmrc
working_dir: ./mobile

- uses: actions/cache@v4
id: cache-deps
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build-release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:


env:
FLUTTER_VERSION: "3.19.1"
RUST_VERSION: "1.70.0"

jobs:
Expand Down
33 changes: 14 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
env:
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
FLUTTER_VERSION: "3.19.1"

jobs:
formatting-dprint:
Expand All @@ -27,13 +26,10 @@ jobs:
- name: Setup rust toolchain
run: rustup show
- uses: Swatinem/[email protected]
- uses: subosito/flutter-action@v2
- uses: ./.github/actions/setup-fvm
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
cache-key: flutter-${{ env.FLUTTER_VERSION }}
cache-path: ${{ runner.tool_cache }}/flutter
fvm_config: ./mobile/.fvmrc
working_dir: ./mobile
- name: Install FFI bindings
run: just deps-gen
- name: Generate FFI bindings
Expand Down Expand Up @@ -94,13 +90,15 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: extractions/setup-just@v1
- uses: subosito/flutter-action@v2
- uses: ./.github/actions/setup-fvm
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
cache-key: flutter-${{ env.FLUTTER_VERSION }}
cache-path: ${{ runner.tool_cache }}/flutter
fvm_config: ./mobile/.fvmrc
working_dir: ./mobile

- uses: ./.github/actions/setup-fvm
with:
fvm_config: ./webapp/frontend/.fvmrc
working_dir: ./webapp/frontend
- name: Download Dart mocks directory
uses: actions/download-artifact@v2
with:
Expand All @@ -127,13 +125,10 @@ jobs:
- name: Setup rust toolchain
run: rustup show
- uses: Swatinem/[email protected]
- uses: subosito/flutter-action@v2
- uses: ./.github/actions/setup-fvm
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
cache-key: flutter-${{ env.FLUTTER_VERSION }}
cache-path: ${{ runner.tool_cache }}/flutter
fvm_config: ./mobile/.fvmrc
working_dir: ./mobile
- name: Download Rust generated FFI flutter bindings
uses: actions/download-artifact@v2
with:
Expand Down
11 changes: 3 additions & 8 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:

env:
REGISTRY: ghcr.io
FLUTTER_VERSION: "3.19.1"

jobs:
docker:
Expand Down Expand Up @@ -63,14 +62,10 @@ jobs:
- uses: extractions/setup-just@v1
if: matrix.bin == 'webapp'

- uses: subosito/flutter-action@v2
if: matrix.bin == 'webapp'
- uses: ./.github/actions/setup-fvm
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
cache-key: flutter-${{ env.FLUTTER_VERSION }}
cache-path: ${{ runner.tool_cache }}/flutter
fvm_config: ./webapp/frontend/.fvmrc
working_dir: ./webapp/frontend

- name: build flutter for webapp
if: matrix.bin == 'webapp'
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/ios-fastlane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ on:
description: "For regtest enter 'test' or mainnet enter 'Runner'"
type: string

env:
FLUTTER_VERSION: "3.19.1"

jobs:
build:
runs-on: macos-14
Expand All @@ -96,13 +93,10 @@ jobs:
- name: List used Xcode version
run: /usr/bin/xcodebuild -version

- uses: subosito/flutter-action@v2
- uses: ./.github/actions/setup-fvm
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
cache-key: flutter-${{ env.FLUTTER_VERSION }}-macos-14
cache-path: ${{ runner.tool_cache }}/flutter
fvm_config: ./mobile/.fvmrc
working_dir: ./mobile

- name: Check cocoapods version
run: /usr/local/bin/pod --version
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ mobile/ios/fastlane/README.md

# esplora override environment variables
.override.esplora.env

.fvm/
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
To begin, ensure that you have a working installation of the following items:

- [Docker](https://docs.docker.com/) and docker-compose
- [Flutter SDK](https://docs.flutter.dev/get-started/install)
- [Flutter Version Manager (FVM)](https://fvm.app/)
- [Rust language](https://rustup.rs/)
- Appropriate [Rust targets](https://rust-lang.github.io/rustup/cross-compilation.html) for cross-compiling to your device
- For Android targets:
Expand All @@ -28,6 +28,16 @@ echo "ANDROID_NDK=.." >> ~/.gradle/gradle.properties
- XCode
- Cocoapods

## FVM (Flutter Version Manager)

We use FVM to be able to easily switch between different Flutter versions.
Make sure to install it locally.
Once installed, you can use your favorite flutter commands as before, just add `fvm` before, e.g.

```bash
fvm flutter run
```

You can see whether you have all the sufficient dependencies for your platform by running `flutter doctor`.

## Contributing
Expand Down
38 changes: 19 additions & 19 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ gen:
#!/usr/bin/env bash
set -euxo pipefail
cd mobile
flutter pub get
fvm flutter pub get
RUST_LOG={{ rust_log_for_frb }} flutter_rust_bridge_codegen \
--rust-input native/src/api.rs \
--c-output ios/Runner/bridge_generated.h \
Expand All @@ -80,13 +80,13 @@ android-release:

# Build flutter webapp for cargo run --bin webapp
build-web args="":
cd webapp/frontend && flutter build web --web-renderer html {{args}}
cd webapp/frontend && fvm flutter build web {{args}}

build-web-release:
cd webapp/frontend && flutter build web --web-renderer html --release
cd webapp/frontend && fvm flutter build web --release

run-web:
cd webapp/frontend && flutter run -d chrome --web-browser-flag "--disable-web-security"
cd webapp/frontend && fvm flutter run -d chrome --web-browser-flag "--disable-web-security"

# Build Rust library for iOS (debug mode)
ios:
Expand All @@ -102,7 +102,7 @@ ios-release:
run args="":
#!/usr/bin/env bash
cd mobile && \
flutter run {{args}} \
fvm flutter run {{args}} \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="REGTEST_FAUCET=http://localhost:8080" \
Expand All @@ -113,7 +113,7 @@ run args="":
run-regtest args="":
#!/usr/bin/env bash
cd mobile && \
flutter run {{args}} \
fvm flutter run {{args}} \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ELECTRS_ENDPOINT={{public_regtest_electrs}}" \
Expand All @@ -126,7 +126,7 @@ run-regtest args="":
run-mainnet args="":
#!/usr/bin/env bash
cd mobile && \
flutter run {{args}} \
fvm flutter run {{args}} \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ELECTRS_ENDPOINT=http://api.10101.finance:3000" \
Expand All @@ -140,7 +140,7 @@ run-mainnet args="":
run-regtest-android args="":
#!/usr/bin/env bash
cd mobile && \
flutter run {{args}} \
fvm flutter run {{args}} \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ELECTRS_ENDPOINT={{public_regtest_electrs}}" \
Expand All @@ -156,7 +156,7 @@ run-local-android args="":
LOCAL_IP=$({{get_local_ip}})
echo "Android app will connect to $LOCAL_IP for 10101 services"
cd mobile && \
flutter run {{args}} \
fvm flutter run {{args}} \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ELECTRS_ENDPOINT=http://${LOCAL_IP}:5050" \
Expand All @@ -178,7 +178,7 @@ clean:
set -euxo pipefail
cd mobile
rm -rf mobile/android/app/src/main/jniLibs/*
flutter clean
fvm flutter clean
cd native && cargo clean
# Wipes everything
Expand Down Expand Up @@ -260,8 +260,8 @@ cargo-clippy:
cargo clippy --all-targets -- -D warnings

lint-flutter:
cd mobile && flutter analyze --fatal-infos .
cd webapp/frontend && flutter analyze --fatal-infos .
cd mobile && fvm flutter analyze --fatal-infos .
cd webapp/frontend && fvm flutter analyze --fatal-infos .

alias flutter-lint := lint-flutter

Expand Down Expand Up @@ -307,7 +307,7 @@ maker args="":
docker run {{run_maker_args}}

flutter-test:
cd mobile && flutter pub run build_runner build --delete-conflicting-outputs && flutter test
cd mobile && fvm flutter pub run build_runner build --delete-conflicting-outputs && fvm flutter test

# Tests for the `native` crate
native-test:
Expand Down Expand Up @@ -460,7 +460,7 @@ build-ipa args="":
args+=(--flavor test)
fi

cd mobile && flutter build ipa "${args[@]}" \
cd mobile && fvm flutter build ipa "${args[@]}" \
--dart-define="ELECTRS_ENDPOINT=${ELECTRS_ENDPOINT}" \
--dart-define="COORDINATOR_P2P_ENDPOINT=${COORDINATOR_P2P_ENDPOINT}" \
--dart-define="NETWORK=${NETWORK}" \
Expand All @@ -483,15 +483,15 @@ publish-testflight-fastlane:
release-testflight: gen ios build-ipa publish-testflight

version:
cargo --version && rustc --version && flutter --version
cargo --version && rustc --version && fvm flutter --version

build-apk-regtest:
#!/usr/bin/env bash
BUILD_NAME=$(yq -r .version {{pubspec}})
BUILD_NUMBER=$(git rev-list HEAD --count)
echo "build name: ${BUILD_NAME}"
echo "build number: ${BUILD_NUMBER}"
cd mobile && flutter build apk \
cd mobile && fvm flutter build apk \
--build-name=${BUILD_NAME} \
--build-number=${BUILD_NUMBER} \
--release \
Expand All @@ -512,7 +512,7 @@ build-app-bundle-regtest:
BUILD_NUMBER=$(git rev-list HEAD --count)
echo "build name: ${BUILD_NAME}"
echo "build number: ${BUILD_NUMBER}"
cd mobile && flutter build appbundle \
cd mobile && fvm flutter build appbundle \
--build-name=${BUILD_NAME} \
--build-number=${BUILD_NUMBER} \
--release \
Expand Down Expand Up @@ -544,7 +544,7 @@ build-android-app-bundle:
os={{os()}}
echo "building on '$os' for '$NETWORK'"

cd mobile && flutter build appbundle \
cd mobile && fvm flutter build appbundle \
--build-name=${BUILD_NAME} \
--build-number=${BUILD_NUMBER} \
--release \
Expand Down Expand Up @@ -576,7 +576,7 @@ build-android-app-apk args="":
os={{os()}}
echo "building on '$os' for '$NETWORK'"

cd mobile && flutter build apk {{args}} \
cd mobile && fvm flutter build apk {{args}} \
--build-name=${BUILD_NAME} \
--build-number=${BUILD_NUMBER} \
--release \
Expand Down
3 changes: 3 additions & 0 deletions mobile/.fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "stable"
}
1 change: 0 additions & 1 deletion webapp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ doc/api/
### Flutter ###
# Flutter/Dart/Pub related
**/doc/api/
.fvm/flutter_sdk
.pub-cache/
.pub/
coverage/
Expand Down
3 changes: 3 additions & 0 deletions webapp/frontend/.fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "beta"
}

0 comments on commit e76604e

Please sign in to comment.