Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the script for bumping versions #47

Merged
merged 5 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@ This repository contains the two workflows located under https://github.com/voil

- Step 1: Prep Release
- Step 2: Publish Release

### Specifying a version spec

The `next` version spec is supported and will bump the packages as follows. For example:

- `0.1.0a0` -> `0.1.0a1`
- `0.1.0b7` -> `0.1.0b8`
- `0.1.0` -> `0.1.1`

You can also specify the Python version directly as the `version_spec` when using the
releaser workflows. For example:

- `0.1.0b8`
- `0.1.1`
- `1.2.0rc0`
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"build": "lerna run build",
"build:prod": "lerna run build:prod",
"build:test": "lerna run build:test",
"bump:js:version": "lerna version --no-push --force-publish --no-git-tag-version --yes",
"clean": "lerna run clean",
"eslint": "eslint . --ext .ts,.tsx,.js,.jsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx,.js,.jsx",
Expand Down
2 changes: 1 addition & 1 deletion packages/voici/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@voila-dashboards/voici",
"version": "0.4.0-alpha.0",
"version": "0.3.0",
"description": "The Voici Frontend",
"author": "Voilà contributors",
"license": "BSD-3-Clause",
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ before-bump-version = [
"python -m pip install hatch",
]
before-build-npm = [
"yarn",
"yarn clean",
"yarn build:prod",
]
Expand All @@ -114,7 +115,7 @@ before-build-python = [
]

[tool.jupyter-releaser.options]
version-cmd = "python scripts/bump-version.py --force"
version-cmd = "python scripts/bump-version.py"

[tool.check-wheel-contents]
ignore = ["W002"]
125 changes: 29 additions & 96 deletions scripts/bump-version.py
Original file line number Diff line number Diff line change
@@ -1,112 +1,45 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.import click

# Heavily inspired by:
# - https://github.com/jupyterlab/jupyterlab/blob/master/buildutils/src/bumpversion.ts
# - https://github.com/jupyterlab/retrolab/blob/main/buildutils/src/release-bump.ts

import click
from jupyter_releaser.util import is_prerelease, get_version, run


OPTIONS = ["major", "minor", "release", "build", "patch", "next"]


def patch(force=False):
version = get_version()
if is_prerelease(version):
raise Exception("Can only make a patch release from a final version")
# Copyright (c) Voici Contributors

run("hatch version patch", quiet=True)

# Version the changed
cmd = "yarn && yarn run lerna version patch --no-push --force-publish --no-git-tag-version"
if force:
cmd += " --yes"
run(cmd)


def update(spec, force=False):
prev = get_version()

is_final = not is_prerelease(prev)

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"hatch version {spec}")
return
# Distributed under the terms of the Modified BSD License.import click

# Determine the version spec to use for lerna and hatch
py_spec = spec
lerna_version = "preminor"
if spec == "build":
lerna_version = "prerelease"
if 'a' in prev:
py_spec = 'a'
elif 'b' in prev:
py_spec = 'b'
elif 'rc' in prev:
py_spec = 'rc'
# a -> b
elif spec == "release" and "a" in prev:
lerna_version = "prerelease --preid=beta"
py_spec = 'beta'
# b -> rc
elif spec == "release" and "b" in prev:
lerna_version = "prerelease --preid=rc"
py_spec = 'rc'
# rc -> final
elif spec == "release" and "c" in prev:
lerna_version = "patch"
py_spec = 'release'
elif spec == "release":
py_spec = 'minor,alpha'
import argparse
from packaging.version import parse as parse_version
from pathlib import Path
from subprocess import run

if lerna_version == "preminor":
lerna_version += " --preid=alpha"

cmd = f"yarn && yarn run lerna version --force-publish --no-push --no-git-tag-version {lerna_version}"
if force:
cmd += " --yes"
ENC = dict(encoding="utf-8")
HATCH_VERSION = "hatch version"
ROOT = Path(__file__).parent.parent

# 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 Python version
run(f"hatch version {py_spec}")
def get_version():
cmd = run([HATCH_VERSION], capture_output=True, shell=True, check=True, cwd=ROOT)
return cmd.stdout.decode("utf-8").strip().split("\n")[-1]


@click.command()
@click.option("--force", default=False, is_flag=True)
@click.argument("spec", nargs=1)
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")
def next_version():
v = parse_version(get_version())
if v.is_prerelease:
return f"{v.major}.{v.minor}.{v.micro}{v.pre[0]}{v.pre[1] + 1}"
return f"{v.major}.{v.minor}.{v.micro + 1}"

# 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"
def bump():
parser = argparse.ArgumentParser()
parser.add_argument("version")
args = parser.parse_args()
py_version = next_version() if args.version == "next" else args.version
js_version = (
py_version.replace("a", "-alpha.").replace("b", "-beta.").replace("rc", "-rc.")
)

if spec == "patch":
patch(force)
return
# bump the Python version with hatch
run(f"{HATCH_VERSION} {py_version}", shell=True, check=True, cwd=ROOT)

update(spec, force)
# bump the JS version with lerna
run(f"yarn run bump:js:version {js_version}", shell=True, check=True)


if __name__ == "__main__":
Expand Down