From addbbd4069a23af522b01478ef9c811c946d8b38 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Thu, 12 Sep 2024 19:10:47 +0900 Subject: [PATCH 01/19] fix(create-prs-to-update-vcs-repositories): fix as follows (see below) * Only handles formats such as: "1.0.0", "1.1.1", "0.0.9", ... etc * Following ones are the mismatched examples: ``` "v0.0.1", # mismatch "ros2-v0.0.4", # mismatch "xxx-1.0.0-yyy", # mismatch "v1.2.3-beta", # mismatch "v1.0", # mismatch "v2", # mismatch "1.0.0-alpha+001", # mismatch "v1.0.0-rc1+build.1", # mismatch "2.0.0+build.1848", # mismatch "2.0.1-alpha.1227", # mismatch "1.0.0-alpha.beta", # mismatch "ros_humble-v0.10.2" # mismatch ``` Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index bf519e20..ce768576 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -131,28 +131,32 @@ def parse_args() -> argparse.Namespace: args_repo.add_argument("--base_branch", type=str, default="main", help="The base branch of autoware.repos") args_repo.add_argument("--new_branch_prefix", type=str, default="feat/update-", help="The prefix of the new branch name") + DEFAULT_SEMANTIC_VERSION_PATTERN = r'\b(? None: autoware_repos: AutowareRepos = AutowareRepos(autoware_repos_file_name = args.autoware_repos_file_name) # Get the repositories with semantic version tags + # e.g. { + # 'https://github.com/user/repo.git': '0.0.1', # Pattern matched + # 'https://github.com/user/repo2.git': None, # Pattern not matched + # } repositories_url_semantic_version_dict: dict[str, str] = autoware_repos.pickup_semver_repositories(semantic_version_pattern = args.semantic_version_pattern) # Get reference to the repository @@ -252,6 +260,11 @@ def main(args: argparse.Namespace) -> None: 7. Create a PR ''' + # Skip if the current version has an invalid format + if current_version is None: + logger.debug(f"The current version ({current_version}) format has a mismatched pattern. Skip for this repository:\n {url}") + continue + # get tags of the repository tags: list[str] = github_interface.get_tags_by_url(url) @@ -259,7 +272,7 @@ def main(args: argparse.Namespace) -> None: # Skip if the expected format is not found if latest_tag is None: - logger.debug(f"The latest tag with expected format is not found in the repository {url}. Skip for this repository.") + logger.debug(f"The latest tag ({latest_tag}) format has a mismatched pattern. Skip for this repository:\n {url}") continue # Exclude parse failed ones such as 'tier4/universe', 'main', ... etc @@ -274,8 +287,8 @@ def main(args: argparse.Namespace) -> None: logger.debug(f"Repository {url} has the latest version {current_version}. Skip for this repository.") continue except (version.InvalidVersion, TypeError): - # If the current version is not a valid version and the latest tag is a valid version, let's update - pass + # If the current version is not a valid version, skip this repository + continue # Get repository name repo_name: str = github_interface.url_to_repository_name(url) From 2d53671c45c20b0c55196eacec512c849c32e6e5 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Thu, 12 Sep 2024 20:05:51 +0900 Subject: [PATCH 02/19] fix(create-prs-to-update-vcs-repositories): fix a wrong match method Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index ce768576..27b612d0 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -57,7 +57,7 @@ def pickup_semver_repositories(self, semantic_version_pattern: str) -> dict[str, repository_url_version_dict = self._parse_repos() repositories_url_semantic_version_dict: dict[str, Optional[str]] = { - url: (match.group(1) if (match := re.search(semantic_version_pattern, version)) else None) + url: (version if re.fullmatch(semantic_version_pattern, version) else None) for url, version in repository_url_version_dict.items() } return repositories_url_semantic_version_dict From 5a9b9672bcf3e3c7c598e2bbe4aa8cee0bb5306f Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Fri, 13 Sep 2024 11:54:50 +0900 Subject: [PATCH 03/19] fix(create-prs-to-update-vcs-repositories): fix README.md * Make clear what is the condition for creating a PR Signed-off-by: Junya Sasaki --- .../README.md | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index 3a4d4e3b..3fae317e 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -58,3 +58,44 @@ jobs: ## Outputs None. + +## What kind of tags are handled + +- Monitors all vcs-imported repositories in the ```autoware.repos``` (if default) which have a version with regular expression pattern ```r'\b(? 0.0.2 + 1.1.1 => 1.2.1 + 2.4.3 => 3.0.0 +``` + + - Invalid ones (PR is not created): +``` + main => 0.0.1 + v0.0.1 => 0.0.2 + xxx-0.0.1 => 0.0.9 + 0.0.1-rc1 => 0.0.2 +``` \ No newline at end of file From 308248e3781ee8a9a8ac01373921c19eaeed93ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 02:57:47 +0000 Subject: [PATCH 04/19] style(pre-commit): autofix --- create-prs-to-update-vcs-repositories/README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index 3fae317e..f28bad72 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -61,8 +61,9 @@ None. ## What kind of tags are handled -- Monitors all vcs-imported repositories in the ```autoware.repos``` (if default) which have a version with regular expression pattern ```r'\b(? 0.0.2 1.1.1 => 1.2.1 2.4.3 => 3.0.0 ``` - - Invalid ones (PR is not created): +- Invalid ones (PR is not created): + ``` main => 0.0.1 v0.0.1 => 0.0.2 xxx-0.0.1 => 0.0.9 0.0.1-rc1 => 0.0.2 -``` \ No newline at end of file +``` From f3159da861ee6bb8d366530c349b5afa34b50eb3 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Fri, 13 Sep 2024 12:32:00 +0900 Subject: [PATCH 05/19] fix(create-prs-to-update-vcs-repositories): specify language for fenced code block Signed-off-by: Junya Sasaki --- create-prs-to-update-vcs-repositories/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index 3fae317e..ccd5d553 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -63,7 +63,7 @@ None. - Monitors all vcs-imported repositories in the ```autoware.repos``` (if default) which have a version with regular expression pattern ```r'\b(? 0.0.2 1.1.1 => 1.2.1 2.4.3 => 3.0.0 ``` - Invalid ones (PR is not created): -``` +```plaintext main => 0.0.1 v0.0.1 => 0.0.2 xxx-0.0.1 => 0.0.9 From 747664a678bcc2c671e7dcd9ad89271a6650da9d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 03:34:10 +0000 Subject: [PATCH 06/19] style(pre-commit): autofix --- .../README.md | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index 333b282e..042d58f4 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -63,12 +63,15 @@ None. - Monitors all vcs-imported repositories in the `autoware.repos` (if default) which have a version with regular expression pattern `r'\b(?>>>>>> 308248e3781ee8a9a8ac01373921c19eaeed93ce + +> > > > > > > 308248e3781ee8a9a8ac01373921c19eaeed93ce + "0.0.1", # match "0.1.0", # match "1.0.0", # match @@ -85,7 +88,8 @@ None. "2.0.1-alpha.1227", # mismatch "1.0.0-alpha.beta", # mismatch "ros_humble-v0.10.2" # mismatch -``` + +```` ## What kind of version update is possible? @@ -96,12 +100,15 @@ None. ```plaintext ======= -``` ->>>>>>> 308248e3781ee8a9a8ac01373921c19eaeed93ce +```` + +> > > > > > > 308248e3781ee8a9a8ac01373921c19eaeed93ce + 0.0.1 => 0.0.2 1.1.1 => 1.2.1 2.4.3 => 3.0.0 -``` + +```` <<<<<<< HEAD - Invalid ones (PR is not created): @@ -109,10 +116,15 @@ None. ======= - Invalid ones (PR is not created): -``` ->>>>>>> 308248e3781ee8a9a8ac01373921c19eaeed93ce +```` + +> > > > > > > 308248e3781ee8a9a8ac01373921c19eaeed93ce + main => 0.0.1 v0.0.1 => 0.0.2 xxx-0.0.1 => 0.0.9 0.0.1-rc1 => 0.0.2 + +``` + ``` From 3a7feefb1fac6dccbf5e47ef2a8a3acefda2ac8f Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Fri, 13 Sep 2024 12:36:18 +0900 Subject: [PATCH 07/19] fix(create-prs-to-update-vcs-repositories): fix wrongly saved README.md Signed-off-by: Junya Sasaki --- create-prs-to-update-vcs-repositories/README.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index 333b282e..69d52958 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -63,12 +63,7 @@ None. - Monitors all vcs-imported repositories in the `autoware.repos` (if default) which have a version with regular expression pattern `r'\b(?>>>>>> 308248e3781ee8a9a8ac01373921c19eaeed93ce "0.0.1", # match "0.1.0", # match "1.0.0", # match @@ -92,25 +87,14 @@ None. - If there is a new version with pattern matched in the vcs-imported repositories, create a PR for each repository, respectively. - The valid/invalid version update cases are as follows: - Valid ones (PR must be created): -<<<<<<< HEAD ```plaintext -======= - -``` ->>>>>>> 308248e3781ee8a9a8ac01373921c19eaeed93ce 0.0.1 => 0.0.2 1.1.1 => 1.2.1 2.4.3 => 3.0.0 ``` -<<<<<<< HEAD - Invalid ones (PR is not created): ```plaintext -======= -- Invalid ones (PR is not created): - -``` ->>>>>>> 308248e3781ee8a9a8ac01373921c19eaeed93ce main => 0.0.1 v0.0.1 => 0.0.2 xxx-0.0.1 => 0.0.9 From 298bcad46f7d5bddf05f8de3b7c3771e28521216 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Fri, 13 Sep 2024 12:41:35 +0900 Subject: [PATCH 08/19] fix(create-prs-to-update-vcs-repositories): fix wrong plaintext annotation Signed-off-by: Junya Sasaki --- create-prs-to-update-vcs-repositories/README.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index eafa15ae..69d52958 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -80,8 +80,7 @@ None. "2.0.1-alpha.1227", # mismatch "1.0.0-alpha.beta", # mismatch "ros_humble-v0.10.2" # mismatch - -```` +``` ## What kind of version update is possible? @@ -92,8 +91,7 @@ None. 0.0.1 => 0.0.2 1.1.1 => 1.2.1 2.4.3 => 3.0.0 - -```` +``` - Invalid ones (PR is not created): ```plaintext @@ -101,7 +99,4 @@ None. v0.0.1 => 0.0.2 xxx-0.0.1 => 0.0.9 0.0.1-rc1 => 0.0.2 - -``` - ``` From ee772cf8bb007200a5e744abd4a8ea5c1339b638 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 03:42:19 +0000 Subject: [PATCH 09/19] style(pre-commit): autofix Signed-off-by: Junya Sasaki --- create-prs-to-update-vcs-repositories/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index 69d52958..df99342c 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -63,6 +63,7 @@ None. - Monitors all vcs-imported repositories in the `autoware.repos` (if default) which have a version with regular expression pattern `r'\b(? 0.0.2 1.1.1 => 1.2.1 2.4.3 => 3.0.0 ``` - - Invalid ones (PR is not created): +- Invalid ones (PR is not created): + ```plaintext main => 0.0.1 v0.0.1 => 0.0.2 From 6694ec4a8d4c4b604e1135e6cabff19cd665247e Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Fri, 13 Sep 2024 18:10:39 +0900 Subject: [PATCH 10/19] Update create-prs-to-update-vcs-repositories/README.md Co-authored-by: Ryohsuke Mitsudome <43976834+mitsudome-r@users.noreply.github.com> Signed-off-by: Junya Sasaki --- create-prs-to-update-vcs-repositories/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index df99342c..e161d8f4 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -59,7 +59,7 @@ jobs: None. -## What kind of tags are handled +## What kind of tags are handled? - Monitors all vcs-imported repositories in the `autoware.repos` (if default) which have a version with regular expression pattern `r'\b(? Date: Tue, 24 Sep 2024 16:51:28 +0900 Subject: [PATCH 11/19] fix(create-prs-to-update-vcs-repositories): fixes in semver (see below): * Do not allow to change the semver pattern via argument: use only fixed pattern. * Add description to make it explicit what kind of patterns are supported. Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 79 ++++++++++++------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index 27b612d0..53f4b569 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -1,3 +1,47 @@ +''' +Description: + + In this script, we create a PR to update the version of the repository specified by the URL in autoware.repos. + The steps are as follows: + 1. Get the repositories with semantic version tags + 1-1. Currently we only support the semantic version pattern of r'\b(? argparse.Namespace: args_repo.add_argument("--base_branch", type=str, default="main", help="The base branch of autoware.repos") args_repo.add_argument("--new_branch_prefix", type=str, default="feat/update-", help="The prefix of the new branch name") - DEFAULT_SEMANTIC_VERSION_PATTERN = r'\b(? None: # 'https://github.com/user/repo.git': '0.0.1', # Pattern matched # 'https://github.com/user/repo2.git': None, # Pattern not matched # } - repositories_url_semantic_version_dict: dict[str, str] = autoware_repos.pickup_semver_repositories(semantic_version_pattern = args.semantic_version_pattern) + repositories_url_semantic_version_dict: dict[str, str] = autoware_repos.pickup_semver_repositories(semantic_version_pattern = SUPPORTED_SEMANTIC_VERSION_PATTERN) # Get reference to the repository repo = git.Repo(args.parent_dir) From d42ae1c289440d0ecbd286563b3cea82298fb791 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Thu, 26 Sep 2024 18:36:57 +0900 Subject: [PATCH 12/19] feat(create-prs-to-update-vcs-repositories): support release types (see below): * Support separated PRs for major, minor, and patch updates * If not specified, PR will be created for any updates Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 263 +++++++++++------- 1 file changed, 169 insertions(+), 94 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index 53f4b569..d6158636 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -38,8 +38,34 @@ ``` python create_prs_to_update_vcs_repositories.py --major --minor ``` -''' +Example usage: + + Example 1: Create PRs for major updates + ``` + python create_prs_to_update_vcs_repositories.py --autoware_repos_file_name autoware.repos --targets major + ``` + + Example 2: Create PRs for minor updates + ``` + python create_prs_to_update_vcs_repositories.py --autoware_repos_file_name autoware.repos --targets minor + ``` + + Example 3: Create PRs for patch updates + ``` + python create_prs_to_update_vcs_repositories.py --autoware_repos_file_name autoware.repos --targets patch + ``` + + Example 4: Create PRs for major and minor updates + ``` + python create_prs_to_update_vcs_repositories.py --autoware_repos_file_name files.repos/autoware.repos --targets major minor + ``` + + Example 5: Create PRs for any updates + ``` + python create_prs_to_update_vcs_repositories.py --autoware_repos_file_name autoware.repos --targets any + ``` +''' import os @@ -179,6 +205,15 @@ def parse_args() -> argparse.Namespace: args_repo.add_argument("--base_branch", type=str, default="main", help="The base branch of autoware.repos") args_repo.add_argument("--new_branch_prefix", type=str, default="feat/update-", help="The prefix of the new branch name") + # Define an argument to specify which version components to check + args_repo.add_argument( + '--targets', + choices=['major', 'minor', 'patch', 'any'], # Restrict choices to 'major', 'minor', 'patch', and 'any' + nargs='+', # Allow multiple values + default=['any'], # Default is 'any': in this case, consider any version newer than the current + help='Specify the version component targets to check for updates (e.g., --targets major minor)' + ) + # For the Autoware args_aw = parser.add_argument_group("Autoware") args_aw.add_argument("--autoware_repos_file_name", type=str, default="autoware.repos", help="The path to autoware.repos") @@ -199,29 +234,66 @@ def get_logger(verbose: int) -> logging.Logger: return logging.getLogger(__name__) -def get_latest_tag(tags: list[str], current_version: str) -> Optional[str]: +def get_latest_tag(tags: list[str], current_version: str, target_release: str) -> Optional[str]: ''' Description: - Get the latest tag from the list of tags + Get the latest tag from the list of tags based on the specified target release type. Args: - tags (list[str]): a list of tags - current_version (str): the current version of the repository + tags (list[str]): A list of tags. + current_version (str): The current version of the repository. + target_release (str): The type of release to check for updates. Can be 'major', 'minor', 'patch', or 'any'. + + Returns: + Optional[str]: The latest tag that matches the target release type, or None if not found. + + Raises: + ValueError: If an invalid target_release is specified. ''' + + valid_releases = {'major', 'minor', 'patch', 'any'} + if target_release not in valid_releases: + raise ValueError(f"Invalid target_release '{target_release}'. Valid options are: {valid_releases}") + + current_ver = version.parse(current_version) latest_tag = None + for tag in tags: - # Exclude parse failed ones such as 'tier4/universe', 'main', ... etc try: - version.parse(tag) + parsed_tag = version.parse(tag) except (version.InvalidVersion, TypeError): continue - # OK, it's a valid version - if latest_tag is None: - latest_tag = tag - else: - if version.parse(tag) > version.parse(latest_tag): - latest_tag = tag + # Skip pre-releases or development versions if not needed + if parsed_tag.is_prerelease or parsed_tag.is_devrelease: + continue + + # Determine if the tag matches the required update type + if target_release == 'major': + if parsed_tag.major > current_ver.major: + # Only consider tags with a higher major version + if latest_tag is None or parsed_tag < version.parse(latest_tag): + latest_tag = tag + + elif target_release == 'minor': + if parsed_tag.major == current_ver.major and parsed_tag.minor > current_ver.minor: + # Only consider tags with the same major but higher minor version + if latest_tag is None or parsed_tag < version.parse(latest_tag): + latest_tag = tag + + elif target_release == 'patch': + if (parsed_tag.major == current_ver.major and + parsed_tag.minor == current_ver.minor and + parsed_tag.micro > current_ver.micro): + # Only consider tags with the same major and minor but higher patch version + if latest_tag is None or parsed_tag < version.parse(latest_tag): + latest_tag = tag + + elif target_release == 'any': + # Consider any version newer than the current version + if parsed_tag > current_ver: + if latest_tag is None or parsed_tag < version.parse(latest_tag): + latest_tag = tag return latest_tag @@ -262,107 +334,110 @@ def main(args: argparse.Namespace) -> None: # Get reference to the repository repo = git.Repo(args.parent_dir) - # Get all the branches - branches = [r.remote_head for r in repo.remote().refs] - - for url, current_version in repositories_url_semantic_version_dict.items(): - ''' - Description: - In this loop, the script will create a PR to update the version of the repository specified by the URL. - The step is as follows: - 1. Get tags of the repository - 2. Check if the current version is the latest - 3. Get the latest tag - 4. Create a new branch - 5. Update autoware.repos - 6. Commit and push - 7. Create a PR - ''' - - # Skip if the current version has an invalid format - if current_version is None: - logger.debug(f"The current version ({current_version}) format has a mismatched pattern. Skip for this repository:\n {url}") - continue + # Get all the existing branches + existing_branches = [r.remote_head for r in repo.remote().refs] + + # Check for each target release type (e.g., major, minor, patch, any) + for target in args.targets: + # Check for each repository + for url, current_version in repositories_url_semantic_version_dict.items(): + ''' + Description: + In this loop, the script will create a PR to update the version of the repository specified by the URL. + The step is as follows: + 1. Get tags of the repository + 2. Check if the current version is the latest + 3. Get the latest tag + 4. Create a new branch + 5. Update autoware.repos + 6. Commit and push + 7. Create a PR + ''' + + # Skip if the current version has an invalid format + if current_version is None: + logger.debug(f"The current version ({current_version}) format has a mismatched pattern. Skip for this repository:\n {url}") + continue - # get tags of the repository - tags: list[str] = github_interface.get_tags_by_url(url) + # get tags of the repository + tags: list[str] = github_interface.get_tags_by_url(url) - latest_tag: Optional[str] = get_latest_tag(tags, current_version) + latest_tag: Optional[str] = get_latest_tag(tags, current_version, target_release=target) - # Skip if the expected format is not found - if latest_tag is None: - logger.debug(f"The latest tag ({latest_tag}) format has a mismatched pattern. Skip for this repository:\n {url}") - continue + # Skip if the expected format is not found + if latest_tag is None: + logger.debug(f"The latest tag ({latest_tag}) format has a mismatched pattern. Skip for this repository:\n {url}") + continue - # Exclude parse failed ones such as 'tier4/universe', 'main', ... etc - try: - # If current version is a valid version, compare with the current version - logger.debug(f"url: {url}, latest_tag: {latest_tag}, current_version: {current_version}") - if version.parse(latest_tag) > version.parse(current_version): - # OK, the latest tag is newer than the current version - pass - else: - # The current version is the latest - logger.debug(f"Repository {url} has the latest version {current_version}. Skip for this repository.") + # Exclude parse failed ones such as 'tier4/universe', 'main', ... etc + try: + # If current version is a valid version, compare with the current version + logger.debug(f"url: {url}, latest_tag: {latest_tag}, current_version: {current_version}") + if version.parse(latest_tag) > version.parse(current_version): + # OK, the latest tag is newer than the current version + pass + else: + # The current version is the latest + logger.debug(f"Repository {url} has the latest version {current_version}. Skip for this repository.") + continue + except (version.InvalidVersion, TypeError): + # If the current version is not a valid version, skip this repository continue - except (version.InvalidVersion, TypeError): - # If the current version is not a valid version, skip this repository - continue - # Get repository name - repo_name: str = github_interface.url_to_repository_name(url) + # Get repository name + repo_name: str = github_interface.url_to_repository_name(url) - # Set branch name - branch_name: str = f"{args.new_branch_prefix}{repo_name}/{latest_tag}" + # Set branch name + branch_name: str = f"{args.new_branch_prefix}{repo_name}/{latest_tag}" - # Check if the remote branch already exists - if branch_name in branches: - logger.info(f"Branch '{branch_name}' already exists on the remote.") - continue + # Skip if the remote branch already exists + if branch_name in existing_branches: + logger.info(f"Branch '{branch_name}' already exists on the remote.") + continue - # First, create a branch - create_one_branch(repo, branch_name, logger) + # First, create a branch + create_one_branch(repo, branch_name, logger) - # Switch to the branch - repo.heads[branch_name].checkout() + # Switch to the branch + repo.heads[branch_name].checkout() - # Change version in autoware.repos - autoware_repos.update_repository_version(url, latest_tag) + # Change version in autoware.repos + autoware_repos.update_repository_version(url, latest_tag) - # Add - repo.index.add([args.autoware_repos_file_name]) + # Add + repo.index.add([args.autoware_repos_file_name]) - # Commit - commit_message = f"feat(autoware.repos): update {repo_name} to {latest_tag}" - repo.git.commit(m=commit_message, s=True) + # Commit + title = f"feat({args.autoware_repos_file_name}): {"version" if target == 'any' else target} update {repo_name} to {latest_tag}" + repo.git.commit(m=title, s=True) - # Push - origin = repo.remote(name='origin') - origin.push(branch_name) + # Push + origin = repo.remote(name='origin') + origin.push(branch_name) - # Switch back to base branch - repo.heads[args.base_branch].checkout() + # Switch back to base branch + repo.heads[args.base_branch].checkout() - # Create a PR - github_interface.create_pull_request( - repo_name = args.repo_name, - title = f"feat(autoware.repos): update {repo_name} to {latest_tag}", - body = f"This PR updates the version of the repository {repo_name} in autoware.repos", - head = branch_name, - base = args.base_branch - ) + # Create a PR + github_interface.create_pull_request( + repo_name = args.repo_name, + title = title, + body = f"This PR updates the version of the repository {repo_name} in autoware.repos", + head = branch_name, + base = args.base_branch + ) - # Switch back to base branch - repo.heads[args.base_branch].checkout() + # Switch back to base branch + repo.heads[args.base_branch].checkout() - # Reset any changes - repo.git.reset('--hard', f'origin/{args.base_branch}') + # Reset any changes + repo.git.reset('--hard', f'origin/{args.base_branch}') - # Clean untracked files - repo.git.clean('-fd') + # Clean untracked files + repo.git.clean('-fd') - # Restore base's autoware.repos - autoware_repos: AutowareRepos = AutowareRepos(autoware_repos_file_name = args.autoware_repos_file_name) + # Restore base's autoware.repos + autoware_repos: AutowareRepos = AutowareRepos(autoware_repos_file_name = args.autoware_repos_file_name) # Loop end From ab681c8a88469a7d292747e8a8c493d23e11ed02 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Thu, 26 Sep 2024 18:46:59 +0900 Subject: [PATCH 13/19] fix(create-prs-to-update-vcs-repositories): ignore a word "devrelease" from spell check Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index d6158636..115d7db9 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -265,7 +265,7 @@ def get_latest_tag(tags: list[str], current_version: str, target_release: str) - continue # Skip pre-releases or development versions if not needed - if parsed_tag.is_prerelease or parsed_tag.is_devrelease: + if parsed_tag.is_prerelease or parsed_tag.is_devrelease: # cspell: ignore devrelease continue # Determine if the tag matches the required update type From 8158c26d479c8c0d15f1ce941b6d00136e21cd79 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Thu, 26 Sep 2024 19:11:03 +0900 Subject: [PATCH 14/19] fix(create-prs-to-update-vcs-repositories): apply missing updates Signed-off-by: Junya Sasaki --- create-prs-to-update-vcs-repositories/README.md | 10 ++++++---- create-prs-to-update-vcs-repositories/action.yaml | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/README.md b/create-prs-to-update-vcs-repositories/README.md index e161d8f4..90a2b86f 100644 --- a/create-prs-to-update-vcs-repositories/README.md +++ b/create-prs-to-update-vcs-repositories/README.md @@ -37,6 +37,7 @@ jobs: token: ${{ steps.generate-token.outputs.token }} repo_name: autowarefoundation/autoware parent_dir: . + targets: major minor base_branch: main new_branch_prefix: feat/update- autoware_repos_file_name: autoware.repos @@ -49,6 +50,7 @@ jobs: | ------------------------ | -------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------- | | token | true | | The token for pull requests. | | repo_name | true | | The name of the repository to create pull requests. | +| targets | false | any | The target release types (choices: any, patch, minor, major). | | parent_dir | false | . | The parent directory of the repository. | | base_branch | false | main | The base branch to create pull requests. | | new_branch_prefix | false | feat/update- | The prefix of the new branch name. The branch name will be `{new_branch_prefix}-{user_name}/{repository_name}/{new_version}`. | @@ -61,7 +63,7 @@ None. ## What kind of tags are handled? -- Monitors all vcs-imported repositories in the `autoware.repos` (if default) which have a version with regular expression pattern `r'\b(? 0.0.2 - 1.1.1 => 1.2.1 - 2.4.3 => 3.0.0 + 0.0.1 => 0.0.2 # If `--target patch` or `--target any` is specified + 1.1.1 => 1.2.1 # If `--target minor` or `--target any` is specified + 2.4.3 => 3.0.0 # If `--target major` or `--target any` is specified ``` - Invalid ones (PR is not created): diff --git a/create-prs-to-update-vcs-repositories/action.yaml b/create-prs-to-update-vcs-repositories/action.yaml index d972b5f7..bdddcd71 100644 --- a/create-prs-to-update-vcs-repositories/action.yaml +++ b/create-prs-to-update-vcs-repositories/action.yaml @@ -12,6 +12,10 @@ inputs: description: Parent directory required: false default: ./ + targets: + description: Target release types + required: false + default: "any" base_branch: description: Base branch required: false @@ -63,6 +67,7 @@ runs: python ${GITHUB_ACTION_PATH}/create_prs_to_update_vcs_repositories.py \ --repo_name ${{ inputs.repo_name }} \ --parent_dir ${{ inputs.parent_dir }} \ + --targets ${{ inputs.targets }} \ --base_branch ${{ inputs.base_branch }} \ --new_branch_prefix ${{ inputs.new_branch_prefix }} \ --autoware_repos_file_name ${{ inputs.autoware_repos_file_name }} \ From 4c330754a1f5e30b02923df8f7a649f0e9535648 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Mon, 30 Sep 2024 14:08:12 +0900 Subject: [PATCH 15/19] fix(create-prs-to-update-vcs-repositories): bug fix (see below): * The existing branch list is not updated correctly. When major, minor, patch, and any are all enabled, The same name branch can be processed twice. This eventually causes an error like: ``` nothing to commit ``` Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index 115d7db9..4fc258cc 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -395,6 +395,9 @@ def main(args: argparse.Namespace) -> None: logger.info(f"Branch '{branch_name}' already exists on the remote.") continue + # Add this branch to the existing branches + existing_branches.append(branch_name) + # First, create a branch create_one_branch(repo, branch_name, logger) From 17f6251a76ab68114b39963371e081714567edad Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Tue, 1 Oct 2024 16:45:36 +0900 Subject: [PATCH 16/19] fix(create-prs-to-update-vcs-repositories): cosmetic fix * The information is duplicated that of README.md Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 70 ------------------- 1 file changed, 70 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index 4fc258cc..57062f6b 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -1,73 +1,3 @@ -''' -Description: - - In this script, we create a PR to update the version of the repository specified by the URL in autoware.repos. - The steps are as follows: - 1. Get the repositories with semantic version tags - 1-1. Currently we only support the semantic version pattern of r'\b(? Date: Tue, 1 Oct 2024 17:02:39 +0900 Subject: [PATCH 17/19] fix(create-prs-to-update-vcs-repositories): fix code duplication Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index 57062f6b..89444dbf 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -14,6 +14,9 @@ # Define the semantic version pattern here SUPPORTED_SEMANTIC_VERSION_PATTERN = r'\b(? argparse.Namespace: # Define an argument to specify which version components to check args_repo.add_argument( '--targets', - choices=['major', 'minor', 'patch', 'any'], # Restrict choices to 'major', 'minor', 'patch', and 'any' + choices=VALID_RELEASES, # Restrict choices nargs='+', # Allow multiple values default=['any'], # Default is 'any': in this case, consider any version newer than the current help='Specify the version component targets to check for updates (e.g., --targets major minor)' @@ -181,9 +184,8 @@ def get_latest_tag(tags: list[str], current_version: str, target_release: str) - ValueError: If an invalid target_release is specified. ''' - valid_releases = {'major', 'minor', 'patch', 'any'} - if target_release not in valid_releases: - raise ValueError(f"Invalid target_release '{target_release}'. Valid options are: {valid_releases}") + if target_release not in VALID_RELEASES: + raise ValueError(f"Invalid target_release '{target_release}'. Valid options are: {VALID_RELEASES}") current_ver = version.parse(current_version) latest_tag = None From 55dd97b82277c702d9aa7231c67dbbd03c392fb9 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Tue, 1 Oct 2024 17:04:26 +0900 Subject: [PATCH 18/19] fix(create-prs-to-update-vcs-repositories): cosmetic fix * Keep consistent indentation Signed-off-by: Junya Sasaki --- .../create_prs_to_update_vcs_repositories.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py index 89444dbf..87f5138a 100644 --- a/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py +++ b/create-prs-to-update-vcs-repositories/create_prs_to_update_vcs_repositories.py @@ -141,9 +141,9 @@ def parse_args() -> argparse.Namespace: # Define an argument to specify which version components to check args_repo.add_argument( '--targets', - choices=VALID_RELEASES, # Restrict choices - nargs='+', # Allow multiple values - default=['any'], # Default is 'any': in this case, consider any version newer than the current + choices=VALID_RELEASES, # Restrict choices + nargs='+', # Allow multiple values + default=['any'], # Default is 'any': in this case, consider any version newer than the current help='Specify the version component targets to check for updates (e.g., --targets major minor)' ) From e653faea7556311f21e5ded9eceb0eeeb2374194 Mon Sep 17 00:00:00 2001 From: Junya Sasaki Date: Tue, 1 Oct 2024 18:02:17 +0900 Subject: [PATCH 19/19] fix(create-prs-to-update-vcs-repositories): fix a yamllint bug Signed-off-by: Junya Sasaki --- create-prs-to-update-vcs-repositories/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create-prs-to-update-vcs-repositories/action.yaml b/create-prs-to-update-vcs-repositories/action.yaml index bdddcd71..540c9f55 100644 --- a/create-prs-to-update-vcs-repositories/action.yaml +++ b/create-prs-to-update-vcs-repositories/action.yaml @@ -15,7 +15,7 @@ inputs: targets: description: Target release types required: false - default: "any" + default: any base_branch: description: Base branch required: false