diff --git a/packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart b/packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart index 24d76f84ed257..3f4191cef7191 100644 --- a/packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart +++ b/packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart @@ -72,5 +72,9 @@ Map compileShorebirdYaml( 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 240ae45f5bb18..d0e3950538fb1 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 @@ -83,6 +83,29 @@ 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