commitVersion static method

Future<void> commitVersion(
  1. String version,
  2. String? root, {
  3. bool? commitBadge,
  4. bool commitChangelog = true,
})

Implementation

static Future<void> commitVersion(
  String version,
  String? root, {
  bool? commitBadge,
  bool commitChangelog = true,
}) async {
  final archivePath = p.join(root ?? '.', changelogArchiveFileName);
  final archiveExists = File(archivePath).existsSync();
  final archiveTracked = commitChangelog && _isGitTracked(changelogArchiveFileName, root);

  final filesToCommit = [
    'pubspec.yaml',
    if (commitChangelog) 'CHANGELOG.md',
    if (commitChangelog && (archiveExists || archiveTracked)) changelogArchiveFileName,
    if (commitBadge == true) 'version_badge.svg',
  ];

  // Add files to git to ensure they are tracked (and stage archive deletions).
  final addResult = await Process.run('git', ['add', '--', ...filesToCommit], workingDirectory: root);

  if (addResult.exitCode != 0) {
    throw GitException('Failed to add files to git: ${addResult.stderr.toString()}');
  }

  final result = await Process.run('git', [
    'commit',
    '-m',
    'chore: bump version to $version [skip ci]',
    '--',
    ...filesToCommit,
  ], workingDirectory: root);
  if (result.exitCode != 0) {
    throw GitException('Failed to commit version $version: ${result.stderr.toString()}');
  }
}