Skip to content

Commit

Permalink
chore: Move to fvm for handling Flutter version
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon committed Aug 14, 2024
1 parent 7064881 commit a730f36
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.22.3"
}
16 changes: 0 additions & 16 deletions .github/scripts/check-outdated-files.sh

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v2
- run: melos analyze --fatal-infos

format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v2
- run: melos format:exclude

mocks:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v3
- run: melos generate
- name: Check for outdated mocks
Expand All @@ -48,7 +48,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v2
- run: melos gen-l10n
- name: Check for outdated l10n
Expand All @@ -68,7 +68,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v2
- run: sudo apt update && sudo apt install -y lcov
- run: melos coverage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v3
- run: sudo apt update
- run: sudo apt install -y clang cmake debhelper libblkid-dev libglib2.0-dev libgtk-3-dev liblzma-dev network-manager ninja-build packagekit pkg-config polkitd xvfb
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pubspec.lock
/build/
coverage/
/doc/
.fvm
**/build/

# Symbolication related
Expand All @@ -50,3 +49,6 @@ app.*.map.json

# Melos generated files
**/pubspec_overrides.yaml

# FVM Version Cache
.fvm/
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

9 changes: 7 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ Translations are managed using [Weblate](https://hosted.weblate.org/projects/ubu

### Required dependencies

[Install Flutter](https://flutter.dev/docs/get-started/install/linux) - the currently used version is specified in `.tool-versions`. If you're using [asdf](https://asdf-vm.com/) to manage your Flutter SDK, you can simply run `asdf install` to install the required version.
[Install Flutter](https://flutter.dev/docs/get-started/install/linux) - the currently used version is specified in `.fvmrc`. If you're using [fvm](https://fvm.app) to manage your Flutter SDK, you can simply run `fvm install` to install the required version.

Install the [Flutter Linux prerequisites](https://docs.flutter.dev/get-started/install/linux#linux-prerequisites)

We provide a [Melos](https://docs.page/invertase/melos) configuration to make it straightforward to execute common tasks.

Install fvm (you can also install it from the scripts directory in the repository):
```
curl -fsSL https://fvm.app/install.sh | bash
```

Install Melos:
```
dart pub global activate melos
Expand All @@ -92,7 +97,7 @@ melos bootstrap

You can run the application with
```
flutter run
fvm flutter run
```

and build a release version with
Expand Down
17 changes: 9 additions & 8 deletions melos.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: app_center
sdkPath: .fvm/flutter_sdk

packages:
- packages/**
Expand All @@ -16,12 +17,12 @@ scripts:
# build all packages
build: >
melos exec -c 1 --fail-fast --flutter --dir-exists=linux -- \
flutter build linux
fvm flutter build linux
# collect coverage information for all packages
coverage: >
melos exec -c 1 --fail-fast --dir-exists=test -- \
flutter test --coverage && melos run coverage:cleanup
fvm flutter test --coverage && melos run coverage:cleanup
# cleanup generated files from coverage
coverage:cleanup: >
Expand All @@ -43,27 +44,27 @@ scripts:
! -path '*/l10n/*.dart' \
! -name '*.pb*.dart' \
! -path '*/.*/*' \
| xargs dart format --set-exit-if-changed
| xargs fvm dart format --set-exit-if-changed

# run build_runner to generate code in all packages
generate: >
melos exec -c 1 --fail-fast --depends-on=build_runner -- \
dart run build_runner build --delete-conflicting-outputs
fvm dart run build_runner build --delete-conflicting-outputs
# run gen-l10n to generate localizations in all packages
gen-l10n: >
melos exec -c 1 --fail-fast --depends-on=flutter_localizations -- \
flutter gen-l10n
fvm flutter gen-l10n
# run integration tests in all packages
integration_test: >
melos exec -c 1 --fail-fast --dir-exists=integration_test -- \
flutter test integration_test
fvm flutter test integration_test
# runs "flutter pub <arg(s)>" in all packages
pub: melos exec -c 1 -- flutter pub "$@"
pub: melos exec -c 1 -- fvm flutter pub "$@"

# run tests in all packages
test: >
melos exec -c 1 --fail-fast --dir-exists=test -- \
flutter test
fvm flutter test
3 changes: 3 additions & 0 deletions packages/app_center/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# FVM Version Cache
.fvm/
10 changes: 5 additions & 5 deletions packages/app_center/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
flutter_html: ^3.0.0-beta.2
flutter_localizations:
sdk: flutter
flutter_markdown: ^0.6.16
flutter_markdown: ^0.7.3+1
flutter_riverpod: ^2.5.1
flutter_svg: ^2.0.10+1
freezed_annotation: ^2.4.1
Expand All @@ -32,22 +32,22 @@ dependencies:
gtk: ^2.1.0
handy_window: ^0.4.0
http: ^1.2.1
intl: ^0.18.1
intl: ^0.19.0
jwt_decode: ^0.3.1
meta: ^1.11.0
package_info_plus: ^4.2.0
package_info_plus: ^8.0.2
packagekit: ^0.2.6
path: ^1.9.0
riverpod_annotation: ^2.3.5
shimmer: ^3.0.0
snapcraft_launcher: ^0.1.0
snapd: ^0.6.3
snowball_stemmer: ^0.1.0
ubuntu_localizations: ^0.3.6
ubuntu_localizations: ^0.4.0
ubuntu_logger: ^0.1.1
ubuntu_service: ^0.3.2
ubuntu_test: ^0.1.0-beta.9
ubuntu_widgets: ^0.5.0
ubuntu_widgets: ^0.6.0
url_launcher: ^6.2.6
xdg_directories: ^1.0.4
yaru: ^4.1.0
Expand Down
117 changes: 117 additions & 0 deletions scripts/install_fvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash

# Function to log messages with date and time
log_message() {
echo -e "$1"
}

# Detect OS and architecture
OS="$(uname -s)"
ARCH="$(uname -m)"

# Map to FVM naming
case "$OS" in
Linux*) OS='linux' ;;
Darwin*) OS='macos' ;;
*) log_message "Unsupported OS"; exit 1 ;;
esac

case "$ARCH" in
x86_64) ARCH='x64' ;;
arm64) ARCH='arm64' ;;
armv7l) ARCH='arm' ;;
*) log_message "Unsupported architecture"; exit 1 ;;
esac

# Terminal colors setup
Color_Off='\033[0m' # Reset
Green='\033[0;32m' # Green
Red='\033[0;31m'

success() {
log_message "${Green}$1${Color_Off}"
}

error() {
log_message "${Red}error: $1${Color_Off}" >&2
exit 1
}

# Log detected OS and architecture
log_message "Detected OS: $OS"
log_message "Detected Architecture: $ARCH"

# Check for curl
if ! command -v curl &> /dev/null; then
error "curl is required but not installed."
fi

# Get installed FVM version if exists
INSTALLED_FVM_VERSION=""
if command -v fvm &> /dev/null; then
INSTALLED_FVM_VERSION=$(fvm --version 2>&1) || error "Failed to fetch installed FVM version."
fi

# Define the URL of the FVM binary
if [ -z "$1" ]; then
FVM_VERSION=$(curl -s https://api.github.com/repos/leoafarias/fvm/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$FVM_VERSION" ]; then
error "Failed to fetch latest FVM version."
fi
else
FVM_VERSION="$1"
fi

log_message "Installing FVM version $FVM_VERSION."

# Setup installation directory and symlink
FVM_DIR="$HOME/.fvm_flutter"
FMV_DIR_BIN="$FVM_DIR/bin"
SYMLINK_TARGET="/usr/local/bin/fvm"


# Create FVM directory if it doesn't exist
mkdir -p "$FVM_DIR" || error "Failed to create FVM directory: $FVM_DIR."

# Check if FVM_DIR exists, and if it does delete it
if [ -d "$FMV_DIR_BIN" ]; then
log_message "FVM bin directory already exists. Removing it."
if ! rm -rf "$FMV_DIR_BIN"; then
error "Failed to remove existing FVM directory: $FMV_DIR_BIN."
fi
fi

# Download FVM
URL="https://github.com/leoafarias/fvm/releases/download/$FVM_VERSION/fvm-$FVM_VERSION-$OS-$ARCH.tar.gz"
if ! curl -L "$URL" -o fvm.tar.gz; then
error "Download failed. Check your internet connection and URL: $URL"
fi


# Extract binary to the new location
if ! tar xzf fvm.tar.gz -C "$FVM_DIR" 2>&1; then
error "Extraction failed. Check permissions and tar.gz file integrity."
fi

# Cleanup
if ! rm -f fvm.tar.gz; then
error "Failed to cleanup"
fi

# Rename FVM_DIR/fvm to FVM_DIR/bin
if ! mv "$FVM_DIR/fvm" "$FMV_DIR_BIN"; then
error "Failed to move fvm to bin directory."
fi

# Create a symlink
if ! ln -sf "$FMV_DIR_BIN/fvm" "$SYMLINK_TARGET"; then
error "Failed to create symlink."
fi

# Verify installation
if ! command -v fvm &> /dev/null; then
error "Installation verification failed. FVM may not be in PATH or failed to execute."
fi

INSTALLED_FVM_VERSION=$(fvm --version 2>&1) || error "Failed to verify installed FVM version."
success "FVM $INSTALLED_FVM_VERSION installed successfully."
7 changes: 3 additions & 4 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ parts:
rm -rf "flutter"
fi
craftctl default
FLUTTER_VERSION=$(sed -n "s/^flutter \([0-9.]\+\).*/\1/p" .tool-versions)
git clone -b $FLUTTER_VERSION --depth 1 https://github.com/flutter/flutter.git
sh scripts/install-flutter.sh
fvm install
override-build: |
mkdir -p $CRAFT_PART_INSTALL/usr/bin
mkdir -p $CRAFT_PART_INSTALL/usr/libexec
cp -r $CRAFT_PART_SRC/flutter $CRAFT_PART_INSTALL/usr/libexec/flutter
cp -r $CRAFT_PART_SRC/.fvm/flutter_sdk $CRAFT_PART_INSTALL/usr/libexec/flutter
ln -s $CRAFT_PART_INSTALL/usr/libexec/flutter/bin/flutter $CRAFT_PART_INSTALL/usr/bin/flutter
ln -s $CRAFT_PART_INSTALL/usr/libexec/flutter/bin/dart $CRAFT_PART_INSTALL/usr/bin/dart
$CRAFT_PART_INSTALL/usr/bin/flutter doctor
Expand Down

0 comments on commit a730f36

Please sign in to comment.