pubRelease method

bool pubRelease({
  1. required PubSpecDetails pubSpecDetails,
  2. required VersionMethod versionMethod,
  3. required int lineLength,
  4. required bool dryrun,
  5. required bool runTests,
  6. required bool autoAnswer,
  7. required String? tags,
  8. required String? excludeTags,
  9. required bool useGit,
  10. Version? setVersion,
})

Implementation

bool pubRelease({
  required PubSpecDetails pubSpecDetails,
  required VersionMethod versionMethod,
  required int lineLength,
  required bool dryrun,
  required bool runTests,
  required bool autoAnswer,
  required String? tags,
  required String? excludeTags,
  required bool useGit,
  Version? setVersion,
}) {
  var success = false;
  doRun(
      dryrun: dryrun,
      runRelease: () {
        final projectRootPath = dirname(pubSpecDetails.path);

        final newVersion = determineAndUpdateVersion(
            versionMethod, setVersion, pubSpecDetails,
            dryrun: dryrun);

        runPubGet(projectRootPath);

        if (runTests) {
          if (!doRunTests(projectRootPath,
              tags: tags, excludeTags: excludeTags)) {
            throw UnitTestFailedException(
                'Some unit tests failed. Release has been halted.');
          }
        }

        final usingGit = useGit && gitChecks(projectRootPath);

        runPreReleaseHooks(projectRootPath,
            version: newVersion, dryrun: dryrun);
        prepareReleaseNotes(
            projectRootPath, newVersion, pubSpecDetails.pubspec.version,
            usingGit: usingGit, autoAnswer: autoAnswer, dryrun: dryrun);
        prepareCode(projectRootPath, lineLength, usingGit: usingGit);

        commitRelease(newVersion, projectRootPath,
            usingGit: usingGit, autoAnswer: autoAnswer, dryrun: dryrun);

        // protect the pubspec.yaml as need to remove the
        // overrides
        withFileProtection([pubSpecDetails.path], () {
          pubSpecDetails.removeOverrides();
          success = publish(pubSpecDetails.path,
              autoAnswer: autoAnswer, dryrun: dryrun);
        });

        runPostReleaseHooks(projectRootPath,
            version: newVersion, dryrun: dryrun);

        if (!success) {
          printerr(red('The publish attempt failed.'));
        }
      });

  return success;
}