def determine_release_tag(ctx: TagContext) -> None: click.secho("> Determining the release tag.", fg="cyan") head_ref = ctx.release_pr["head"]["ref"] click.secho(f"PR head ref is {head_ref}") match = re.match(r"release-(.+)-v(\d+\.\d+\.\d+)", head_ref) rp13_match = re.match(r"release-please--branches--(.+)--components--(.+)", head_ref) title_match = re.match(r"chore\(.+\): release (.+) (\d+\.\d+\.\d+)", ctx.release_pr["title"]) if match is not None: ctx.package_name = match.group(1) ctx.release_version = match.group(2) ctx.release_tag = f"{ctx.package_name}/v{ctx.release_version}" elif rp13_match is not None and title_match is not None: ctx.package_name = title_match.group(1) ctx.release_version = title_match.group(2) ctx.release_tag = f"{ctx.package_name}/v{ctx.release_version}" if ctx.release_tag is None: click.secho( "I couldn't determine what the release tag should be from the PR's " f"head ref {head_ref}.", fg="red", ) ctx.release_tag = click.prompt( "What should the release tag be (for example, google-cloud-storage/v1.2.3)?" ) click.secho(f"Package name is {ctx.package_name}") click.secho(f"Package version is {ctx.release_version}") click.secho(f"Release tag is {ctx.release_tag}")
def determine_release_tag(ctx: TagContext) -> None: click.secho("> Determining what the release tag should be.", fg="cyan") head_ref = ctx.release_pr["head"]["ref"] ctx.release_tag = _parse_release_tag(head_ref) if ctx.release_tag is None: click.secho( "I couldn't determine what the release tag should be from the PR's" f"head ref {head_ref}.", fg="red", ) ctx.release_tag = click.prompt( "What should the release tag be (for example, storage-1.2.3)?") click.secho(f"Release tag is {ctx.release_tag}.")
def determine_release_tag(ctx: TagContext) -> None: click.secho("> Determining what the release tag should be.", fg="cyan") head_ref = ctx.release_pr["head"]["ref"] match = re.match("release-(.+)", head_ref) if match is not None: ctx.release_tag = match.group(1) else: print( "I couldn't determine what the release tag should be from the PR's" f"head ref {head_ref}.") ctx.release_tag = click.prompt( "What should the release tag be (for example, storage-1.2.3)?") click.secho(f"Release tag is {ctx.release_tag}.")
def determine_release_tag(ctx: TagContext) -> None: click.secho("> Determining what the release tag should be.", fg="cyan") head_ref = ctx.release_pr["head"]["ref"] # try release-please v13 pull requests title = ctx.release_pr["title"] match = re.match("chore\\(.*\\): release (\\d+\\.\\d+\\.\\d+.*)", title) if match is not None: ctx.release_tag = f"v{match.group(1)}" return match = re.match("release-(.+)", head_ref) if match is not None: ctx.release_tag = match.group(1) else: print( "I couldn't determine what the release tag should be from the PR's" f"head ref {head_ref}.") ctx.release_tag = click.prompt( "What should the release tag be (for example, v1.2.3)?") click.secho(f"Release tag is {ctx.release_tag}.")
def determine_release_tag(ctx: TagContext) -> None: click.secho("> Determining the release tag.", fg="cyan") head_ref = ctx.release_pr["head"]["ref"] click.secho(f"PR head ref is {head_ref}") match = re.match(r"^release-([a-z-]+)-v(\d\.\d.\d)$", head_ref) if match is not None: ctx.package_name = match.group(1) ctx.release_version = match.group(2) ctx.release_tag = f"{ctx.package_name}/v{ctx.release_version}" else: click.secho( "I couldn't determine what the release tag should be from the PR's" f"head ref {head_ref}.", fg="red", ) ctx.release_tag = click.prompt( "What should the release tag be (for example, google-cloud-storage/v1.2.3)?" ) determine_package_name_and_version(ctx) click.secho(f"Package name is {ctx.package_name}") click.secho(f"Package version is {ctx.release_version}") click.secho(f"Release tag is {ctx.release_tag}")
def create_releases(ctx: TagContext) -> None: click.secho("> Creating the release.") commitish = ctx.release_pr["merge_commit_sha"] title = ctx.release_pr["title"] body_lines = ctx.release_pr["body"].splitlines() all_lines = [title] + body_lines pr_comment = "" for line in all_lines: match = re.search(RELEASE_LINE_PATTERN, line) if match is not None: package = match.group(1) version = match.group(2) tag = package + "-" + version ctx.github.create_release( repository=ctx.upstream_repo, tag_name=tag, target_commitish=commitish, name=f"{package} version {version}", # TODO: either reformat the message as we do in TagReleases, # or make sure we create the PR with an "already-formatted" # body. (The latter is probably simpler, and will make the # PR easier to read anyway.) body=ctx.release_pr["body"], # Versions like "1.0.0-beta01" or "0.9.0" are prerelease prerelease="-" in version or version.startswith("0."), ) click.secho(f"Created release for {tag}") pr_comment = pr_comment + f"- Created release for {tag}\n" if pr_comment == "": raise ValueError("No releases found within pull request") ctx.github.create_pull_request_comment( ctx.upstream_repo, ctx.release_pr["number"], pr_comment ) # This isn't a tag, but that's okay - it just needs to be a commitish for # Kokoro to build against. ctx.release_tag = commitish repo_short_name = ctx.upstream_repo.split("/")[-1] ctx.kokoro_job_name = f"cloud-sharp/{repo_short_name}/gcp_windows/autorelease" ctx.github.update_pull_labels( ctx.release_pr, add=["autorelease: tagged"], remove=["autorelease: pending"] ) releasetool.commands.common.publish_via_kokoro(ctx)
def tag(ctx: TagContext = None) -> TagContext: if not ctx: ctx = TagContext() if ctx.interactive: click.secho(f"o/ Hey, {getpass.getuser()}, let's tag a release!", fg="magenta") if ctx.github is None: releasetool.commands.common.setup_github_context(ctx) # delegate releaase tagging to release-please default_branch = ctx.release_pr["base"]["ref"] repo = ctx.release_pr["base"]["repo"]["full_name"] with tempfile.NamedTemporaryFile("w+t", delete=False) as fp: fp.write(ctx.token) token_file = fp.name output = subprocess.check_output( [ "npx", "release-please", "github-release", f"--token={token_file}", f"--default-branch={default_branch}", "--release-type=java-yoshi", "--bump-minor-pre-major=true", f"--repo-url={repo}", "--package-name=", "--debug", ] ) ctx.release_tag = _parse_release_tag(output.decode("utf-8")) ctx.kokoro_job_name = kokoro_job_name(ctx.upstream_repo, ctx.package_name) if ctx.interactive: click.secho("\\o/ All done!", fg="magenta") return ctx
def create_releases(ctx: TagContext) -> None: click.secho("> Creating the release.") commitish = ctx.release_pr["merge_commit_sha"] lines = ctx.release_pr["body"].splitlines() pr_comment = "" for line in lines: match = re.search(RELEASE_LINE_PATTERN, line) if match is not None: package = match.group(1) version = match.group(2) tag = package + "-" + version ctx.github.create_release( repository=ctx.upstream_repo, tag_name=tag, target_commitish=commitish, name=tag, body=f"Package {package} version {version}", # Versions like "1.0.0-beta01" or "0.9.0" are prerelease prerelease="-" in version or version.startswith("0."), ) click.secho(f"Created release for {tag}") pr_comment = pr_comment + f"- Created release for {tag}\n" if pr_comment == "": raise ValueError("No releases found within pull request") ctx.github.create_pull_request_comment(ctx.upstream_repo, ctx.release_pr["number"], pr_comment) # This isn't a tag, but that's okay - it just needs to be a commitish for # Kokoro to build against. ctx.release_tag = commitish ctx.kokoro_job_name = f"cloud-sharp/google-cloud-dotnet/gcp_windows/autorelease" ctx.github.update_pull_labels(ctx.release_pr, add=["autorelease: tagged"], remove=["autorelease: pending"]) releasetool.commands.common.publish_via_kokoro(ctx)
def tag(ctx: TagContext = None) -> TagContext: if not ctx: ctx = TagContext() if ctx.interactive: click.secho(f"o/ Hey, {getpass.getuser()}, let's tag a release!", fg="magenta") if ctx.github is None: releasetool.commands.common.setup_github_context(ctx) if ctx.release_pr is None: determine_release_pr(ctx) # If using manifest release, the manifest releaser determines # release tag, version, and release notes: if ctx.upstream_repo not in manifest_release: determine_release_tag(ctx) determine_package_version(ctx) # If the release already exists, don't do anything if releasetool.commands.common.release_exists(ctx): click.secho(f"{ctx.release_tag} already exists.", fg="magenta") return ctx get_release_notes(ctx) else: # If using mono-release strategy, fallback to using sha from # time of merge: ctx.release_tag = ctx.release_pr["merge_commit_sha"] create_release(ctx) ctx.kokoro_job_name = kokoro_job_name(ctx.upstream_repo, ctx.package_name) releasetool.commands.common.publish_via_kokoro(ctx) if ctx.interactive: click.secho("\\o/ All done!", fg="magenta") return ctx