Skip to content

Commit 5845038

Browse files
Merge branch 'test-latest-dart-and-flutter'
2 parents e0541e4 + 429f321 commit 5845038

File tree

4 files changed

+142
-72
lines changed

4 files changed

+142
-72
lines changed
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ on:
1212
permissions:
1313
contents: read
1414

15+
env:
16+
# Do code analysis with latest SDK.
17+
# Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new SDKs.
18+
FLUTTER_VERSION: 3.29.2 # Available versions: https://docs.flutter.dev/release/archive
19+
DART_VERSION: 3.7.2 # Available versions: https://dart.dev/get-dart/archive
20+
1521
jobs:
16-
analyze:
22+
analyze-and-format:
1723
runs-on: ubuntu-24.04
1824
steps:
1925
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
20-
# Prefer running on Ubuntu over Dart Docker image
21-
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 # v1.6.5
26+
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # v2.16.0
2227
with:
23-
sdk: 3.5.2
28+
flutter-version: ${{ env.FLUTTER_VERSION }}
29+
cache: true
2430
- name: Get dependencies
2531
run: |
2632
dart pub get --directory=benchmark
@@ -40,7 +46,12 @@ jobs:
4046
dart analyze objectbox
4147
dart analyze objectbox_test
4248
- name: Check formatting of all packages
43-
run: dart format --set-exit-if-changed --fix .
49+
# Since Dart 3.7, dart format needs pub get to run before formatting,
50+
# so to check formatting of Flutter packages run pub get for them first.
51+
run: |
52+
flutter pub get --directory=flutter_libs
53+
flutter pub get --directory=sync_flutter_libs
54+
dart format --set-exit-if-changed .
4455
4556
pana:
4657
runs-on: ubuntu-24.04
@@ -63,7 +74,7 @@ jobs:
6374
exit 1
6475
fi
6576
66-
coverage:
77+
test-coverage:
6778
runs-on: ubuntu-24.04
6879
permissions:
6980
checks: write # to publish the report
@@ -72,7 +83,7 @@ jobs:
7283
# Prefer running on Ubuntu over Dart Docker image
7384
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 # v1.6.5
7485
with:
75-
sdk: 3.5.2
86+
sdk: ${{ env.DART_VERSION }}
7687
- name: Install coverage tools
7788
run: |
7889
./tool/apt-install.sh lcov
Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and test
1+
name: Test
22

33
# Avoid duplicate builds for pull requests, allow manual trigger.
44
on:
@@ -8,40 +8,53 @@ on:
88
pull_request:
99
workflow_dispatch:
1010

11+
# Minimal access by default
12+
permissions:
13+
contents: read
14+
1115
defaults:
1216
run:
1317
shell: bash
1418

15-
# Minimal access by default
16-
permissions:
17-
contents: read
19+
env:
20+
# Run generator integration tests and init script with latest SDK.
21+
# Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new SDKs.
22+
# NOTE: also update matrix configurations below!
23+
FLUTTER_VERSION: 3.29.2 # Available versions: https://docs.flutter.dev/release/archive
24+
DART_VERSION: 3.7.2 # Available versions: https://dart.dev/get-dart/archive
1825

1926
jobs:
20-
generator:
27+
28+
# Runs generator integration tests, e.g. ensures generator works as expected.
29+
# Note: no need to test oldest SDK here, generator package is also built as part of unit-tests job.
30+
generator-integ-tests:
2131
runs-on: ubuntu-24.04
2232
steps:
2333
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
2434
# Prefer running on Ubuntu over Dart Docker image
2535
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 # v1.6.5
2636
with:
27-
sdk: 3.5.2
37+
sdk: ${{ env.DART_VERSION }}
2838
- name: Install ObjectBox C library
2939
run: ./install.sh --install # Install globally for generator integration tests
3040
- name: Integration test
3141
run: ./generator/test.sh
3242

