pubRelease method
void
pubRelease({})
Implementation
void pubRelease(
{bool? incVersion,
required bool setVersion,
String? passedVersion,
required int lineLength,
required bool dryrun}) {
print('');
/// If the user has set the version from the cli we assume they want to answer
/// yes to all questions.
final autoAnswer = setVersion;
//print('Running pub_release version: $packageVersion');
final pubspecPath = findPubSpec();
if (pubspecPath == null) {
print('Unable to find pubspec.yaml, run release from the '
"package's root directory.");
exit(-1);
}
final pubspec = PubSpec.fromFile(pubspecPath);
final projectRootPath = dirname(pubspecPath);
final currentVersion = pubspec.version;
checkHooksAreReadyToRun(projectRootPath);
print(green('Found pubspec.yaml for ${orange(pubspec.name!)}.'));
print('');
if (!autoAnswer && !confirm('Is this the correct package?')) exit(-1);
print('');
print(green('Current ${pubspec.name} version is $currentVersion'));
final usingGit = Git().usingGit(projectRootPath)!;
if (usingGit) {
print('Found Git project.');
// we do a premptive git pull as we won't be able to do a push
// at the end if we are behind head.
Git().pull();
print('Checking files are committed.');
Git().checkAllFilesCommited();
}
Version? newVersion;
if (setVersion) {
// we were passed the new version so just updated everything.
newVersion = Version.parse(passedVersion!);
print(green('Setting version to $passedVersion'));
if (!dryrun) {
updateVersion(newVersion, pubspec, pubspecPath);
}
} else {
// Ask the user for the new version
if (incVersion!) {
newVersion = askForVersion(currentVersion!);
if (!dryrun) {
updateVersion(newVersion, pubspec, pubspecPath);
}
}
}
runPreReleaseHooks(projectRootPath, version: newVersion, dryrun: dryrun);
// ensure that all code is correctly formatted.
formatCode(projectRootPath, usingGit: usingGit, lineLength: lineLength);
final progress = start('dart analyze',
workingDirectory: projectRootPath,
nothrow: true,
progress: Progress.print());
if (progress.exitCode != 0) {
printerr(
red('dart analyze failed. Please fix the errors and try again.'));
exit(1);
}
print('Generating release notes.');
if (!dryrun) {
generateReleaseNotes(projectRootPath, newVersion, currentVersion,
autoAnswer: autoAnswer, dryrun: dryrun);
}
if (usingGit && !dryrun) {
print('Committing release notes and versioned files');
Git().commit("Released $newVersion");
Git().push();
print('add tag');
Git().addGitTag(newVersion, autoAnswer: autoAnswer);
}
print('publish');
publish(pubspecPath, autoAnswer: autoAnswer, dryrun: dryrun);
runPostReleaseHooks(projectRootPath, version: newVersion, dryrun: dryrun);
}