Skip to content

Commit

Permalink
Allow prereleases from prepare-release workflow (#8628)
Browse files Browse the repository at this point in the history
Fix #7551
  • Loading branch information
nicoddemus committed Jun 24, 2021
1 parent d7b0e17 commit 0d6cb3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/prepare-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down Expand Up @@ -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 }}'
20 changes: 13 additions & 7 deletions scripts/prepare-release-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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:
Expand All @@ -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,
)


Expand Down

0 comments on commit 0d6cb3b

Please sign in to comment.