33-
# make sure the init script doesn't stop working - it's not something we usually run during normal development
43+
# Check the init script works - it's not something we usually run during normal development.
44+
# The init script gets dependencies for all packages and runs code generation for those that
45+
# need it.
3446
init-script:
3547
runs-on: ubuntu-24.04
3648
steps:
3749
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
3850
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # v2.16.0
3951
with:
40-
flutter-version: 3.24.2
52+
flutter-version: ${{ env.FLUTTER_VERSION }}
4153
cache: true
4254
- run: ./tool/init.sh
4355

44-
lib:
56+
# Runs generator and objectbox unit tests
57+
unit-tests:
4558
strategy:
4659
fail-fast: false # To see all Dart SDKs that fail, also sometimes with more helpful errors.
4760
matrix:
@@ -50,11 +63,12 @@ jobs:
5063
- macos-13
5164
- ubuntu-24.04
5265
sdk:
53-
# Always include lowest supported version (see sdk key in objectbox and generator
54-
# pubspec.yaml, but may be higher due to dependencies).
55-
- 3.5.2
56-
- 3.4.4
57-
- 2.18.6
66+
# Test latest available and lowest supported SDK (see dev-doc/updating-dart-flutter-and-dependencies.md).
67+
# Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new SDKs.
68+
# Can not use env variables here, only within 'steps'.
69+
# For available versions see https://dart.dev/get-dart/archive
70+
- 3.7.2
71+
- 2.18.6 # Use latest bugfix release to get tooling fixes
5872
runs-on: ${{ matrix.os }}
5973
steps:
6074
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 # v1.6.5
@@ -82,20 +96,22 @@ jobs:
8296
export OBX_IN_MEMORY=true
8397
../tool/pub.sh run test --concurrency=1
8498
85-
flutter-integration-test:
99+
# Builds a mobile and a desktop release of the main Flutter examples
100+
flutter-examples:
86101
strategy:
87102
fail-fast: false
88103
matrix:
89104
os:
90105
- macos-13
91106
- ubuntu-24.04
92-
- windows-2022 # Flutter 2.9 and newer need Visual Studio 2022 to build desktop.
107+
- windows-2022 # Flutter 2.9 and newer need Visual Studio 2022 to build for desktop
93108
flutter-version:
94-
# Include lowest working version (use lowest tested Dart SDK as a guideline, see lib tests
95-
# above; but may be higher due to dependency conflicts)
96-
# https://docs.flutter.dev/development/tools/sdk/releases lists included Dart SDK.
97-
- 3.24.2
98-
- 3.7.12
109+
# Test latest available and lowest supported SDK (see dev-doc/updating-dart-flutter-and-dependencies.md).
110+
# Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new SDKs.
111+
# Can not use env variables here, only within 'steps'.
112+
# For available versions see https://docs.flutter.dev/release/archive
113+
- 3.29.2
114+
- 3.7.12 # Use latest bugfix release to get tooling fixes
99115
runs-on: ${{ matrix.os }}
100116
steps:
101117
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

.gitlab-ci.yml

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
stages:
2-
- analyze
2+
- code-analysis
33
- test
4+
- test-coverage
45

56
variables:
6-
# Note: use specific tags as docker images may not always be pulled due to "if-not-present" pull policy.
7-
# Thus, do not use tags like latest/beta, but check https://hub.docker.com/_/dart?tab=tags for latest.
8-
DART_VERSION: '3.5.2'
7+
# Test latest available and lowest supported SDK (see dev-doc/updating-dart-flutter-and-dependencies.md).
8+
# # Pick a concrete version instead of "latest" to avoid builds breaking due to changes in new
9+
# SDKs. For available versions see https://hub.docker.com/_/dart?tab=tags
10+
DART_VERSION_LATEST: '3.7.2'
11+
DART_VERSION_LOWEST: '2.18.6' # Use latest bugfix release to get tooling fixes
12+
DART_VERSION: $DART_VERSION_LATEST # Also used for caching, see .cache template
13+
14+
.common:
15+
image: dart:$DART_VERSION # Official Dart Docker image https://hub.docker.com/_/dart
16+
tags: [ x64, linux, docker ] # Jobs use shell commands and scripts, so only run on Linux
917

