Skip to content

Commit dee608b

Browse files
committed
check: pin flutter version
* Introduce a git submodule to pin the version of flutter SDK under `vendor/flutter`. * Use direnv to add `vendor/flutter/bin` to the current PATH so that subsequent calls to `flutter` on the shell uses the our pinned version of flutter. * Update instructions to use pinned version of flutter. * Pin to 18340ea16c of flutter which matches the current lowerbound version in pubsec.yaml (3.21.0-12.0.pre.26). NOTE: Users can still choose to opt-out and use their own version of flutter. This just provides a recommended and tested version on our CI. Closes zulip#15
1 parent 9044a9a commit dee608b

File tree

9 files changed

+128
-20
lines changed

9 files changed

+128
-20
lines changed

.envrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file is used by direnv to setup the environment when entering
2+
# to use vendored flutter SDK.
3+
4+
# Comment out the next line if you want to use your system flutter.
5+
PATH_add vendor/flutter/bin

.github/workflows/ci.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@ jobs:
66
check:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- name: Checkout repository
10+
uses: actions/checkout@v3
1011

11-
- name: Clone Flutter SDK
12+
- name: Checkout flutter submodule
1213
# We can't do a depth-1 clone, because we need the most recent tag
1314
# so that Flutter knows its version and sees the constraint in our
1415
# pubspec is satisfied. It's uncommon for flutter/flutter to go
15-
# more than 100 commits between tags. Fetch 1000 for good measure.
16+
# more than 100 commits between tags. Fetch 1000 for good measure.
17+
# This is also why we don't use the `with submodules` in the
18+
# `checkout` action.
1619
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"
20+
git submodule update --init --depth 1000
21+
22+
- name: Add vendored flutter to PATH
23+
run: |
24+
echo vendor/flutter/bin >> "$GITHUB_PATH"
25+
26+
- name: Run setup
27+
run: tools/setup-vendor-flutter
28+
29+
- name: Display version (Temporary)
30+
run: |
31+
flutter --version
2032
2133
- name: Download Flutter SDK artifacts (flutter precache)
2234
run: flutter precache --universal

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "vendor/flutter"]
2+
path = vendor/flutter
3+
url = https://github.com/flutter/flutter.git
4+
branch = main

.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": ["vendor/flutter"],
2021
}

README.md

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,74 @@ Two specific points to expand on:
9292

9393
### Setting up
9494

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).
99-
3. Ensure Flutter is correctly configured by running `flutter doctor`.
100-
4. Start the app with `flutter run`, or from your IDE.
95+
1. Setup the pinned version of flutter.
96+
(See [Flutter version](#flutter-version) for details on what this
97+
step does and read it if you want to use your own version of
98+
flutter.)
99+
100+
1.1. Make sure you have initialized submodule by doing (do
101+
not do `--depth=1` as flutter relies on tags to know its version):
102+
103+
```sh
104+
# Update and initialize submodule
105+
git submodule update --init
106+
# Run setup-vendor-flutter
107+
./tools/setup-vendor-flutter
108+
```
109+
110+
1.2. Install [direnv][direnv], and set up its hook:
111+
112+
```sh
113+
# For MacOS users, you can use Homebrew:
114+
brew install direnv
115+
116+
# For Linux users, direnv is typically distributed as a package,
117+
# so you can use apt-get (see direnv website for distro-specific
118+
# instructions if this doesn't work):
119+
sudo apt install direnv
120+
121+
# After installation, make sure to run this in the zulip-flutter
122+
# directory to allow the .envrc file.
123+
direnv allow
124+
```
125+
2. Ensure Flutter is correctly configured by running `flutter doctor`.
126+
3. Start the app with `flutter run`, or from your IDE.
127+
If you're using VSCode, you're set.
128+
If you're using Android Studio, please read the next step.
129+
130+
3.1 For Android Studio users only (unless you are using your own
131+
custom version of flutter):
132+
133+
After you first open, the project, go to:
134+
`Settings -> Languages & Frameworks -> Flutter`
135+
Under `Flutter SDK Path`, enter `<REPO_DIR>/vendor/flutter` (where
136+
`<REPO_DIR>` is the location of the checkout of the repo).
101137

102138

103139
### Flutter version
104140

105-
While in the beta phase, we use the latest Flutter from Flutter's
106-
main branch. Use `flutter channel main` and `flutter upgrade`.
141+
We pin to a particular version of flutter SDK via git submodules in
142+
[vendor/flutter/](vendor/flutter/).
143+
If your local checkout of this repository does not have this submodule
144+
checked out at the same commit, the build may fail.
107145

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][].
146+
However, if you want to manage your own flutter SDK version you can
147+
opt out of this behavior by either of:
148+
- Skip installing direnv or don't do `direnv allow`.
149+
- Comment out the lines in `.envrc`.
112150

