- Notifications
You must be signed in to change notification settings - Fork261
feat(cmd-version): add support for partial tags#1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
0acaf5504eac97e3df3f7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -75,10 +75,13 @@ def is_forced_prerelease( | ||||||
| ) | ||||||
| def last_released( | ||||||
| repo_dir: Path, tag_format: str, add_partial_tags: bool = False | ||||||
| ) -> tuple[Tag, Version] | None: | ||||||
| with Repo(str(repo_dir)) as git_repo: | ||||||
| ts_and_vs = tags_and_versions( | ||||||
| git_repo.tags, | ||||||
| VersionTranslator(tag_format=tag_format, add_partial_tags=add_partial_tags), | ||||||
| ) | ||||||
| return ts_and_vs[0] if ts_and_vs else None | ||||||
| @@ -449,7 +452,11 @@ def version( # noqa: C901 | ||||||
| if print_last_released or print_last_released_tag: | ||||||
| # TODO: get tag format a better way | ||||||
| if not ( | ||||||
| last_release := last_released( | ||||||
| config.repo_dir, | ||||||
| tag_format=config.tag_format, | ||||||
| add_partial_tags=config.add_partial_tags, | ||||||
| ) | ||||||
| ): | ||||||
| logger.warning("No release tags found.") | ||||||
| return | ||||||
| @@ -470,6 +477,7 @@ def version( # noqa: C901 | ||||||
| major_on_zero = runtime.major_on_zero | ||||||
| no_verify = runtime.no_git_verify | ||||||
| opts = runtime.global_cli_options | ||||||
| add_partial_tags = config.add_partial_tags | ||||||
| gha_output = VersionGitHubActionsOutput( | ||||||
| gh_client=hvcs_client if isinstance(hvcs_client, Github) else None, | ||||||
| mode=( | ||||||
| @@ -744,6 +752,27 @@ def version( # noqa: C901 | ||||||
| tag=new_version.as_tag(), | ||||||
| noop=opts.noop, | ||||||
| ) | ||||||
| # Create or update partial tags for releases | ||||||
| if add_partial_tags and not prerelease: | ||||||
| partial_tags = [new_version.as_major_tag(), new_version.as_minor_tag()] | ||||||
| # If build metadata is set, also retag the version without the metadata | ||||||
| if build_metadata: | ||||||
| partial_tags.append(new_version.as_patch_tag()) | ||||||
| for partial_tag in partial_tags: | ||||||
| project.git_tag( | ||||||
| tag_name=partial_tag, | ||||||
| message=f"{partial_tag} is {new_version.as_tag()}", | ||||||
CopilotAI | ||||||
| message=f"{partial_tag} is{new_version.as_tag()}", | |
| message=f"Tracks{new_version.as_tag()}", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -197,7 +197,12 @@ def git_commit( | ||
| raise GitCommitError("Failed to commit changes") from err | ||
| def git_tag( | ||
| self, | ||
| tag_name: str, | ||
| message: str, | ||
| isotimestamp: str, | ||
| force: bool = False, | ||
| noop: bool = False, | ||
| ) -> None: | ||
| try: | ||
| datetime.fromisoformat(isotimestamp) | ||
| @@ -207,21 +212,25 @@ def git_tag( | ||
| if noop: | ||
| command = str.join( | ||
| " ", | ||
| filter( | ||
| None, | ||
| [ | ||
| f"GIT_COMMITTER_DATE={isotimestamp}", | ||
| *( | ||
| [ | ||
| f"GIT_AUTHOR_NAME={self._commit_author.name}", | ||
| f"GIT_AUTHOR_EMAIL={self._commit_author.email}", | ||
| f"GIT_COMMITTER_NAME={self._commit_author.name}", | ||
| f"GIT_COMMITTER_EMAIL={self._commit_author.email}", | ||
| ] | ||
| if self._commit_author | ||
| else [""] | ||
| ), | ||
| f"git tag -a {tag_name} -m '{message}'", | ||
| "--force" if force else "", | ||
| ], | ||
| ), | ||
| ).strip() | ||
CopilotAI | ||
| noop_report( | ||
| indented( | ||
| @@ -238,7 +247,7 @@ def git_tag( | ||
| {"GIT_COMMITTER_DATE": isotimestamp}, | ||
| ): | ||
| try: | ||
| repo.git.tag(tag_name, a=True, m=message, force=force) | ||
| except GitCommandError as err: | ||
| self.logger.exception(str(err)) | ||
| raise GitTagError(f"Failed to create tag ({tag_name})") from err | ||
| @@ -264,21 +273,23 @@ def git_push_branch(self, remote_url: str, branch: str, noop: bool = False) -> N | ||
| f"Failed to push branch ({branch}) to remote" | ||
| ) from err | ||
| def git_push_tag( | ||
| self, remote_url: str, tag: str, noop: bool = False, force: bool = False | ||
| ) -> None: | ||
| if noop: | ||
| noop_report( | ||
| indented( | ||
| f"""\ | ||
| would have run: | ||
| git push {self._cred_masker.mask(remote_url)} tag {tag} {"--force" if force else ""} | ||
| """ # noqa: E501 | ||
| ) | ||
| ) | ||
| return | ||
| with Repo(str(self.project_root)) as repo: | ||
| try: | ||
| repo.git.push(remote_url, "tag", tag, force=force) | ||
| except GitCommandError as err: | ||
| self.logger.exception(str(err)) | ||
| raise GitPushError(f"Failed to push tag ({tag}) to remote") from err | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -42,11 +42,17 @@ def __init__( | ||||||||||
| self, | ||||||||||
| tag_format: str = "v{version}", | ||||||||||
| prerelease_token: str = "rc", # noqa: S107 | ||||||||||
| add_partial_tags: bool = False, | ||||||||||
| ) -> None: | ||||||||||
| check_tag_format(tag_format) | ||||||||||
| self.tag_format = tag_format | ||||||||||
| self.prerelease_token = prerelease_token | ||||||||||
| self.add_partial_tags = add_partial_tags | ||||||||||
| self.from_tag_re = self._invert_tag_format_to_re(self.tag_format) | ||||||||||
| self.partial_tag_re = re.compile( | ||||||||||
| tag_format.replace(r"{version}", r"[0-9]+(\.(0|[1-9][0-9]*))?$"), | ||||||||||
CopilotAI | ||||||||||
| tag_format.replace(r"{version}",r"[0-9]+(\.(0|[1-9][0-9]*))?$"), | |
| re.escape(tag_format).replace( | |
| re.escape("{version}"),r"[0-9]+(\.(0|[1-9][0-9]*))?$" | |
| ), |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.