1018
# Make PUB_CACHE cacheable in GitLab;
1119
# see also https://gitlab.com/gitlab-org/gitlab/-/merge_requests/77791/diffs and
1220
# https://dikman.medium.com/optimising-flutter-ci-by-caching-packages-8a1d537e0b23
1321
# Requires extending job to set DART_VERSION variable.
1422
.cache:
23+
extends: .common
1524
before_script:
1625
- export PUB_CACHE="$CI_PROJECT_DIR/.pub-cache" # https://dart.dev/tools/pub/environment-variables
1726
- export PATH="$PATH":"$PUB_CACHE/bin"
@@ -23,11 +32,9 @@ variables:
2332
key: "linux-x64-dart-$DART_VERSION-pub-cache"
2433

2534
# Analyze (only) Dart packages, check formatting in Dart and Flutter packages.
26-
analyze:
35+
analyze-and-format:
2736
extends: .cache
28-
stage: analyze
29-
tags: [ x64, linux, docker ]
30-
image: dart:$DART_VERSION
37+
stage: code-analysis
3138
script:
3239
# Get dependencies
3340
- dart pub get --directory=benchmark
@@ -49,23 +56,29 @@ analyze:
4956
- dart analyze objectbox
5057
- dart analyze objectbox_test
5158
- dart analyze objectbox/example/dart-native/vectorsearch_cities
52-
# Check formatting of all packages
53-
- dart format --set-exit-if-changed --fix .
59+
# Since Dart 3.7, dart format needs pub get to run before formatting,
60+
# so can no longer check formatting of Flutter packages (would require Flutter SDK):
61+
# Check formatting only for Dart packages
62+
- dart format --set-exit-if-changed benchmark
63+
- dart format --set-exit-if-changed generator
64+
- dart format --set-exit-if-changed objectbox
65+
- dart format --set-exit-if-changed objectbox_test
66+
- dart format --set-exit-if-changed objectbox/example/dart-native
5467

5568
# Runs generator integration tests, e.g. ensures generator works as expected.
56-
test-generator:linux:x64:
69+
# Note: no need to test oldest SDK here, generator package is also built as part of unit-tests job.
70+
generator-integ-tests:
5771
extends: .cache
5872
stage: test
59-
tags: [ x64, linux, docker ]
60-
image: dart:$DART_VERSION
6173
script:
6274
- ./install.sh --install # Install globally for generator integration tests
6375
- ./generator/test.sh
6476

6577
# Runs generator and objectbox unit tests.
66-
.test:
78+
.unit-tests-template:
6779
extends: .cache
6880
stage: test
81+
needs: ["generator-integ-tests"] # Wait for generator integration tests
6982
script:
7083
# Generator tests
7184
- cd generator
@@ -84,28 +97,33 @@ test-generator:linux:x64:
8497
- export OBX_IN_MEMORY=true
8598
- dart test --concurrency=1 --reporter expanded
8699

87-
test-lib:linux:x64:
88-
extends: .test
89-
tags: [ x64, linux, docker ]
90-
image: dart:$DART_VERSION
91-
needs: ["test-generator:linux:x64"] # Wait for generator test
100+
unit-tests:
101+
extends: .unit-tests-template
92102
parallel:
93103
matrix:
94-
# Note: use specific versions instead of latest/beta tags as Docker images may not always be
95-
# pulled due to "if-not-present" pull policy. Check https://hub.docker.com/_/dart?tab=tags.
96-
# Always include lowest supported version (see sdk key in objectbox and generator
97-
# pubspec.yaml, but may be higher due to dependencies).
98-
- DART_VERSION: [ '2.18.6', '3.4.4', '3.5.2' ]
104+
- DART_VERSION: [ $DART_VERSION_LOWEST, $DART_VERSION_LATEST ]
105+
106+
# For the Dart Native example compiles and runs the executable (analysis and code formatting is
107+
# checked by analyze job).
108+
vectorsearch-example:
109+
extends: .cache
110+
stage: test
111+
needs: ["generator-integ-tests"] # Wait for generator integration tests
112+
script:
113+
- cd objectbox/example/dart-native/vectorsearch_cities
114+
- dart pub get
115+
- dart run build_runner build
116+
- ../../../../install.sh
117+
- dart compile exe bin/vectorsearch_cities.dart
118+
- ./bin/vectorsearch_cities.exe
99119

