Пример #1
0
    def push(self, force: bool = False):
        ''' Boolean return type states, whether to continue process or abort'''
        if (not force and not self.has_unpushed_commits()):
            log_info("Nothing to be pushed.")
            return

        if (self.__config.test_run or self.__config.debug) and not prompt_yesno_question(
                "[DEBUG] Changes will be pushed now. Continue?"):
            self.reset()
            sys.exit()
        if self.__config.dry_run:
            log_info_dry('Skipping pushing of changes.')
            return

        try:
            log_info(
                "Pushing to origin/" + self.__repo.active_branch.name + " in " + self.__repo.working_tree_dir + "  ...")
            self.__repo.git.execute("git push origin " + self.__repo.active_branch.name + " --tags")
        except Exception as e:
            if "no changes added to commit" in str(e):
                log_info("No file is changed, nothing to commit.")
            else:
                if not prompt_yesno_question(
                        "Something went wrong during pushing. Please check if you can perform pushing on your own. Resume the script?"):
                    self.reset()
Пример #2
0
    def merge(self, source: str, target: str) -> None:
        if self.__config.dry_run:
            log_info_dry("Would merge from " + source + " to " + target)
            return

        try:
            self.checkout(target)
            log_info("Executing git pull...")
            self.pull()
            log_info("Merging...")
            self.__repo.git.execute("git merge " + self.__config.branch_to_be_released)
            log_info("Adapting automatically generated merge commit message to include issue no.")
            automatic_commit_message = self.__repo.git.execute("git log -1 --pretty=%B")
            if "Merge" in automatic_commit_message and str(
                    self.__config.github_issue_no) not in automatic_commit_message:
                self.__repo.git.execute('git commit --amend -m"#' + str(
                    self.__config.github_issue_no) + ' ' + automatic_commit_message + '"')
        except Exception as ex:
            log_error("Something went wrong, please check if merge conflicts exist and solve them.")
            if self.__config.debug:
                print(ex)
            if not prompt_yesno_question(
                    "If there were conflicts you solved and committed, would you like to resume the script?"):
                self.__repo.git.execute("git merge --abort")
                self.reset()
                sys.exit()
Пример #3
0
    def create_issue(self, title: str, milestone: Milestone, body: str) -> int:
        '''Function creates an issue in git hub with title,milestone,body,labels passed'''
        if self.__config.dry_run:
            log_info_dry('Skipping creation of issue with title ' + str(title))
            return 0
        if self.__config.debug and not prompt_yesno_question(
                '[DEBUG] Would now create GitHub issue with title="' + title +
                '", milestone=' + str(milestone) + '. Continue?'):
            sys.exit()

        log_info('Create GitHub issue with title "' + title + '"...')

        try:
            issue: Issue = self.__repo.create_issue(
                title=title,
                body=body,
                milestone=milestone,
                labels=[self.__config.issue_label_name, "CI/CD"],
                assignee=self.__github.get_user().login)
            self.__config.github_issue_no = issue.number
            self.__cache.issues.update({issue.number: issue})
            return self.__config.github_issue_no
        except GithubException as e:
            print(str(e))
            return 0
