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

Add a script to bump the version #954

Merged
merged 20 commits into from
Sep 10, 2021
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
19 changes: 19 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[bumpversion]
current_version = 0, 2, 11, "final", 0
commit = False
tag = False
parse = (?P<major>\d+)\,\ (?P<minor>\d+)\,\ (?P<patch>\d+)\,\ \"(?P<release>\S+)\"\,\ (?P<build>\d+)
serialize =
{major}, {minor}, {patch}, "{release}", {build}

[bumpversion:part:release]
optional_value = final
values =
alpha
beta
candidate
final

[bumpversion:part:build]

[bumpversion:file:voila/_version.py]
23 changes: 23 additions & 0 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,63 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: 3.9
architecture: 'x64'

- name: Install node
uses: actions/setup-node@v2
with:
node-version: '14.x'

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"

- name: Cache pip
uses: actions/cache@v1
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Cache checked links
uses: actions/cache@v2
with:
path: ~/.cache/pytest-link-check
key: ${{ runner.os }}-linkcheck-${{ hashFiles('**/.md') }}-md-links
restore-keys: |
${{ runner.os }}-linkcheck-

- name: Upgrade packaging dependencies
run: |
pip install --upgrade pip setuptools wheel jupyter-packaging~=0.10 --user

- name: Install Dependencies
run: |
pip install .

- name: Configure Version Spec
id: version-spec
if: ${{ matrix.group == 'check_release' }}
run: |
set -eux
version=$(python setup.py --version)
if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
version_spec=patch
else
version_spec=build
fi
echo "::set-output name=spec::${version_spec}"

- name: Check Release
uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v1
env:
RH_VERSION_SPEC: ${{ steps.version-spec.outputs.spec }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
23 changes: 21 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ Soon, the recommended way to make a release will be to use [`jupyter_releaser`](

For now releases are still done manually (see section below).

## Bumping versions

`voila` follows a similar bump strategy as in JupyterLab:

https://github.com/jupyterlab/jupyterlab/blob/master/RELEASE.md#bump-version

To manually bump the version, run:

```bash
# install the dependencies
python -m pip install -e ".[test,dev]"

# bump the version
python scripts/bump-version.py <spec>
```

Where `<spec>` can be one of the following: `patch`, `minor`, `major`, `release`.

## Releasing on conda-forge

1. Open a new PR on https://github.com/conda-forge/voila-feedstock to update the `version` and the `sha256` hash (see [example](https://github.com/conda-forge/voila-feedstock/pull/23/files))
Expand Down Expand Up @@ -38,8 +56,9 @@ Make sure the `dist/` folder is empty.
1. If the JupyterLab extension has changed, make sure to bump the version number in `./packages/jupyterlab-preview/package.json`
2. If the Voilà front-end JavaScript has changed, make sure to bump the version number in `./packages/voila/package.json`
3. Bump the version:
- `pip install tbump@git+git://github.com/dmerejkowsky/tbump.git@03988d5d2267ddd4a33b3c4196b05b7f24f0a0a4`
- `tbump x.y.z`
- `python -m pip install bump2version jupyter-releaser`
- For a patch release: `python scripts/bump-version patch`
- For a build release: `python scripts/bump-version build`
4. `python -m build`
5. Double check the size of the bundles in the `dist/` folder
6. Make sure the JupyterLab extension is correctly bundled in source distribution
Expand Down
2 changes: 1 addition & 1 deletion packages/voila/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@voila-dashboards/voila",
"private": true,
"version": "1.0.0",
"version": "0.2.11",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now this package is still private, but will probably be released too when #846 lands

"description": "The Voilà Frontend",
"author": "Voilà contributors",
"license": "BSD-3-Clause",
Expand Down
23 changes: 8 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,15 @@ factory = "jupyter_packaging.npm_builder"
build_cmd = "build:prod"
npm = ["jlpm"]

[tool.tbump.version]
current = "0.2.11"
regex = '''
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
((?P<channel>a|b|rc|.dev)(?P<release>\d+))?
'''

[tool.tbump.git]
message_template = "Release {new_version}"
tag_template = "{new_version}"

[[tool.tbump.file]]
src = "voila/_version.py"
[tool.jupyter-releaser]
skip = ["check-links"]

[tool.jupyter-releaser.hooks]
before-build-npm = ["python -m pip install jupyterlab~=3.0", "jlpm"]
before-bump-version = ["python -m pip install bump2version jupyterlab~=3.0"]
before-build-npm = ["python -m pip install jupyterlab~=3.0", "jlpm", "jlpm build:prod"]

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

[tool.check-manifest]
ignore = [".binder/**", "docs/**", "notebooks/**", "packages/**", "share/**/*.js", "share/**/*.woff", "*.json", "*.gif", "yarn.lock", "environment.yml", "readthedocs.yml", ".*", "lint-staged.config.js", "voila/labextension/**", "voila/static/**", "tests/**", "ui-tests/**"]
ignore = [".binder/**", "docs/**", "notebooks/**", "packages/**", "share/**/*.js", "share/**/*.woff", "*.json", "*.gif", "yarn.lock", "environment.yml", "readthedocs.yml", ".*", "lint-staged.config.js", "scripts/**", "voila/labextension/**", "voila/static/**", "tests/**", "ui-tests/**"]
112 changes: 112 additions & 0 deletions scripts/bump-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# 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 run


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


def get_python_version():
"""Return the version of the voila Python package"""
import voila

return voila.__version__


def patch(force=False):
python_version = get_python_version()
if "a" in python_version or "b" in python_version or "rc" in python_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 update(spec, force=False):
prev = get_python_version()

# Make sure we have a valid version spec.
if spec not in OPTIONS:
raise Exception(f"Version spec must be one of: {OPTIONS}")

is_final = "a" not in prev and "b" not in prev and "c" not in 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")


@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")

if spec == "patch":
patch(force)
return

update(spec, force)


if __name__ == "__main__":
bump()
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ install_requires =
nbconvert>=6.0.0,<7

[options.extras_require]
dev =
black
bump2version
jupyter_releaser~=0.6

test =
ipywidgets
mock
Expand Down
32 changes: 22 additions & 10 deletions voila/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@
# The full license is in the file LICENSE, distributed with this software. #
#############################################################################

import re
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

# Version string must appear intact for tbump versioning
__version__ = '0.2.11'
from collections import namedtuple

# Build up version_info tuple for backwards compatibility
pattern = r'(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)'
match = re.match(pattern, __version__)
parts = [int(match[part]) for part in ['major', 'minor', 'patch']]
if match['rest']:
parts.append(match['rest'])
version_info = tuple(parts)
VersionInfo = namedtuple(
"VersionInfo", ["major", "minor", "micro", "releaselevel", "serial"]
)

# DO NOT EDIT THIS DIRECTLY! It is managed by bumpversion
version_info = VersionInfo(0, 2, 11, "final", 0)

_specifier_ = {"alpha": "a", "beta": "b", "candidate": "rc", "final": ""}

__version__ = "{}.{}.{}{}".format(
version_info.major,
version_info.minor,
version_info.micro,
(
""
if version_info.releaselevel == "final"
else _specifier_[version_info.releaselevel] + str(version_info.serial)
),
)