doRun method
Implementation
@override
Future<int> doRun() async {
final args = argResults!;
final isDemo = args[_argDemo] as bool;
if (!isDemo) {
fs = const IOFileSystem();
} else {
printInfo("Demonstration mode");
fs = DemoFileSystem();
}
git = getGit(config, isDemo: isDemo);
final skipL10n = args[_argSkipL10n] as bool? ?? false;
final isLocalRelease = args[_argLocal] as bool? ?? false;
final ciConfig = config.ci;
if (!ciConfig.enabled && !isLocalRelease) {
return error(1,
message: 'You can only use local release if CI is disabled. '
'See --$_argLocal and section ci in alex config section.');
}
final targetPath = (args[_argTargetPath] as String?)?.trim();
if (targetPath != null) {
if (!isLocalRelease) {
return error(1,
message: 'Option --$_argTargetPath can be used '
'only for local release builds. See --$_argLocal.');
}
if (targetPath.isEmpty) {
return error(1, message: "Option --$_argTargetPath can't be empty.");
}
// Fail before the release is started if the target can't be used.
final targetDir = await _ensureTargetDir(targetPath);
_checkTargetDirIsNotInRepo(targetDir);
}
git.ensureCleanAndCheckoutDevelop();
final spec = await Spec.pub(fs);
final version = spec.version;
final vs = version.short;
if (int.tryParse(version.build) == null) {
return error(1,
message: 'Invalid version "$vs": '
'you should define build number (after +).');
}
// Prepare parameters of a local build before the release is started,
// so an invalid value will not break the process in the middle.
final _LocalBuildOptions? localBuildOptions;
final List<_BuildPlatform> buildPlatforms;
if (isLocalRelease) {
localBuildOptions = _LocalBuildOptions(
entryPoint: args[_argEntryPoint] as String?,
targetPath: targetPath,
artifactName:
BuildArtifactName.sanitizeName(config.build.name ?? spec.name),
version: version,
);
buildPlatforms =
_BuildPlatform.parseArgs(args[_argBuildPlatforms] as String);
printVerbose('Platforms: ${buildPlatforms.asDesc()}');
} else {
localBuildOptions = null;
buildPlatforms = const [];
}
if (skipL10n) {
if (args.wasParsed(_argLocale)) {
return error(1,
message:
"You can't pass --$_argSkipL10n and --$_argLocale at the same time");
}
} else {
final baseLocale =
args.getLocale(_argLocale) ?? _defaultLocale.asXmlLocale();
final processLocResult = await _processLocalization(baseLocale);
if (processLocResult != 0) {
return processLocResult;
}
// Commit translations.
_commit("Generated translations.");
}
final scriptPaths = config.scripts?.preReleaseScriptsPaths;
if (scriptPaths != null && scriptPaths.isNotEmpty) {
printInfo('Running pre release scripts.');
for (final path in scriptPaths) {
final res = await flutter.runPubOrFail(
'${config.rootPath}/$path',
const [],
title: null,
);
if (res.exitCode == 0) {
printInfo('Pre release script $path run - OK');
} else {
// TODO: Clean current changes for git.
return error(res.exitCode, message: '${res.stderr}');
}
_commit('Pre release scripts run.');
}
} else {
printInfo('There are no pre release scripts to run.');
}
printInfo('Start new release <v$vs>');
git.gitflowReleaseStart(vs);
printInfo('Upgrading CHANGELOG.md...');
final changeLog = await upgradeChangeLog(version) ?? '';
printInfo("Change log: \n$changeLog");
final summary = StringBuffer();
if (ciConfig.enabled) {
final Map<String, String> prompt;
final chatGptApiKey = await settings.openAIApiKey;
if (chatGptApiKey != null && chatGptApiKey.isNotEmpty) {
printInfo('Trying to generate release notes prompt...');
prompt = await _getReleaseNotesPrompt(chatGptApiKey, changeLog);
} else {
prompt = {};
}
printInfo('Waiting for release notes...');
final releaseNotes = await getReleaseNotes(version, changeLog, prompt);
summary
..writeln()
..writeln('# Release Notes')
..writeln()
..writeln(releaseNotes);
}
summary
..writeln()
..writeln('# Changelog')
..writeln()
..writeln(changeLog);
if (localBuildOptions != null) {
for (final platform in buildPlatforms) {
await _localBuild(platform, localBuildOptions);
}
}
printInfo("Finishing release...");
// committing changes
_commit("Changelog and release notes");
// finishing release
git.gitflowReleaseFinish(vs);
final branchDevelop = git.branchDevelop;
if (git.getCurrentBranch() != branchDevelop) {
git.checkout(branchDevelop);
}
// increment version
incrementVersion(spec, version);
_commit("Version increment");
git.push(branchDevelop);
git.push(git.branchMaster);
printInfo('Release successfully completed');
printInfo('');
printInfo(
'Release summary, copypaste it in the comment for release issue:');
printInfo('');
printInfo(summary.toString());
return 0;
}