Пример #4
0
    def create_release(self, closed_milestone: Milestone, core_version_in_eclipse_pom: str) -> GitRelease:
        if self.__config.dry_run:
            log_info_dry("Would create a new GitHub release")
            return None

        url_milestone = self.__config.github_closed_milestone_url(closed_milestone.number)
        release_title = self.__config.cobigenwiki_title_name + " v" + self.__config.release_version
        release_text = "[ChangeLog](" + url_milestone + ")"
        if "eclipse" in self.__config.branch_to_be_released and core_version_in_eclipse_pom:
            cobigen_core_milestone: Milestone = self.find_milestone("dev_core", core_version_in_eclipse_pom)
            if cobigen_core_milestone.state == "closed":
                core_url_milestone = self.__config.github_closed_milestone_url(cobigen_core_milestone.number)
                release_text = release_text + "\n also includes \n" + "[ChangeLog CobiGen Core](" + core_url_milestone + ")"
            else:
                log_info("Core version " + core_version_in_eclipse_pom +
                         " is not yet released. This should be released before releasing cobigen-eclipse")
                sys.exit()

        try:
            release: GitRelease = self.__repo.create_git_release(self.__config.tag_name, release_title,
                                                                 release_text, draft=False, prerelease=False,
                                                                 target_commitish="master")

            content_type = "application/java-archive"
            if self.__config.branch_to_be_released == self.__config.branch_eclipseplugin:
                content_type = "application/zip"

            for root, dirs, files in os.walk(
                os.path.join(self.__config.build_folder_abs, self.__config.build_artifacts_root_search_path)):
                dirs[:] = [d for d in dirs if
                           d not in [".settings", "src", "repository", "repository-upload", "classes", "apidocs"]]
                for fname in files:
                    fpath = os.path.join(root, fname)
                    # To prevent uploading of unnecessary zip/jar files.
                    if (fname.endswith("jar") or fname.endswith("zip")) and self.__config.release_version in fname and 'nexus-staging' in fpath:
                        log_info("Uploading file " + fname + " from " + fpath + " ...")
                        try:
                            asset: GitReleaseAsset = release.upload_asset(path=fpath, label=fname,
                                                                          content_type=content_type)
                            log_info("Uploaded " + str(asset.size) + "kb!")
                        except GithubException as e:
                            log_error("Upload failed!")
                            if self.__config.debug:
                                print(str(e))

            # workaround as of https://github.com/PyGithub/PyGithub/issues/779
            self.__login()
            self.__initialize_repository_object()

            return release
        except GithubException as e:
            log_error("Could not create release.")
            print(str(e))
            sys.exit()
Пример #5
0
    def create_next_release_milestone(self) -> Milestone:
        new_mile_title = self.__config.expected_milestone_name.replace(self.__config.release_version,
                                                                       self.__config.next_version)
        if self.__config.dry_run:
            log_info_dry("Would now create a new milestone with title '" + new_mile_title + "'.")
            return None

        log_info("Creating milestone '" + new_mile_title + "' for next release...")
        try:
            milestone: Milestone = self.__repo.create_milestone(title=new_mile_title, state="open")
            log_info("New milestone created!")
            return milestone
        except GithubException as e:
            log_info("Could not create milestone!")
            print(str(e))
            return None
    run_maven_process_and_handle_error(
        "mvn clean -Dmaven.test.skip=true deploy -U", execpath=execpath)


def __deploy_p2(oss: bool, execpath: str = config.build_folder_abs):
    activation_str = ""
    if oss:
        activation_str = ",oss -Dgpg.keyname=" + config.gpg_keyname
    run_maven_process_and_handle_error(
        "mvn clean -Dmaven.test.skip=true deploy -U -Pp2-build-stable,p2-build-mars"
        + activation_str + " -Dp2.upload=stable",
        execpath=execpath)


if config.dry_run or config.test_run:
    log_info_dry(
        "Would now deploy to maven central/OSS & updatesite. Skipping...")
else:
    if config.branch_to_be_released not in [
            config.branch_eclipseplugin, config.branch_mavenplugin,
            config.branch_core, config.branch_javaplugin,
            config.branch_openapiplugin
    ]:
        __deploy_m2_as_p2(config.oss)
    elif config.branch_to_be_released == config.branch_javaplugin:
        __deploy_m2_only(
            config.oss,
            os.path.join(config.build_folder_abs, "cobigen-javaplugin-model"))
        __deploy_m2_as_p2(
            config.oss,
            os.path.join(config.build_folder_abs, "cobigen-javaplugin"))
    elif config.branch_to_be_released == config.branch_openapiplugin: