Skip to content

Commit

Permalink
Allow prereleases from prepare-release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed May 4, 2021
1 parent 2637ec3 commit 116ab3d
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", including the quotes)'
required: true
default: '""'

jobs:
build:
Expand All @@ -34,9 +38,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 }} ${{ secrets.chatops }}
tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ secrets.chatops }} --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 }} ${{ secrets.chatops }} --major
tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ secrets.chatops }} --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 @@ -47,14 +47,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 @@ -116,7 +118,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 @@ -134,11 +136,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 @@ -147,9 +149,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 116ab3d

Please sign in to comment.