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

Use hatch for version bumping #668

Merged
merged 4 commits into from
Oct 18, 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
17 changes: 9 additions & 8 deletions .github/workflows/vscode-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- 'code/**'

jobs:
vscode:
build:
runs-on: ubuntu-latest
steps:
- uses: 'actions/checkout@v4'
Expand All @@ -35,20 +35,21 @@ jobs:
- run: |
python --version
python -m pip install --upgrade pip
python -m pip install --upgrade bump2version tox
python -m pip install --upgrade hatch tox towncrier 'importlib-resources<6'
name: Install Build Tools

- run: |
set -e
cd lib/esbonio
tox run -e pkg
echo "ESBONIO_WHL=$(find $(pwd)/dist -name '*.whl')" >> $GITHUB_ENV
name: Package Language Server
./scripts/make_release.py lsp
./scripts/make_release.py vscode
name: Set Versions

- run: |
set -e
./scripts/make-release.sh vscode
name: Set Versions
cd lib/esbonio
hatch build
echo "ESBONIO_WHL=$(find $(pwd)/dist -name '*.whl')" >> $GITHUB_ENV
name: Package Language Server

- run: |
set -e
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/vscode-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# This must be the minimum Python version we support
python-version: "3.8"

- name: Pip cache
- name: pip cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
Expand All @@ -39,12 +39,12 @@ jobs:

python --version
python -m pip install --upgrade pip
python -m pip install --upgrade tox bump2version towncrier docutils
python -m pip install --upgrade tox hatch towncrier docutils
name: Install Build Tools

- run: |
set -e
./scripts/make-release.sh vscode
./scripts/make_release.py vscode
name: Set Version

- run: |
Expand Down
10 changes: 0 additions & 10 deletions code/.bumpversion.cfg

This file was deleted.

59 changes: 20 additions & 39 deletions code/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,46 +1,27 @@
[project]
name = "esbonio-vscode"
dynamic = ["version"]

[tool.hatch.version]
path = "package.json"
pattern = "\\s*\"version\": \"(?P<version>[^\"]+)\""
validate-bump = false

[tool.towncrier]
filename = "CHANGES.rst"
directory = "changes/"
title_format = "v{version} - {project_date}"
issue_format = "`#{issue} <https://github.com/swyddfa/esbonio/issues/{issue}>`_"
underlines = ["-", "^", "\""]

[[tool.towncrier.type]]
directory = "breaking"
name = "Breaking Changes"
showcontent = true

[[tool.towncrier.type]]
directory = "feature"
name = "Features"
showcontent = true

[[tool.towncrier.type]]
directory = "fix"
name = "Fixes"
showcontent = true

[[tool.towncrier.type]]
directory = "doc"
name = "Docs"
showcontent = true

[[tool.towncrier.type]]
directory = "enhancement"
name = "Enhancements"
showcontent = true

[[tool.towncrier.type]]
directory = "deprecated"
name = "Deprecated"
showcontent = true

[[tool.towncrier.type]]
directory = "misc"
name = "Misc"
showcontent = true

[[tool.towncrier.type]]
directory = "removed"
name = "Removed"
showcontent = true
type = [
{ name = "Breaking Changes", directory = "breaking", showcontent = true },
{ name = "Features", directory = "feature", showcontent = true },
{ name = "Enhancements", directory = "enhancement", showcontent = true },
{ name = "API Changes", directory = "api", showcontent = true },
{ name = "Fixes", directory = "fix", showcontent = true },
{ name = "Docs", directory = "doc", showcontent = true },
{ name = "Deprecated", directory = "deprecated", showcontent = true },
{ name = "Misc", directory = "misc", showcontent = true },
{ name = "Removed", directory = "removed", showcontent = true },
]
13 changes: 11 additions & 2 deletions scripts/make_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
import argparse
import io
import json
import os
import pathlib
import re
Expand All @@ -16,6 +17,7 @@
import tempfile
from datetime import datetime
from typing import Dict
from typing import Optional
from typing import TypedDict

IS_CI = "CI" in os.environ
Expand Down Expand Up @@ -171,6 +173,13 @@ def set_version(component: Component) -> str:
dev_version = f"{version}{sep}dev{match.group(1)}"
run("hatch", "version", dev_version, cwd=component["src"])

# Annoying, but necessary since hatch normalises `-` to `.`
if component["name"] == "vscode":
package_json = pathlib.Path(component["src"]) / "package.json"
meta = json.loads(package_json.read_text())
meta["version"] = dev_version
package_json.write_text(json.dumps(meta, indent=2))

print(f"Next version: {dev_version!r}")
return dev_version

Expand All @@ -196,7 +205,7 @@ def generate_changelog(component: Component, version: str):
draft_file.write_text(draft)

with Output(STEP_SUMMARY) as summary:
draft >> summary
f"{draft}\n\n" >> summary

if not IS_RELEASE:
return
Expand Down Expand Up @@ -248,7 +257,7 @@ def commit_and_tag(component: Component, version: str) -> str:
return tag


def run(*cmd, cwd: str | None = None, capture: bool = False) -> str | None:
def run(*cmd, cwd: Optional[str] = None, capture: bool = False) -> Optional[str]:
"""Run a command"""

result = subprocess.run(cmd, cwd=cwd, capture_output=capture)
Expand Down