Skip to content

Commit a4b5060

Browse files
committed
build: pin flutter SDK version
sketch of a .envrc for using fvm's flutter add notes in notice add note to comment out check flutter version update README
1 parent 9044a9a commit a4b5060

File tree

6 files changed

+87
-22
lines changed

6 files changed

+87
-22
lines changed

.envrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is used by direnv to setup the environment when entering to use fvm's flutter.
2+
3+
# Comment out the next line if you want to use your system flutter.
4+
PATH_add .fvm/flutter_sdk/bin
5+
6+
# Check flutter version matches what's in .fvmrc
7+
check_flutter_version() {
8+
local fvm_flutter_version_string=$(cat .fvmrc)
9+
# Fetch string from format `"flutter": "18340ea16c"``
10+
local fvm_flutter_version=$(echo "$fvm_flutter_version_string" | grep -o '"flutter": "[a-z0-9]*"' | cut -d '"' -f 4)
11+
12+
local flutter_version_string=$(flutter --version)
13+
# Fetch string from format `Framework • revision 11c034f037`
14+
local flutter_version=$(echo $flutter_version_string | grep -o 'Framework • revision [a-z0-9]*' | cut -d ' ' -f 4)
15+
16+
if [ "$fvm_flutter_version" != "$flutter_version" ]; then
17+
echo "Flutter version mismatch: $fvm_flutter_version != $flutter_version"
18+
echo "Expected Flutter version: $fvm_flutter_version"
19+
echo "Actual Flutter version: $flutter_version"
20+
echo "Run 'fvm install' to fix this or see README on Setup."
21+
return 1
22+
fi
23+
}
24+
25+
# Check flutter version when entering directory
26+
# Comment this out at your own risk if you want to use a custom flutter version.
27+
check_flutter_version

.fvmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"flutter": "18340ea16c",
3+
"updateVscodeSettings": false
4+
}

.github/workflows/ci.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,32 @@ jobs:
88
steps:
99
- uses: actions/checkout@v3
1010

11-
- name: Clone Flutter SDK
12-
# We can't do a depth-1 clone, because we need the most recent tag
13-
# so that Flutter knows its version and sees the constraint in our
14-
# pubspec is satisfied. It's uncommon for flutter/flutter to go
15-
# more than 100 commits between tags. Fetch 1000 for good measure.
11+
- name: Set up Homebrew
12+
id: set-up-homebrew
13+
uses: Homebrew/actions/setup-homebrew@master
14+
15+
# - name: Clone Flutter SDK
16+
# # We can't do a depth-1 clone, because we need the most recent tag
17+
# # so that Flutter knows its version and sees the constraint in our
18+
# # pubspec is satisfied. It's uncommon for flutter/flutter to go
19+
# # more than 100 commits between tags. Fetch 1000 for good measure.
20+
# run: |
21+
# git clone --depth=1000 https://github.com/flutter/flutter ~/flutter
22+
# TZ=UTC git --git-dir ~/flutter/.git log -1 --format='%h | %ci | %s' --date=iso8601-local
23+
# echo ~/flutter/bin >> "$GITHUB_PATH"
24+
25+
- name: Install FVM
1626
run: |
17-
git clone --depth=1000 https://github.com/flutter/flutter ~/flutter
18-
TZ=UTC git --git-dir ~/flutter/.git log -1 --format='%h | %ci | %s' --date=iso8601-local
19-
echo ~/flutter/bin >> "$GITHUB_PATH"
27+
brew tap leoafarias/fvm
28+
brew install fvm
29+
30+
- name: Install Flutter SDK
31+
run: |
32+
fvm install
33+
fvm use
34+
35+
- name: Load direnv (.envrc)
36+
uses: HatsuneMiku3939/direnv-action@v1
2037

2138
- name: Download Flutter SDK artifacts (flutter precache)
2239
run: flutter precache --universal

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ app.*.map.json
4949

5050
# Old scaffolding hack
5151
lib/credential_fixture.dart
52+
53+
# FVM Version Cache
54+
.fvm/

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717

1818
// This much more focused automatic fix is helpful, though.
1919
"files.trimTrailingWhitespace": true,
20+
"dart.flutterSdkPaths": [".fvm/flutter_sdk"],
2021
}

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,40 @@ Two specific points to expand on:
9191
## Getting started in developing this beta app
9292

9393
### Setting up
94-
95-
1. Follow the [Flutter installation guide](https://docs.flutter.dev/get-started/install)
96-
for your platform of choice.
97-
2. Switch to the latest version of Flutter by running `flutter channel main`
98-
and `flutter upgrade` (see [Flutter version](#flutter-version) below).
94+
1. Install [direnv](https://direnv.net/) and [fvm](https://fvm.app/), for most
95+
users, you can use Homebrew:
96+
97+
```sh
98+
brew install direnv
99+
# Follow instructions for to add the hook https://direnv.net/docs/hook.html
100+
brew tap leoafarias/fvm
101+
brew install fvm
102+
# Close and open a new terminal to ensure that direnv is loaded.
103+
# For any changes in the contents of direnv, and first use, you need to call
104+
# this.
105+
direnv allow
106+
```
107+
108+
> [!NOTE]
109+
> (Advanced Users) If you want to manage own flutter SDK installation, you can skip step 1-2. See below section on [Flutter version](#flutter-version)
110+
111+
2. Run `fvm use` to setup the flutter version.
99112
3. Ensure Flutter is correctly configured by running `flutter doctor`.
100113
4. Start the app with `flutter run`, or from your IDE.
101114

102115

103116
### Flutter version
104117

105-
While in the beta phase, we use the latest Flutter from Flutter's
106-
main branch. Use `flutter channel main` and `flutter upgrade`.
107-
108-
We don't pin a specific version, because Flutter itself doesn't offer
109-
a way to do so. So far that hasn't been a problem. When it becomes one,
110-
we'll figure it out; there are several tools for this in the Flutter
111-
community. See [issue #15][].
112-
113-
[issue #15]: https://github.com/zulip/zulip-flutter/issues/15
118+
We use direnv and fvm to ensure that the version of flutter SDK that you're
119+
using matches what has been tested on CI, and across developer setups.
114120

121+
However, if you want to manage your own flutter SDK version you can opt out of
122+
this behavior.
123+
Do note that if you do this, you need to manually make sure that the flutter SDK
124+
version matches or is compatible with the pinned version in `.fvmrc`. If you
125+
want manage your own flutter SDK version, follow the [Flutter installation
126+
guide](https://docs.flutter.dev/get-started/install) for your platform of
127+
choice.
115128

116129
### Tests
117130

0 commit comments

Comments
 (0)