def update(spec, force=False): prev = get_version() is_final = not is_prerelease(prev) if is_final and spec == "release": raise Exception( 'Use "major" or "minor" to switch back to alpha release') if is_final and spec == "build": raise Exception("Cannot increment a build on a final release") # If this is a major release during the alpha cycle, bump # just the Python version. if "a" in prev and spec == "major": run(f"bumpversion {spec}") return # Determine the version spec to use for lerna. lerna_version = "preminor" if spec == "build": lerna_version = "prerelease" # a -> b elif spec == "release" and "a" in prev: lerna_version = "prerelease --preid=beta" # b -> rc elif spec == "release" and "b" in prev: lerna_version = "prerelease --preid=rc" # rc -> final elif spec == "release" and "c" in prev: lerna_version = "patch" if lerna_version == "preminor": lerna_version += " --preid=alpha" cmd = f"jlpm run lerna version --force-publish --no-push --no-git-tag-version {lerna_version}" if force: cmd += " --yes" # For a preminor release, we bump 10 minor versions so that we do # not conflict with versions during minor releases of the top level package. if lerna_version == "preminor": for i in range(10): run(cmd) else: run(cmd) # Bump the version. run(f"bumpversion {spec} --allow-dirty")
def bump(force, spec): status = run("git status --porcelain").strip() if len(status) > 0: raise Exception("Must be in a clean git state with no untracked files") # Make sure we have a valid version spec. if spec not in OPTIONS: raise ValueError(f"Version spec must be one of: {OPTIONS}") prev = get_version() is_final = not is_prerelease(prev) if spec == "next": spec = "patch" if is_final else "build" if spec == "patch": patch(force) return update(spec, force)
def patch(force=False): version = get_version() if is_prerelease(version): raise Exception("Can only make a patch release from a final version") run("bumpversion patch", quiet=True) # switches to alpha run("bumpversion release --allow-dirty", quiet=True) # switches to beta run("bumpversion release --allow-dirty", quiet=True) # switches to rc. run("bumpversion release --allow-dirty", quiet=True) # switches to final. # Version the changed cmd = "jlpm run lerna version patch --no-push --force-publish --no-git-tag-version" if force: cmd += " --yes" run(cmd)
def draft_release( ref, branch, repo, auth, changelog_path, version_cmd, dist_dir, dry_run, post_version_spec, assets, ): """Publish Draft GitHub release and handle post version bump""" branch = branch or util.get_branch() repo = repo or util.get_repo() assets = assets or glob(f"{dist_dir}/*") version = util.get_version() body = changelog.extract_current(changelog_path) prerelease = util.is_prerelease(version) # Bump to post version if given if post_version_spec: post_version = bump_version(post_version_spec, version_cmd) util.log(f"Bumped version to {post_version}") util.run(f'git commit -a -m "Bump to {post_version}"') if dry_run: return owner, repo_name = repo.split("/") gh = GhApi(owner=owner, repo=repo_name, token=auth) # Remove draft releases over a day old if bool(os.environ.get("GITHUB_ACTIONS")): for release in gh.repos.list_releases(): if str(release.draft).lower() == "false": continue created = release.created_at d_created = datetime.strptime(created, r"%Y-%m-%dT%H:%M:%SZ") delta = datetime.utcnow() - d_created if delta.days > 0: gh.repos.delete_release(release.id) remote_url = util.run("git config --get remote.origin.url") if not os.path.exists(remote_url): util.run(f"git push origin HEAD:{branch} --follow-tags --tags") util.log(f"Creating release for {version}") util.log(f"With assets: {assets}") release = gh.create_release( f"v{version}", branch, f"Release v{version}", body, True, prerelease, files=assets, ) # Set the GitHub action output util.actions_output("release_url", release.html_url)