Skip to content

Commit d03aead

Browse files
committed
Support null-safety in functions_framework[_builder]
1 parent 1237afd commit d03aead

39 files changed

+277
-194
lines changed

.github/workflows/conformance.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ jobs:
3030
with:
3131
go-version: '1.13'
3232

33-
- uses: cedx/setup-dart@v2
33+
- uses: dart-lang/setup-dart@v1.0
3434
with:
35-
release-channel: stable
36-
version: "2.10.0"
35+
sdk: stable
3736
- run: dart --version
3837

3938
- uses: actions/checkout@v2

.github/workflows/lint.yml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Created with package:mono_repo v3.4.6
1+
# Created with package:mono_repo v3.4.7
22
name: Dart Lint CI
33
on:
44
push:
@@ -26,13 +26,13 @@ jobs:
2626
restore-keys: |
2727
os:ubuntu-latest;pub-cache-hosted
2828
os:ubuntu-latest
29-
- uses: dart-lang/setup-dart@v0.3
29+
- uses: dart-lang/setup-dart@v1.0
3030
with:
3131
sdk: stable
3232
- id: checkout
3333
uses: actions/checkout@v2
3434
- name: mono_repo self validate
35-
run: pub global activate mono_repo 3.4.6
35+
run: pub global activate mono_repo 3.4.7
3636
- name: mono_repo self validate
3737
run: pub global run mono_repo generate --validate
3838
job_002:
@@ -49,7 +49,7 @@ jobs:
4949
os:ubuntu-latest;pub-cache-hosted;dart:dev
5050
os:ubuntu-latest;pub-cache-hosted
5151
os:ubuntu-latest
52-
- uses: dart-lang/setup-dart@v0.3
52+
- uses: dart-lang/setup-dart@v1.0
5353
with:
5454
sdk: dev
5555
- id: checkout
@@ -107,20 +107,20 @@ jobs:
107107
working-directory: test/hello
108108
run: dartanalyzer --fatal-infos .
109109
job_003:
110-
name: "analyze_format; Dart 2.10.0; PKGS: dartfn, functions_framework, functions_framework_builder, test/hello; `dartanalyzer .`"
110+
name: "analyze_format; Dart 2.10.0; PKG: dartfn; `dartanalyzer .`"
111111
runs-on: ubuntu-latest
112112
steps:
113113
- name: Cache Pub hosted dependencies
114114
uses: actions/cache@v2
115115
with:
116116
path: "~/.pub-cache/hosted"
117-
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:dartfn-functions_framework-functions_framework_builder-test/hello;commands:dartanalyzer_1"
117+
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:dartfn;commands:dartanalyzer_1"
118118
restore-keys: |
119-
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:dartfn-functions_framework-functions_framework_builder-test/hello
119+
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:dartfn
120120
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0
121121
os:ubuntu-latest;pub-cache-hosted
122122
os:ubuntu-latest
123-
- uses: dart-lang/setup-dart@v0.3
123+
- uses: dart-lang/setup-dart@v1.0
124124
with:
125125
sdk: "2.10.0"
126126
- id: checkout
@@ -134,6 +134,25 @@ jobs:
134134
if: "always() && steps.dartfn_pub_upgrade.conclusion == 'success'"
135135
working-directory: dartfn
136136
run: dartanalyzer .
137+
job_004:
138+
name: "analyze_format; Dart 2.12.0; PKGS: functions_framework, functions_framework_builder, test/hello; `dartanalyzer .`"
139+
runs-on: ubuntu-latest
140+
steps:
141+
- name: Cache Pub hosted dependencies
142+
uses: actions/cache@v2
143+
with:
144+
path: "~/.pub-cache/hosted"
145+
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:functions_framework-functions_framework_builder-test/hello;commands:dartanalyzer_1"
146+
restore-keys: |
147+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:functions_framework-functions_framework_builder-test/hello
148+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
149+
os:ubuntu-latest;pub-cache-hosted
150+
os:ubuntu-latest
151+
- uses: dart-lang/[email protected]
152+
with:
153+
sdk: "2.12.0"
154+
- id: checkout
155+
uses: actions/checkout@v2
137156
- id: functions_framework_pub_upgrade
138157
name: "functions_framework; pub upgrade --no-precompile"
139158
if: "always() && steps.checkout.conclusion == 'success'"
@@ -161,7 +180,7 @@ jobs:
161180
if: "always() && steps.test_hello_pub_upgrade.conclusion == 'success'"
162181
working-directory: test/hello
163182
run: dartanalyzer .
164-
job_004:
183+
job_005:
165184
name: Notify failure
166185
runs-on: ubuntu-latest
167186
if: "(github.event_name == 'push' || github.event_name == 'schedule') && failure()"
@@ -176,3 +195,4 @@ jobs:
176195
- job_001
177196
- job_002
178197
- job_003
198+
- job_004

