Skip to content

Commit 81363a8

Browse files
chrisirhcgnprice
authored andcommitted
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 #15
1 parent fcd74e6 commit 81363a8

File tree

10 files changed

+125
-21
lines changed

10 files changed

+125
-21
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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ jobs:
66
check:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- name: Check out repository
10+
uses: actions/checkout@v3
11+
# We're not using `with: submodules` here because we can't do a
12+
# depth=1 clone. See below for more details.
1013

11-
- name: Clone Flutter SDK
14+
- name: Checkout flutter submodule
1215
# We can't do a depth-1 clone, because we need the most recent tag
1316
# so that Flutter knows its version and sees the constraint in our
1417
# pubspec is satisfied. It's uncommon for flutter/flutter to go
15-
# more than 100 commits between tags. Fetch 1000 for good measure.
18+
# more than 100 commits between tags. Fetch 1000 for good measure.
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
2028

2129
- name: Download Flutter SDK artifacts (flutter precache)
2230
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: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,75 @@ 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+
97+
1.1. Make sure you have initialized submodule by doing:
98+
99+
```sh
100+
# Update and initialize submodule
101+
git submodule update --init
102+
# Run setup-vendor-flutter
103+
tools/setup-vendor-flutter
104+
```
105+
106+
1.2. Install [direnv][direnv], and set up its hook:
107+
108+
```sh
109+
# On Debian or Ubuntu (bash):
110+
sudo apt install direnv && echo 'eval "$(direnv hook bash)"' >>~/.bashrc
111+
112+
# Or using Homebrew:
113+
brew install direnv
114+
115+
# Or see: https://direnv.net/docs/installation.html
116+
# Then: https://direnv.net/docs/hook.html
117+
118+
# After installing and setting up the hook, run this in the zulip-flutter
119+
# directory to allow the .envrc file.
120+
direnv allow
121+
```
122+
123+
1.3. Follow remaining instructions in [Flutter installation guide](https://docs.flutter.dev/get-started/install)
124+
for your platform of choice. You can skip the Flutter SDK installation as that is now done.
125+
126+
2. Ensure Flutter is correctly configured by running `flutter doctor`.
127+
3. Start the app with `flutter run`, or from your IDE.
128+
If you're using VSCode, you're set.
129+
If you're using Android Studio, please read the next step.
130+
131+
3.1 For Android Studio users only (unless you are using your own
132+
custom version of flutter):
133+
134+
After you first open, the project, go to:
135+
`Settings -> Languages & Frameworks -> Flutter`
136+
Under `Flutter SDK Path`, enter `<REPO_DIR>/vendor/flutter` (where
137+
`<REPO_DIR>` is the location of the checkout of the repo).
101138
102139
103140
### Flutter version
104141
105-
While in the beta phase, we use the latest Flutter from Flutter's
106-
main branch. Use `flutter channel main` and `flutter upgrade`.
142+
We pin to a particular version of flutter SDK via git submodules in
143+
[vendor/flutter/](vendor/flutter/).
144+
If your local checkout of this repository does not have this submodule
145+
checked out at the same commit, the build may fail.
146+
147+
However, if you want to manage your own flutter SDK version you can
148+
opt out of this behavior by either of:
149+
- Skip installing direnv or don't do `direnv allow`.
150+
- Comment out the lines in `.envrc`.
151+
152+
Do note that if you do this, you need to manually make sure that the
153+
flutter SDK version matches or is compatible with the version
154+
indicated by the submodule commit SHA.
107155

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][].
156+
Otherwise, the build can fail as we have not tested the current code
157+
with that particular flutter SDK version.
112158

113-
[issue #15]: https://github.com/zulip/zulip-flutter/issues/15
159+
If you want manage your own flutter SDK version, follow the [Flutter
160+
installation guide](https://docs.flutter.dev/get-started/install) for
161+
your platform of choice.
114162

163+
[direnv]: https://direnv.net/
115164

116165
### Tests
117166

@@ -242,13 +291,16 @@ that's a good prompt to do this. We also do this when there's a
242291
new PR merged that we particularly want to take.
243292
244293
To update the version bounds:
294+
* First, make sure you're on the `main` channel, run:
295+
`flutter channel main`.
245296
* Use `flutter upgrade` to upgrade your local Flutter and Dart.
246297
* Update the lower bounds at `environment` in `pubspec.yaml`
247298
to the new versions, as seen in `flutter --version`.
248299
* Run `flutter pub get`, which will update `pubspec.lock`.
249300
* Make a quick check that things work: `tools/check`,
250301
and do a quick smoke-test of the app.
251-
* Commit and push the changes in `pubspec.yaml` and `pubspec.lock`.
302+
* Commit and push the changes in the submodule `vendor/flutter`,
303+
`pubspec.yaml` and `pubspec.lock`.
252304

253305

254306
### Upgrading dependencies

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ analyzer:
1212
# TODO(pigeon) re-enable lints once clean: https://github.com/flutter/flutter/issues/145633
1313
- lib/host/*.g.dart
1414

15+
# Skip analysis on `vendor/`, which has outside code like the Flutter SDK.
16+
- vendor/**
17+
1518
linter:
1619
# For a list of all available lints, with docs, see:
1720
# https://dart-lang.github.io/linter/lints/index.html.

tools/check

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ run_icons() {
353353

354354
run_shellcheck() {
355355
# Omitted from this check: nothing (nothing known, anyway).
356-
files_check tools/ '!*.'{dart,js,json} \
356+
files_check tools/ '!*.'{dart,js,json} .envrc \
357357
|| return 0
358358

359359
# Shellcheck is fast, <1s; so if we touched any possible targets at all,
@@ -362,6 +362,7 @@ run_shellcheck() {
362362
targets=(
363363
$(git grep -l '#!.*sh\b' -- tools/)
364364
$(git ls-files -- tools/'*.sh')
365+
.envrc
365366
)
366367

367368
if ! type shellcheck >/dev/null 2>&1; then

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-vendor-flutter

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 "vendor/flutter" ; then
14+
echo >&2 "There are changes in 'vendor/flutter' tree 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 b019842

0 commit comments

Comments
 (0)