Skip to content

Commit

Permalink
support previewing staging patches
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman committed Jan 29, 2025
1 parent 3d08910 commit a57d7fd
Showing 1 changed file with 66 additions and 24 deletions.
90 changes: 66 additions & 24 deletions packages/shorebird_cli/lib/src/commands/preview_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ This is only applicable when previewing Android releases.''',
}
}

final progress = logger.progress('Using ${track.name} track');
try {
await setChannelOnLinuxApp(
channel: track.name,
bundleDirectory: appDirectory,
);
progress.complete();
} on Exception catch (error) {
progress.fail('$error');
return ExitCode.software.code;
}

final executableFile = appDirectory.listSync().whereType<File>().first;

await process.run('chmod', ['+x', executableFile.path]);
Expand Down Expand Up @@ -847,10 +859,10 @@ This is only applicable when previewing Android releases.''',
throw Exception('Unable to find shorebird.yaml');
}

final yaml = YamlEditor(shorebirdYaml.readAsStringSync())
..update(['channel'], channel);

shorebirdYaml.writeAsStringSync(yaml.toString(), flush: true);
await _setChannelInShorebirdYaml(
channel: channel,
shorebirdYamlFile: shorebirdYaml,
);
});
}

Expand Down Expand Up @@ -882,26 +894,10 @@ This is only applicable when previewing Android releases.''',
),
);

if (!shorebirdYamlFile.existsSync()) {
throw Exception('Unable to find shorebird.yaml');
}

final yamlText = shorebirdYamlFile.readAsStringSync();
final yaml = loadYaml(yamlText) as YamlMap;
final yamlChannel = yaml['channel'];

if (yamlChannel == null && channel == DeploymentTrack.stable.channel) {
// We would be updating the channel to the default value.
return;
}

if (yamlChannel == channel) {
// Updating this channel would be a no-op.
return;
}

final yamlEditor = YamlEditor(yamlText)..update(['channel'], channel);
shorebirdYamlFile.writeAsStringSync(yamlEditor.toString(), flush: true);
await _setChannelInShorebirdYaml(
channel: channel,
shorebirdYamlFile: shorebirdYamlFile,
);

// This is equivalent to `zip --no-dir-entries`
// Which does NOT create entries in the zip archive for directories.
Expand All @@ -924,6 +920,52 @@ This is only applicable when previewing Android releases.''',
tempDir.deleteSync(recursive: true);
});
}

/// Sets the channel property in the shorebird.yaml file if none is set.
Future<void> setChannelOnLinuxApp({
required String channel,
required Directory bundleDirectory,
}) async {
final shorebirdYamlFile = File(
p.join(
bundleDirectory.path,
'data',
'flutter_assets',
'shorebird.yaml',
),
);

await _setChannelInShorebirdYaml(
channel: channel,
shorebirdYamlFile: shorebirdYamlFile,
);
}

Future<void> _setChannelInShorebirdYaml({
required String channel,
required File shorebirdYamlFile,
}) async {
if (!shorebirdYamlFile.existsSync()) {
throw Exception('Unable to find shorebird.yaml');
}

final yamlText = shorebirdYamlFile.readAsStringSync();
final yaml = loadYaml(yamlText) as YamlMap;
final yamlChannel = yaml['channel'];

if (yamlChannel == null && channel == DeploymentTrack.stable.channel) {
// We would be updating the channel to the default value.
return;
}

if (yamlChannel == channel) {
// Updating this channel would be a no-op.
return;
}

final yamlEditor = YamlEditor(yamlText)..update(['channel'], channel);
shorebirdYamlFile.writeAsStringSync(yamlEditor.toString(), flush: true);
}
}

/// Extension on [Release] that exposes the active platforms (e.g. platforms
Expand Down

0 comments on commit a57d7fd

Please sign in to comment.