From 0d6cb3b281f972951349de50dea36d38846fbe31 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 24 Jun 2021 15:05:56 -0300 Subject: [PATCH] Allow prereleases from prepare-release workflow (#8628) Fix #7551 --- .github/workflows/prepare-release-pr.yml | 8 ++++++-- scripts/prepare-release-pr.py | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/prepare-release-pr.yml b/.github/workflows/prepare-release-pr.yml index 91977f5b2..7fa036613 100644 --- a/.github/workflows/prepare-release-pr.yml +++ b/.github/workflows/prepare-release-pr.yml @@ -11,6 +11,10 @@ on: description: 'Major release? (yes/no)' required: true default: 'no' + prerelease: + description: 'Prerelease (ex: rc1). Leave empty if not a pre-release.' + required: true + default: '' # Set permissions at the job level. permissions: {} @@ -41,9 +45,9 @@ jobs: - name: Prepare release PR (minor/patch release) if: github.event.inputs.major == 'no' run: | - tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ github.token }} + tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ github.token }} --prerelease '${{ github.event.inputs.prerelease }}' - name: Prepare release PR (major release) if: github.event.inputs.major == 'yes' run: | - tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ github.token }} --major + tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ github.token }} --major --prerelease '${{ github.event.inputs.prerelease }}' diff --git a/scripts/prepare-release-pr.py b/scripts/prepare-release-pr.py index ca5ed411a..27152fea1 100644 --- a/scripts/prepare-release-pr.py +++ b/scripts/prepare-release-pr.py @@ -46,14 +46,16 @@ def login(token: str) -> Repository: return github.repository(owner, repo) -def prepare_release_pr(base_branch: str, is_major: bool, token: str) -> None: +def prepare_release_pr( + base_branch: str, is_major: bool, token: str, prerelease: str +) -> None: print() print(f"Processing release for branch {Fore.CYAN}{base_branch}") check_call(["git", "checkout", f"origin/{base_branch}"]) try: - version = find_next_version(base_branch, is_major) + version = find_next_version(base_branch, is_major, prerelease) except InvalidFeatureRelease as e: print(f"{Fore.RED}{e}") raise SystemExit(1) @@ -115,7 +117,7 @@ def prepare_release_pr(base_branch: str, is_major: bool, token: str) -> None: print(f"Pull request {Fore.CYAN}{pr.url}{Fore.RESET} created.") -def find_next_version(base_branch: str, is_major: bool) -> str: +def find_next_version(base_branch: str, is_major: bool, prerelease: str) -> str: output = check_output(["git", "tag"], encoding="UTF-8") valid_versions = [] for v in output.splitlines(): @@ -133,11 +135,11 @@ def find_next_version(base_branch: str, is_major: bool) -> str: is_feature_release = features or breaking if is_major: - return f"{last_version[0]+1}.0.0" + return f"{last_version[0]+1}.0.0{prerelease}" elif is_feature_release: - return f"{last_version[0]}.{last_version[1] + 1}.0" + return f"{last_version[0]}.{last_version[1] + 1}.0{prerelease}" else: - return f"{last_version[0]}.{last_version[1]}.{last_version[2] + 1}" + return f"{last_version[0]}.{last_version[1]}.{last_version[2] + 1}{prerelease}" def main() -> None: @@ -146,9 +148,13 @@ def main() -> None: parser.add_argument("base_branch") parser.add_argument("token") parser.add_argument("--major", action="store_true", default=False) + parser.add_argument("--prerelease", default="") options = parser.parse_args() prepare_release_pr( - base_branch=options.base_branch, is_major=options.major, token=options.token + base_branch=options.base_branch, + is_major=options.major, + token=options.token, + prerelease=options.prerelease, )