def __get_cobigenwiki_title_name(config: Config): wiki_description_name = { config.branch_core: 'CobiGen', config.branch_mavenplugin: 'CobiGen - Maven Build Plug-in', config.branch_eclipseplugin: 'CobiGen - Eclipse Plug-in', config.branch_javaplugin: 'CobiGen - Java Plug-in', 'dev_xmlplugin': 'CobiGen - XML Plug-in', 'dev_htmlmerger': 'CobiGen - HTML Plug-in', config.branch_openapiplugin: 'CobiGen - Open API Plug-in', 'dev_tsplugin': 'CobiGen - TypeScript Plug-in', 'dev_textmerger': 'CobiGen - Text Merger', 'dev_propertyplugin': 'CobiGen - Property Plug-in', 'dev_jsonplugin': 'CobiGen - JSON Plug-in', 'dev_tempeng_freemarker': 'CobiGen - FreeMaker Template Engine', 'dev_tempeng_velocity': 'CobiGen - Velocity Template Engine', 'dev_cli': 'CobiGen CLI' } val = wiki_description_name.get(config.branch_to_be_released, "") if not val: log_error( 'Branch name unknown to script. Please edit function get_cobigenwiki_title_name in scripts/src/tools/initialization.py' ) sys.exit() return val
def exit_if_origin_is_not_correct(config: Config): remote_origin = git.cmd.Git(config.root_path).execute( "git remote -v".split(" ")) if config.github_repo not in remote_origin: log_error("Origin of the current repository is not '" + config.github_repo + "', Please go to correct directory.") sys.exit()
def init_git_dependent_config(config: Config, github: GitHub, git_repo: GitRepo): while(True): config.branch_to_be_released = prompt_enter_value("the name of the branch to be released") if(is_valid_branch(config)): break config.release_version = "" version_pattern = re.compile(r'[0-9]\.[0-9]\.[0-9]') while(not version_pattern.match(config.release_version)): config.release_version = prompt_enter_value("release version number without 'v' in front") config.next_version = "" while(not version_pattern.match(config.next_version)): config.next_version = prompt_enter_value("next version number (after releasing) without 'v' in front") config.build_folder = __get_build_folder(config) config.build_folder_abs = os.path.join(config.root_path, config.build_folder) config.build_artifacts_root_search_path = __get_build_artifacts_root_search_path(config) config.cobigenwiki_title_name = __get_cobigenwiki_title_name(config) config.tag_name = __get_tag_name(config) + config.release_version config.tag_core_name = __get_tag_name_specific_branch(config, config.branch_core) if git_repo.exists_tag(config.tag_name): log_error("Git tag " + config.tag_name + " already exists. Maybe you entered the wrong release version? Please fix the problem and try again.") sys.exit() config.issue_label_name = config.tag_name[:-7] config.expected_milestone_name = config.tag_name[:-7] + "-v" + config.release_version config.expected_core_milestone_name = config.tag_core_name[:-2] + "-v" milestone = github.find_release_milestone() if milestone: log_info("Milestone '"+milestone.title+"' found!") else: log_error("Milestone not found! Searched for milestone with name '" + config.expected_milestone_name+"'. Aborting...") sys.exit() while(True): github_issue_no: str = prompt_enter_value( "release issue number without # prefix in case you already created one or type 'new' to create an issue automatically") if github_issue_no == 'new': issue_text = "This issue has been automatically created. It serves as a container for all release related commits" config.github_issue_no = github.create_issue("Release " + config.expected_milestone_name, body=issue_text, milestone=milestone) if not config.github_issue_no: log_error("Could not create issue! Aborting...") sys.exit() else: log_info('Successfully created issue #' + str(github_issue_no)) break else: try: if github.find_issue(int(github_issue_no)): config.github_issue_no = int(github_issue_no) log_info("Issue #" + str(config.github_issue_no) + " found remotely!") break else: log_error("Issue with number #" + str(config.github_issue_no) + " not found! Typo?") except ValueError: log_error("Please enter a number.")
def check_running_in_bash(): try: FNULL = open(os.devnull, 'w') subprocess.call("ls", stdout=FNULL) except: log_error("Please run the script in a linux like environment (e.g. git bash)") sys.exit()
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()
def exit_if_not_executed_in_ide_environment(): '''This part checks if environment variables is set or not.''' if not ("ICSD_FILESERVER_USER" and "ICSD_FILESERVER_PASSWD") in os.environ: log_error( "Please use CobiGen IDE initialized console and set the variables in the variables-customized.bat." ) sys.exit()
def __set_path(config: Config, attr: str): msg = { 'root_path': "path of the repository to work on", } while True: if not hasattr(config, attr) or not getattr(config, attr): path = prompt_enter_value(msg[attr]) else: path = getattr(config, attr) # set by script param if not __check_path(path): setattr(config, attr, "") continue if (attr == "root_path") & (os.path.realpath(__file__).startswith( os.path.abspath(path))): log_error( "Please copy and run the create release script in another place outside of the repository and execute again." ) sys.exit() try: Git(path) except InvalidGitRepositoryError: log_error("Path is not a git repository.") setattr(config, attr, path) info = { "root_path": "Executing release in path '", } log_info(info[attr] + str(getattr(config, attr)) + "'") break
def __run_maven_and_handle_error(self, execpath: str, command: str) -> None: returncode = self.run_maven_process(execpath, command) if returncode == 1: log_error( "Maven execution failed, please see create_release.py.log for logs located at current directory." ) sys.exit()
def exit_if_not_executed_in_ide_environment(): '''This part checks if environment variables is set or not.''' if not ("OSSRH_USER" and "OSSRH_PASSWD" and "GPG_SIGNING_PASSWD" and "BINTRAY_USER" and "BINTRAY_TOKEN") in os.environ: log_error( "Please use CobiGen IDE initialized console and set the variables OSSRH_USER, OSSRH_PASSWD, GPG_SIGNING_PASSWD, BINTRAY_USER, and BINTRAY_TOKEN in the variables-customized.bat." ) sys.exit()
def update_and_clean(self): log_info("Executing update and cleanup (git pull origin && git submodule update && git clean -fd)") self.pull() self.__repo.git.submodule("update") self.__repo.git.clean("-fd") if not self.is_working_copy_clean(): log_error("Reset and cleanup did not work out. Other branches have local commits not yet pushed:") log_info("\n" + self.__list_unpushed_commits()) sys.exit()
def assure_clean_working_copy(self) -> None: if not self.is_working_copy_clean(True): log_error("Working copy is not clean!") if self.__config.cleanup_silently or prompt_yesno_question("Should I clean the repo for you? This will delete all untracked files and hardly reset the repository!"): self.reset() else: log_info("Please cleanup your working copy first. Then run the script again.") sys.exit() else: log_info("Working copy clean.")
def run_maven_process_and_handle_error(command: str, execpath: str=config.build_folder_abs): log_info("Execute command '" + command + "'") returncode = maven.run_maven_process(execpath, command) if returncode == 1: log_error("Maven execution failed, please see create_release.py.log for logs located at current directory.") if prompt_yesno_question("Maven execution failed. Script is not able to recover from it by its own.\nCan you fix the problem right now? If so, would you like to retry the last maven execution and resume the script?"): run_maven_process_and_handle_error(command, execpath) else: git_repo.reset() sys.exit()
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()
def __init__(self, config: Config, path: str = None) -> None: self.__config: Config = config try: if not path: path = config.root_path self.__repo = Repo(path) assert not self.__repo.bare self.origin = self.__repo.remote('origin') except InvalidGitRepositoryError: log_error("Path " + path + " is not a git repository. Please go to valid git repository!") sys.exit()
def update_and_clean(self): log_info("Executing update and cleanup (git pull origin && git clean -fd)") self.pull() self.__repo.git.clean("-fd") if not self.is_working_copy_clean(): log_error("Reset and cleanup did not work out. Other branches have local commits not yet pushed:") log_info("\n" + self.__list_unpushed_commits()) if not prompt_yesno_question( "Something went wrong during cleanup. Please check if you can perform the cleanup on your own. Resume the script?"): self.reset() sys.exit()
def run_maven_process(self, execpath: str, command: str) -> int: maven_process = subprocess.Popen(command.split(), shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True, bufsize=1, cwd=execpath, env=os.environ) for line in maven_process.stdout: log_info(line.strip()) maven_process.stdout.close() for line in maven_process.stderr: log_error(line.strip()) maven_process.stderr.close() return_code = maven_process.wait() return return_code
def pull(self, branch_name: str = None): if not branch_name: branch = self.__repo.active_branch.name else: branch = branch_name try: log_info('Pull changes from origin ...') self.__repo.git.execute("git pull origin {}".format(branch).split(" ")) except GitCommandError: log_error("Pull from origin/" + branch + " on " + self.__repo.working_tree_dir + " is not possible as you might have uncommitted or untracked files. Fix the working tree, and then try again.") if not prompt_yesno_question("Did you fix the issue manually? Resume script?"): self.reset() sys.exit()
def __get_tag_name(config: Config, branch_to_get_tag: str = None): tag_names = __get_tag_names(config) if branch_to_get_tag is None: val = tag_names.get(config.branch_to_be_released, "") else: val = tag_names.get(branch_to_get_tag, "") if not val: log_error( 'Branch name unknown to script. Please edit function get_tag_names in scripts/src/tools/initialization.py' ) sys.exit() return val
def __request_milestone_list(self) -> PaginatedList: # caching! try: return self.__cache.milestones except AttributeError: log_debug("Milestones not found in cache, retrieving from GitHub...") try: milestones: PaginatedList = self.__repo.get_milestones(state="all") self.__cache.milestones = milestones return milestones except GithubException as e: log_error('Could not retrieve milestones') print(str(e)) sys.exit()
def __set_path(config: Config, attr: str): while True: if not hasattr(config, attr) or not getattr(config, attr): path = config.temp_root_path if not hasattr(config, "two_factor_authentication"): config.two_factor_authentication = prompt_yesno_question( "Are you using two-factor authentication on GitHub?") if config.two_factor_authentication: repository_url = "[email protected]:" + config.github_repo + ".git" else: repository_url = "https://github.com/" + config.github_repo + ".git" log_info("Cloning temporary repository from " + repository_url + " to " + str(path) + " for processing the release...") Repo.clone_from(repository_url, path, multi_options=["--config core.longpaths=true"]) else: path = getattr(config, attr) # set by script param if not __check_path(path): setattr(config, attr, "") continue if (attr == "root_path") & (os.path.realpath(__file__).startswith( os.path.abspath(path))): log_error( "Please copy and run the create release script in another place outside of the repository and execute again." ) sys.exit() try: Git(path) except InvalidGitRepositoryError: log_error("Path " + path + " is not a git repository.") setattr(config, attr, path) info = { "root_path": "Executing release in path '", } log_info(info[attr] + str(getattr(config, attr)) + "'") break
def __get_build_folder(config: Config): build_folder = { config.branch_core: os.path.join('cobigen', 'cobigen-core-parent'), config.branch_mavenplugin: 'cobigen-maven', config.branch_eclipseplugin: 'cobigen-eclipse', config.branch_javaplugin: os.path.join('cobigen', 'cobigen-javaplugin-parent'), 'dev_xmlplugin': os.path.join('cobigen', 'cobigen-xmlplugin'), 'dev_htmlmerger': os.path.join('cobigen', 'cobigen-htmlplugin'), config.branch_openapiplugin: os.path.join('cobigen', 'cobigen-openapiplugin-parent'), 'dev_tsplugin': os.path.join('cobigen', 'cobigen-tsplugin'), 'dev_textmerger': os.path.join('cobigen', 'cobigen-textmerger'), 'dev_propertyplugin': os.path.join('cobigen', 'cobigen-propertyplugin'), 'dev_jsonplugin': os.path.join('cobigen', 'cobigen-jsonplugin'), 'dev_tempeng_freemarker': os.path.join('cobigen', 'cobigen-templateengines', 'cobigen-tempeng-freemarker'), 'dev_tempeng_velocity': os.path.join('cobigen', 'cobigen-templateengines', 'cobigen-tempeng-velocity'), 'dev_cli': os.path.join('cobigen-cli') } val = build_folder.get(config.branch_to_be_released, "") if not val: log_error( 'Branch name unknown to script. Please edit function get_build_folder in scripts/src/tools/initialization.py' ) sys.exit() return val
def __get_tag_name_specific_branch(config: Config, branch_to_get_tag: str): tag_name = { config.branch_core: 'cobigen-core/v', config.branch_mavenplugin: 'cobigen-maven/v', config.branch_eclipseplugin: 'cobigen-eclipse/v', config.branch_javaplugin: 'cobigen-javaplugin/v', 'dev_xmlplugin': 'cobigen-xmlplugin/v', 'dev_htmlmerger': 'cobigen-htmlplugin/v', config.branch_openapiplugin: 'cobigen-openapiplugin/v', 'dev_tsplugin': 'cobigen-tsplugin/v', 'dev_textmerger': 'cobigen-textmerger/v', 'dev_propertyplugin': 'cobigen-propertyplugin/v', 'dev_jsonplugin': 'cobigen-jsonplugin/v', 'dev_tempeng_freemarker': 'cobigen-tempeng-freemarker/v', 'dev_tempeng_velocity': 'cobigen-tempeng-velocity/v', } val = tag_name.get(branch_to_get_tag, "") if not val: log_error('Branch name unknown to script. Please edit function get_tag_name in scripts/**/__config.py') sys.exit() return val
def __get_tag_name(config: Config): tag_name = { config.branch_core: 'cobigen-core/v', config.branch_mavenplugin: 'cobigen-maven/v', config.branch_eclipseplugin: 'cobigen-eclipse/v', config.branch_javaplugin: 'cobigen-javaplugin/v', 'dev_xmlplugin': 'cobigen-xmlplugin/v', 'dev_htmlmerger': 'cobigen-htmlplugin/v', config.branch_openapiplugin: 'cobigen-openapiplugin/v', 'dev_tsplugin': 'cobigen-tsplugin/v', 'dev_textmerger': 'cobigen-textmerger/v', 'dev_propertyplugin': 'cobigen-propertyplugin/v', 'dev_jsonplugin': 'cobigen-jsonplugin/v', 'dev_tempeng_freemarker': 'cobigen-tempeng-freemarker/v', 'dev_tempeng_velocity': 'cobigen-tempeng-velocity/v', 'dev_cli': 'cobigen-cli/v' } val = tag_name.get(config.branch_to_be_released, "") if not val: log_error('Branch name unknown to script. Please edit function get_tag_name in scripts/src/tools/initialization.py') sys.exit() return val
def __get_wiki_name_specific_branch(config: Config, branch_to_get_wikiname: str): wiki_name = { config.branch_core: 'cobigen-core', config.branch_mavenplugin: 'cobigen-maven', config.branch_eclipseplugin: 'cobigen-eclipse', config.branch_javaplugin: 'cobigen-javaplugin', 'dev_xmlplugin': 'cobigen-xmlplugin', 'dev_htmlmerger': 'cobigen-htmlplugin', config.branch_openapiplugin: 'cobigen-openapiplugin', 'dev_tsplugin': 'cobigen-tsplugin', 'dev_textmerger': 'cobigen-textmerger', 'dev_propertyplugin': 'cobigen-propertyplugin', 'dev_jsonplugin': 'cobigen-jsonplugin', 'dev_tempeng_freemarker': 'cobigen-tempeng-freemarker', 'dev_tempeng_velocity': 'cobigen-tempeng-velocity', 'master': 'master-cobigen', } if branch_to_get_wikiname not in wiki_name: log_error( 'Branch name unknown to script. Please edit function get_tag_name in scripts/**/__config.py' ) sys.exit() return wiki_name[branch_to_get_wikiname]
def init_non_git_config(config: Config): __process_params(config) def __check_path(path): if not os.path.exists(path): log_error("Path does not exist.") if not os.path.isdir(path): log_error("Path is not a directory.") return os.path.exists(path) & os.path.isdir(path) def __set_path(config: Config, attr: str): msg = { 'root_path': "path of the repository to work on", } while True: if not hasattr(config, attr) or not getattr(config, attr): path = prompt_enter_value(msg[attr]) else: path = getattr(config, attr) # set by script param if not __check_path(path): setattr(config, attr, "") continue if (attr == "root_path") & (os.path.realpath(__file__).startswith( os.path.abspath(path))): log_error( "Please copy and run the create release script in another place outside of the repository and execute again." ) sys.exit() try: Git(path) except InvalidGitRepositoryError: log_error("Path is not a git repository.") setattr(config, attr, path) info = { "root_path": "Executing release in path '", } log_info(info[attr] + str(getattr(config, attr)) + "'") break __set_path(config, "root_path") if not hasattr(config, 'github_repo'): config.github_repo = "" repo_pattern = re.compile(r'[a-zA-Z]+/[a-zA-Z]+') while (not repo_pattern.match(config.github_repo)): if config.github_repo: log_error("'" + config.github_repo + "' is not a valid GitHub repository name.") config.github_repo = prompt_enter_value( "repository to be released (e.g. devonfw/tools-cobigen)") log_info("Releasing against GitHub repository '" + config.github_repo + "'") config.git_repo_name = config.github_repo.split(sep='/')[1] config.git_repo_org = config.github_repo.split(sep='/')[0] if not config.oss: config.oss = prompt_yesno_question( "Should the release been published to maven central as open source?" ) if config.oss: if not hasattr(config, "gpg_keyname"): config.gpg_keyname = prompt_enter_value( """Please provide your gpg.keyname for build artifact signing. If you are unsure about this, please stop here and clarify, whether * you created a pgp key and * published it! gpg.keyname = """) if not config.gpg_loaded: config.gpg_loaded = prompt_yesno_question( "Make sure the gpg key '" + config.gpg_keyname + "' is loaded by tools like Kleopatra before continuing! Continue?" ) if not config.gpg_loaded: sys.exit() #Check whether the user has gpg2 installed if is_tool("gpg2"): if not hasattr(config, "gpg_executable"): log_info("gpg2 installation found") config.gpg_executable = "gpg2" elif is_tool("gpg"): if not hasattr(config, "gpg_executable"): log_info("gpg installation found") config.gpg_executable = "gpg" else: log_error( "gpg2 nor gpg are installed. Please install them on your computer (system path) or either use command -Dgpg.executable='gpg2'" )
"Maven execution failed. Script is not able to recover from it by its own.\nCan you fix the problem right now? If so, would you like to retry the last maven execution and resume the script?" ): run_maven_process_and_handle_error(command, execpath) else: git_repo.reset() sys.exit() ##################################################################### ############################# __log_step("Check for working CI build and tests...") ############################# if not prompt_yesno_question("Are the tests on branch " + config.branch_to_be_released + " passing in CI?"): log_error("Please correct the build failures before releasing!") sys.exit() else: report_messages.append( "User confirmed that tests are running on CI and the build is not failing." ) log_info("Build is reported to be successful.") ############################# __log_step("Navigate to branch " + config.branch_to_be_released + " and prepare workspace...") ############################# git_repo.checkout(config.branch_to_be_released) ############################# __log_step("Set the SNAPSHOT version...")
def load_file(path): with open(path, 'r') as file: try: return yaml.safe_load(file) except yaml.YAMLError as exc: log_error(exc)
def init_non_git_config(config: Config): __process_params(config) while True: if not hasattr(config, 'root_path') or not config.root_path: root_path = prompt_enter_value("path of the repository to work on") else: root_path = config.root_path # set by script param if not os.path.exists(root_path): log_error("Path does not exist.") config.root_path = "" continue if not os.path.isdir(root_path): log_error("Path is not a directory.") config.root_path = "" continue if os.path.realpath(__file__).startswith(os.path.abspath(root_path)): log_error( "Please copy and run the create release script in another place outside of the repository and execute again." ) sys.exit() try: Git(root_path) except InvalidGitRepositoryError: log_error("Path is not a git repository.") config.root_path = root_path log_info("Executing release in path '" + str(config.root_path) + "'") break if not hasattr(config, 'github_repo'): config.github_repo = "" repo_pattern = re.compile(r'[a-zA-Z]+/[a-zA-Z]+') while (not repo_pattern.match(config.github_repo)): if config.github_repo: log_error("'" + config.github_repo + "' is not a valid GitHub repository name.") config.github_repo = prompt_enter_value( "repository to be released (e.g. devonfw/tools-cobigen)") log_info("Releasing against GitHub repository '" + config.github_repo + "'") config.git_repo_name = config.github_repo.split(sep='/')[1] config.git_repo_org = config.github_repo.split(sep='/')[0] config.wiki_submodule_name = "cobigen-documentation/" + config.git_repo_name + ".wiki" config.wiki_submodule_path = os.path.abspath( os.path.join(config.root_path, "cobigen-documentation", config.git_repo_name + ".wiki")) config.oss = prompt_yesno_question( "Should the release been published to maven central as open source?") if config.oss: if not hasattr(config, "gpg_keyname"): config.gpg_keyname = prompt_enter_value( """Please provide your gpg.keyname for build artifact signing. If you are unsure about this, please stop here and clarify, whether * you created a pgp key and * published it! gpg.keyname = """) if not prompt_yesno_question( "Make sure the gpg key '" + config.gpg_keyname + "' is loaded by tools like Kleopatra before continuing! Continue?" ): sys.exit()
def init_non_git_config(config: Config): __process_params(config) def __check_path(path): if not os.path.exists(path): log_error("Path does not exist.") if not os.path.isdir(path): log_error("Path is not a directory.") return os.path.exists(path) & os.path.isdir(path) def __set_path(config: Config, attr: str): while True: if not hasattr(config, attr) or not getattr(config, attr): path = config.temp_root_path if not hasattr(config, "two_factor_authentication"): config.two_factor_authentication = prompt_yesno_question( "Are you using two-factor authentication on GitHub?") if config.two_factor_authentication: repository_url = "[email protected]:" + config.github_repo + ".git" else: repository_url = "https://github.com/" + config.github_repo + ".git" log_info("Cloning temporary repository from " + repository_url + " to " + str(path) + " for processing the release...") Repo.clone_from(repository_url, path, multi_options=["--config core.longpaths=true"]) else: path = getattr(config, attr) # set by script param if not __check_path(path): setattr(config, attr, "") continue if (attr == "root_path") & (os.path.realpath(__file__).startswith(os.path.abspath(path))): log_error( "Please copy and run the create release script in another place outside of the repository and execute again.") sys.exit() try: Git(path) except InvalidGitRepositoryError: log_error("Path " + path + " is not a git repository.") setattr(config, attr, path) info = { "root_path": "Executing release in path '", } log_info(info[attr] + str(getattr(config, attr)) + "'") break ################################################################################################################################### if not hasattr(config, 'github_repo'): config.github_repo = "" repo_pattern = re.compile(r'[a-zA-Z]+/[a-zA-Z]+') while(not repo_pattern.match(config.github_repo)): if config.github_repo: log_error("'" + config.github_repo + "' is not a valid GitHub repository name.") config.github_repo = prompt_enter_value("repository to be released (default on empty: devonfw/cobigen)", "devonfw/cobigen") log_info("Releasing against GitHub repository '"+config.github_repo+"'") config.git_repo_name = config.github_repo.split(sep='/')[1] config.git_repo_org = config.github_repo.split(sep='/')[0] __set_path(config, "root_path") if not config.oss: config.oss = prompt_yesno_question("Should the release been published to maven central as open source?") if config.oss: if not hasattr(config, "gpg_keyname"): config.gpg_keyname = prompt_enter_value("""Please provide your gpg.keyname for build artifact signing. If you are unsure about this, please stop here and clarify, whether * you created a pgp key and * published it! gpg.keyname = """) if not config.gpg_loaded: config.gpg_loaded = prompt_yesno_question("Make sure the gpg key '" + config.gpg_keyname + "' is loaded by tools like Kleopatra before continuing! Continue?") if not config.gpg_loaded: sys.exit() # Check whether the user has gpg2 installed if is_tool("gpg2"): if not hasattr(config, "gpg_executable"): log_info("gpg2 installation found") config.gpg_executable = "gpg2" elif is_tool("gpg"): if not hasattr(config, "gpg_executable"): log_info("gpg installation found") config.gpg_executable = "gpg" else: log_error("gpg2 nor gpg are installed. Please install them on your computer (system path) or either use command -Dgpg.executable='gpg2'")
def __check_path(path): if not os.path.exists(path): log_error("Path does not exist.") if not os.path.isdir(path): log_error("Path is not a directory.") return os.path.exists(path) & os.path.isdir(path)