diff --git a/packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart b/packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart index a741b2683d765..a6230549965b4 100644 --- a/packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart +++ b/packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart @@ -61,5 +61,9 @@ Map compileShorebirdYaml(YamlMap yamlMap, {required String? fla if (shorebirdPublicKeyEnvVar != null) { compiled['patch_public_key'] = shorebirdPublicKeyEnvVar; } + final String? moduleVersion = environment['SHOREBIRD_MODULE_VERSION']; + if (moduleVersion != null) { + compiled['module_version'] = moduleVersion; + } return compiled; } diff --git a/packages/flutter_tools/test/general.shard/shorebird/shorebird_yaml_test.dart b/packages/flutter_tools/test/general.shard/shorebird/shorebird_yaml_test.dart index 7e05fec171409..d991ccf1596a8 100644 --- a/packages/flutter_tools/test/general.shard/shorebird/shorebird_yaml_test.dart +++ b/packages/flutter_tools/test/general.shard/shorebird/shorebird_yaml_test.dart @@ -74,6 +74,25 @@ patch_verification: strict 'patch_public_key': '4-a', }); }); + test('module_version from environment', () { + const String yamlContents = ''' +app_id: 1-a +'''; + final YamlDocument input = loadYamlDocument(yamlContents); + final YamlMap yamlMap = input.contents as YamlMap; + + // Without env var, module_version is absent. + final Map withoutEnv = + compileShorebirdYaml(yamlMap, flavor: null, environment: {}); + expect(withoutEnv.containsKey('module_version'), isFalse); + + // With env var, module_version is included. + final Map withEnv = + compileShorebirdYaml(yamlMap, flavor: null, environment: { + 'SHOREBIRD_MODULE_VERSION': 'abc1234', + }); + expect(withEnv['module_version'], 'abc1234'); + }); test('edit in place', () { const String yamlContents = ''' app_id: 1-a