113-
[issue #15]: https://github.com/zulip/zulip-flutter/issues/15
151+
Do note that if you do this, you need to manually make sure that the
152+
flutter SDK version matches or is compatible with the version
153+
indicated by the submodule commit SHA.
114154

155+
Otherwise, the build can fail as we have not tested the current code
156+
with that particular flutter SDK version.
157+
158+
If you want manage your own flutter SDK version, follow the [Flutter
159+
installation guide](https://docs.flutter.dev/get-started/install) for
160+
your platform of choice.
161+
162+
[direnv]: https://direnv.net/
115163

116164
### Tests
117165

@@ -242,13 +290,16 @@ that's a good prompt to do this. We also do this when there's a
242290
new PR merged that we particularly want to take.
243291

244292
To update the version bounds:
293+
* First, make sure you're on the `main` channel, run:
294+
`flutter channel main`.
245295
* Use `flutter upgrade` to upgrade your local Flutter and Dart.
246296
* Update the lower bounds at `environment` in `pubspec.yaml`
247297
to the new versions, as seen in `flutter --version`.
248298
* Run `flutter pub get`, which will update `pubspec.lock`.
249299
* Make a quick check that things work: `tools/check`,
250300
and do a quick smoke-test of the app.
251-
* Commit and push the changes in `pubspec.yaml` and `pubspec.lock`.
301+
* Commit and push the changes in the submodule `vendor/flutter`,
302+
`pubspec.yaml` and `pubspec.lock`.
252303

253304

254305
### Upgrading dependencies

analysis_options.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
# packages, and plugins designed to encourage good coding practices.
1010
include: package:flutter_lints/flutter.yaml
1111

12+
analyzer:
13+
# Don't analyze code in the `vendor/` directory which contains the flutter
14+
# SDK.
15+
exclude: [vendor/**]
16+
1217
linter:
1318
# The lint rules applied to this project can be customized in the
1419
# section below to disable rules from the `package:flutter_lints/flutter.yaml`

tools/lib/git.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,13 @@ git_base_commit() {
9090
git_changed_files() {
9191
git diff --name-only --diff-filter=d "$@"
9292
}
93+
94+
# Note that this assumes ONE submodule. If we ever have more than one,
95+
# we'll need to generalize this.
96+
submodule_is_clean()
97+
{
98+
# first character of every line status indicates the status of the
99+
# submodule. If there is a space, it means the submodule is clean
100+
# and initiated.
101+
git submodule status | grep -q "^ "
102+
}

tools/setup

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
this_dir=${BASH_SOURCE[0]%/*}
5+
6+
# shellcheck source=tools/lib/git.sh
7+
. "${this_dir}"/lib/git.sh
8+
9+
10+
# One-time setup to let git submodule + flutter SDK know that we're
11+
# using the main channel (main branch).
12+
# We should do a quick check that there's no changes.
13+
if ! submodule_is_clean; then
14+
echo >&2 "There are changes in the submodule or it is not initialized."
15+
echo >&2 "Please run 'git submodule update --init' then run this script again."
16+
exit 1
17+
fi
18+
19+
git -C vendor/flutter checkout -B main HEAD

vendor/flutter

Submodule flutter added at 18340ea

0 commit comments

Comments
 (0)