.github/workflows/unit.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Created with package:mono_repo v3.4.6
1+
# Created with package:mono_repo v3.4.7
22
name: Dart Unit CI
33
on:
44
push:
@@ -28,7 +28,7 @@ jobs:
2828
os:ubuntu-latest;pub-cache-hosted;dart:dev
2929
os:ubuntu-latest;pub-cache-hosted
3030
os:ubuntu-latest
31-
- uses: dart-lang/setup-dart@v0.3
31+
- uses: dart-lang/setup-dart@v1.0
3232
with:
3333
sdk: dev
3434
- id: checkout
@@ -56,7 +56,7 @@ jobs:
5656
os:ubuntu-latest;pub-cache-hosted;dart:dev
5757
os:ubuntu-latest;pub-cache-hosted
5858
os:ubuntu-latest
59-
- uses: dart-lang/setup-dart@v0.3
59+
- uses: dart-lang/setup-dart@v1.0
6060
with:
6161
sdk: dev
6262
- id: checkout
@@ -84,7 +84,7 @@ jobs:
8484
os:ubuntu-latest;pub-cache-hosted;dart:dev
8585
os:ubuntu-latest;pub-cache-hosted
8686
os:ubuntu-latest
87-
- uses: dart-lang/setup-dart@v0.3
87+
- uses: dart-lang/setup-dart@v1.0
8888
with:
8989
sdk: dev
9090
- id: checkout
@@ -99,22 +99,22 @@ jobs:
9999
working-directory: test/hello
100100
run: pub run test --run-skipped -t presubmit-only
101101
job_004:
102-
name: "unit_test; Dart 2.10.0; PKG: functions_framework_builder; `pub run test`"
102+
name: "unit_test; Dart 2.12.0; PKG: functions_framework_builder; `pub run test`"
103103
runs-on: ubuntu-latest
104104
steps:
105105
- name: Cache Pub hosted dependencies
106106
uses: actions/cache@v2
107107
with:
108108
path: "~/.pub-cache/hosted"
109-
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:functions_framework_builder;commands:test_1"
109+
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:functions_framework_builder;commands:test_1"
110110
restore-keys: |
111-
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:functions_framework_builder
112-
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0
111+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:functions_framework_builder
112+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
113113
os:ubuntu-latest;pub-cache-hosted
114114
os:ubuntu-latest
115-
- uses: dart-lang/setup-dart@v0.3
115+
- uses: dart-lang/setup-dart@v1.0
116116
with:
117-
sdk: "2.10.0"
117+
sdk: "2.12.0"
118118
- id: checkout
119119
uses: actions/checkout@v2
120120
- id: functions_framework_builder_pub_upgrade
@@ -140,7 +140,7 @@ jobs:
140140
os:ubuntu-latest;pub-cache-hosted;dart:dev
141141
os:ubuntu-latest;pub-cache-hosted
142142
os:ubuntu-latest
143-
- uses: dart-lang/setup-dart@v0.3
143+
- uses: dart-lang/setup-dart@v1.0
144144
with:
145145
sdk: dev
146146
- id: checkout
@@ -155,22 +155,22 @@ jobs:
155155
working-directory: functions_framework_builder
156156
run: pub run test
157157
job_006:
158-
name: "unit_test; Dart 2.10.0; PKG: test/hello; `pub run test -x presubmit-only`"
158+
name: "unit_test; Dart 2.12.0; PKG: test/hello; `pub run test -x presubmit-only`"
159159
runs-on: ubuntu-latest
160160
steps:
161161
- name: Cache Pub hosted dependencies
162162
uses: actions/cache@v2
163163
with:
164164
path: "~/.pub-cache/hosted"
165-
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:test/hello;commands:test_2"
165+
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:test/hello;commands:test_2"
166166
restore-keys: |
167-
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:test/hello
168-
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0
167+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:test/hello
168+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
169169
os:ubuntu-latest;pub-cache-hosted
170170
os:ubuntu-latest
171-
- uses: dart-lang/setup-dart@v0.3
171+
- uses: dart-lang/setup-dart@v1.0
172172
with:
173-
sdk: "2.10.0"
173+
sdk: "2.12.0"
174174
- id: checkout
175175
uses: actions/checkout@v2
176176
- id: test_hello_pub_upgrade
@@ -196,7 +196,7 @@ jobs:
196196
os:ubuntu-latest;pub-cache-hosted;dart:dev
197197
os:ubuntu-latest;pub-cache-hosted
198198
os:ubuntu-latest
199-
- uses: dart-lang/setup-dart@v0.3
199+
- uses: dart-lang/setup-dart@v1.0
200200
with:
201201
sdk: dev
202202
- id: checkout
@@ -211,22 +211,22 @@ jobs:
211211
working-directory: test/hello
212212
run: pub run test -x presubmit-only
213213
job_008:
214-
name: "unit_test; Dart 2.10.0; PKG: test/hello; `pub run test --run-skipped -t presubmit-only`"
214+
name: "unit_test; Dart 2.12.0; PKG: test/hello; `pub run test --run-skipped -t presubmit-only`"
215215
runs-on: ubuntu-latest
216216
steps:
217217
- name: Cache Pub hosted dependencies
218218
uses: actions/cache@v2
219219
with:
220220
path: "~/.pub-cache/hosted"
221-
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:test/hello;commands:test_0"
221+
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:test/hello;commands:test_0"
222222
restore-keys: |
223-
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0;packages:test/hello
224-
os:ubuntu-latest;pub-cache-hosted;dart:2.10.0
223+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:test/hello
224+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
225225
os:ubuntu-latest;pub-cache-hosted
226226
os:ubuntu-latest
227-
- uses: dart-lang/setup-dart@v0.3
227+
- uses: dart-lang/setup-dart@v1.0
228228
with:
229-
sdk: "2.10.0"
229+
sdk: "2.12.0"
230230
- id: checkout
231231
uses: actions/checkout@v2
232232
- id: test_hello_pub_upgrade

