Skip to content

Commit 43059b9

Browse files
fix(ai): the package version number wasn't properly updated after migrating from vertex_ai (#17745)
Co-authored-by: russellwheatley <[email protected]>
1 parent f365663 commit 43059b9

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

melos.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ command:
1717
workspaceChangelog: true
1818
hooks:
1919
preCommit: |
20+
dart run scripts/generate_firebaseai_version.dart && \
2021
dart run scripts/generate_dataconnect_version.dart && \
2122
dart run scripts/generate_versions_spm.dart && \
2223
git add packages/firebase_data_connect/firebase_data_connect/lib/src/dataconnect_version.dart

packages/firebase_ai/firebase_ai/lib/src/base_model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ import 'client.dart';
2929
import 'content.dart';
3030
import 'developer/api.dart';
3131
import 'error.dart';
32+
import 'firebaseai_version.dart';
3233
import 'imagen/imagen_api.dart';
3334
import 'imagen/imagen_content.dart';
3435
import 'imagen/imagen_edit.dart';
3536
import 'imagen/imagen_reference.dart';
3637
import 'live_api.dart';
3738
import 'live_session.dart';
3839
import 'tool.dart';
39-
import 'vertex_version.dart';
4040

4141
part 'generative_model.dart';
4242
part 'imagen/imagen_model.dart';

packages/firebase_ai/firebase_ai/lib/src/client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import 'dart:convert';
1818
import 'package:http/http.dart' as http;
1919

2020
import 'error.dart';
21-
import 'vertex_version.dart';
21+
import 'firebaseai_version.dart';
2222

2323
/// Client name to feed into the request.
2424
const clientName = 'vertexai-dart/$packageVersion';

packages/firebase_ai/firebase_ai/lib/src/vertex_version.dart renamed to packages/firebase_ai/firebase_ai/lib/src/firebaseai_version.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
// limitations under the License.
1414

1515
/// generated version number for the package, do not manually edit
16-
const packageVersion = '2.0.0';
16+
const packageVersion = '3.3.0';
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'dart:io' show Directory, File;
16+
import 'package:path/path.dart' show joinAll;
17+
import 'package:yaml/yaml.dart' show YamlMap, loadYaml;
18+
19+
Future<void> main() async {
20+
final outputPath = joinAll(
21+
[
22+
Directory.current.path,
23+
'packages',
24+
'firebase_ai',
25+
'firebase_ai',
26+
'lib',
27+
'src',
28+
'firebaseai_version.dart',
29+
],
30+
);
31+
32+
final pubspecPath = joinAll(
33+
[
34+
Directory.current.path,
35+
'packages',
36+
'firebase_data_connect',
37+
'firebase_data_connect',
38+
'pubspec.yaml',
39+
],
40+
);
41+
final yamlMap = loadYaml(File(pubspecPath).readAsStringSync()) as YamlMap;
42+
final currentVersion = yamlMap['version'] as String;
43+
final fileContents = File(outputPath).readAsStringSync();
44+
45+
final lines = fileContents.split('\n');
46+
47+
const versionLinePrefix = 'const packageVersion = ';
48+
bool versionLineFound = false;
49+
for (int i = 0; i < lines.length; i++) {
50+
if (lines[i].startsWith(versionLinePrefix)) {
51+
lines[i] = "$versionLinePrefix'$currentVersion';";
52+
versionLineFound = true;
53+
break;
54+
}
55+
}
56+
57+
if (!versionLineFound) {
58+
lines.add("$versionLinePrefix'$currentVersion';");
59+
}
60+
61+
// Join the lines back into a single string
62+
final newFileContents = lines.join('\n');
63+
64+
await File(outputPath).writeAsString(newFileContents);
65+
}

0 commit comments

Comments
 (0)