100120
# Runs tests with coverage on the objectbox package.
101121
# Note: As this requires to run tests, make sure this does not block the actual test jobs so test
102122
# issues can be seen.
103-
coverage:
123+
test-coverage:
104124
extends: .cache
105-
stage: test
106-
needs: ["test-lib:linux:x64"] # Get test results first
107-
tags: [ x64, linux, docker ]
108-
image: dart:$DART_VERSION
125+
stage: test-coverage
126+
needs: ["unit-tests"] # Get test results first
109127
script:
110128
# Install coverage tools
111129
- apt-get update
@@ -124,18 +142,3 @@ coverage:
124142
artifacts:
125143
paths:
126144
- objectbox/coverage/html/
127-
128-
# For the Dart Native example compiles and runs the executable (analysis and code formatting is
129-
# checked by analyze job).
130-
dart-examples-test:
131-
extends: .cache
132-
stage: test
133-
tags: [ x64, linux, docker ]
134-
image: dart:$DART_VERSION
135-
script:
136-
- cd objectbox/example/dart-native/vectorsearch_cities
137-
- dart pub get
138-
- dart run build_runner build
139-
- ../../../../install.sh
140-
- dart compile exe bin/vectorsearch_cities.dart
141-
- ./bin/vectorsearch_cities.exe
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Testing and updating Dart and Flutter SDKs and dependencies
2+
3+
## Testing SDKs
4+
5+
Officially the Dart developers only [commit to release security fixes](https://dart.dev/security)
6+
for the latest version of the Dart SDK. The Flutter developers have so far not released fixes for a
7+
previous minor version of the Flutter SDK.
8+
9+
[Packages specify](https://dart.dev/tools/pub/pubspec#sdk-constraints) a minimum supported Dart and
10+
optionally Flutter SDK. And allow any new not major Dart SDK (and technically
11+
[any new Flutter SDK](https://dart.dev/tools/pub/pubspec#flutter-sdk-constraints)).
12+
13+
So packages should work with the latest allowed SDKs (tools, APIs), but remain compatible with the
14+
lowest allowed SDKs (APIs, language features).
15+
16+
Based on that, the ObjectBox packages should be
17+
18+
- **tested with the latest available Flutter and Dart SDK** and
19+
- SDKs matching **the lowest supported Dart and Flutter version**.
20+
21+
Note: regarding API compatibility, the issue is that the tools won't error if an API is used that
22+
is not available in the lowest supported SDK. Testing with an older SDK is a workaround for this.
23+
24+
## Updating required SDKs and dependencies
25+
26+
The pub tool prevents upgrading a dependency of an application or library when
27+
28+
- its highest allowed Dart or Flutter SDK, or
29+
- the highest allowed version of one of its shared transitive dependencies
30+
31+
is too low. So assume that applications or libraries may not support the most recent SDKs and
32+
dependencies, but are safe from breaking changes.
33+
34+
Based on that, ObjectBox packages
35+
36+
- may require the latest, but **should require at most the latest major version of a dependency**
37+
and
38+
- may require the latest, but **should require the lowest version of the Dart and Flutter SDK
39+
required by dependencies** and
40+
- to simplify testing, **all packages should require the same SDK versions**.

0 commit comments

Comments
 (0)