Skip to content

Commit b8c4043

Browse files
committed
check: pin flutter SDK version
Use direnv and flutter to enforce and validate a pinned version of flutter. This approach uses `direnv` and `fvm` to setup the environment with the pinned version of the repo. When setup correctly, `direnv` will turn on `fvm`'s pinned flutter version whenever entering the zulip-flutter repository (directory). The `.envrc` does the following: - Use fvm's flutter version if it's available. - Check that whether the flutter binary version matches what was pinned for the repo. - Let users know if there's a mismatch of version so that the user can take action. Other notes: - Power users can: - use their checked out flutter sdk (either their own custom path, configured in .envrc, or the system default) - disable the check if they know what they're doing and want to use a custom flutter installation
1 parent 9044a9a commit b8c4043

File tree

6 files changed

+88
-23
lines changed

6 files changed

+88
-23
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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ 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: Install FVM
16+
run: |
17+
brew tap leoafarias/fvm
18+
brew install fvm
19+
20+
- name: Install Flutter SDK
1621
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"
22+
fvm install
23+
fvm use
24+
25+
- name: Load direnv (.envrc)
26+
uses: HatsuneMiku3939/direnv-action@v1
2027

2128
- name: Download Flutter SDK artifacts (flutter precache)
2229
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: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,50 @@ 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+
> [!NOTE]
95+
> (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)
96+
97+
1. Install [direnv][direnv] and [fvm][fvm], for most
98+
users, you can use Homebrew:
99+
100+
```sh
101+
brew install direnv
102+
# Follow instructions for to add the hook https://direnv.net/docs/hook.html
103+
brew tap leoafarias/fvm
104+
brew install fvm
105+
# Close and open a new terminal to ensure that direnv is loaded.
106+
# For any changes in the contents of direnv, and first use, you need to call
107+
# this.
108+
direnv allow
109+
```
110+
2. Run `fvm use` to setup the flutter version.
99111
3. Ensure Flutter is correctly configured by running `flutter doctor`.
100112
4. Start the app with `flutter run`, or from your IDE.
101113

102114

103115
### Flutter version
104116

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
114-
117+
We use [direnv][direnv] and [fvm][fvm] to ensure that the version of flutter SDK
118+
that you're using matches what has been tested on CI, and across developer
119+
setups.
120+
The Flutter version pinned for the current build is in the [.fvmrc](.fvmrc)
121+
file under the `flutter` key. It can either be a hash like
122+
[`18340ea16c`](https://github.com/flutter/flutter/commit/18340ea16c) or a
123+
version number like `3.21.0-11.0.pre`.
124+
125+
However, if you want to manage your own flutter SDK version you can opt out of
126+
this behavior.
127+
Do note that if you do this, you need to manually make sure that the flutter SDK
128+
version matches or is compatible with the pinned version in `.fvmrc`. Otherwise,
129+
the build can fail as we have not tested the current code with that particular
130+
flutter SDK version.
131+
132+
If you want manage your own flutter SDK version, follow the [Flutter
133+
installation guide](https://docs.flutter.dev/get-started/install) for your
134+
platform of choice.
135+
136+
[direnv]: https://direnv.net/
137+
[fvm]: https://fvm.app/
115138

116139
### Tests
117140

0 commit comments

Comments
 (0)