.github/workflows/verify_examples.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jobs:
3535
os:ubuntu-latest;pub-cache-hosted;dart:dev
3636
os:ubuntu-latest;pub-cache-hosted
3737
os:ubuntu-latest
38-
- uses: cedx/setup-dart@v2
38+
- uses: dart-lang/setup-dart@v1.0
3939
with:
40-
release-channel: dev
40+
sdk: stable
4141
- uses: actions/checkout@v2
4242
- run: dart --version
4343
- id: pub_upgrade

functions_framework/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 0.4.0-dev
44

5+
- Now null-safe.
6+
- Requires Dart `2.12.0`.
57
- **BREAKING** `RequestContext`: removed deprecated `headers` and `headersAll`
68
properties.
79
- **BREAKING** `serve.dart`:

functions_framework/lib/serve.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export 'src/function_target.dart'
3737
/// [ProcessSignal.sigint].
3838
Future<void> serve(
3939
List<String> args,
40-
FunctionTarget Function(String) nameToFunctionTarget,
40+
FunctionTarget? Function(String) nameToFunctionTarget,
4141
) async {
4242
try {
4343
await _serve(args, nameToFunctionTarget);
@@ -52,7 +52,7 @@ Future<void> serve(
5252

5353
Future<void> _serve(
5454
List<String> args,
55-
FunctionTarget Function(String) nameToFunctionTarget,
55+
FunctionTarget? Function(String) nameToFunctionTarget,
5656
) async {
5757
final configFromEnvironment = FunctionConfig.fromEnv();
5858

@@ -88,7 +88,7 @@ Future<void> _serve(
8888

8989
// sigIntSub is copied below to avoid a race condition - ignoring this lint
9090
// ignore: cancel_subscriptions
91-
StreamSubscription sigIntSub, sigTermSub;
91+
StreamSubscription? sigIntSub, sigTermSub;
9292

9393
Future<void> signalHandler(ProcessSignal signal) async {
9494
print('Received signal $signal - closing');
@@ -99,7 +99,7 @@ Future<void> _serve(
9999
await subCopy.cancel();
100100
sigIntSub = null;
101101
if (sigTermSub != null) {
102-
await sigTermSub.cancel();
102+
await sigTermSub!.cancel();
103103
sigTermSub = null;
104104
}
105105
completer.complete(true);

functions_framework/lib/src/bad_configuration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class BadConfigurationException implements Exception {
1616
final String message;
17-
final String details;
17+
final String? details;
1818

1919
BadConfigurationException(this.message, {this.details});
2020

functions_framework/lib/src/bad_request_exception.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import 'package:stack_trace/stack_trace.dart';
2727
class BadRequestException implements Exception {
2828
final int statusCode;
2929
final String message;
30-
final Object innerError;
31-
final StackTrace innerStack;
30+
final Object? innerError;
31+
final StackTrace? innerStack;
3232

3333
BadRequestException(
3434
this.statusCode,
3535
this.message, {
3636
this.innerError,
3737
this.innerStack,
38-
}) : assert(message != null && message.isNotEmpty) {
38+
}) : assert(message.isNotEmpty) {
3939
if (statusCode < 400 || statusCode > 499) {
4040
throw ArgumentError.value(
4141
statusCode,

functions_framework/lib/src/cloud_event.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
import 'package:json_annotation/json_annotation.dart';
16-
import 'package:meta/meta.dart';
1716

1817
part 'cloud_event.g.dart';
1918

@@ -30,19 +29,19 @@ class CloudEvent {
3029
final String type;
3130

3231
@JsonKey(name: 'datacontenttype')
33-
final String dataContentType;
34-
final Object data;
32+
final String? dataContentType;
33+
final Object? data;
3534

3635
@JsonKey(name: 'dataschema')
37-
final Uri dataSchema;
38-
final String subject;
39-
final DateTime time;
36+
final Uri? dataSchema;
37+
final String? subject;
38+
final DateTime? time;
4039

4140
CloudEvent({
42-
@required this.id,
43-
@required this.source,
44-
@required this.specVersion,
45-
@required this.type,
41+
required this.id,
42+
required this.source,
43+
required this.specVersion,
44+
required this.type,
4645
this.data,
4746
this.dataContentType,
4847
this.dataSchema,

0 commit comments

Comments
 (0)