Skip to content
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
135 changes: 135 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "bumpver",
# "nox",
# ]
# ///
Expand All @@ -10,9 +11,11 @@

import json
import os
import re
from pathlib import Path

import nox
from bumpver.version import to_pep440

nox.options.default_venv_backend = "uv|virtualenv"
nox.options.reuse_existing_virtualenvs = True
Expand Down Expand Up @@ -150,5 +153,137 @@ def gha_matrix(session):
print(matrix)


@nox.session
def cog(session):
COG_FILES = [
"CONTRIBUTING.md",
"README.md",
"pyproject.toml",
]
session.run(
"uv",
"run",
"--with",
"bumpver",
"--with",
"cogapp",
"--with",
"nox",
"cog",
"-r",
*COG_FILES,
)
git_status = session.run("git", "status", "--porcelain", external=True, silent=True)
if not any(cog_file in git_status for cog_file in COG_FILES):
session.log("No changes to documentation files, skipping commit")
return
session.run("git", "add", *COG_FILES, external=True)
session.run(
"git",
"commit",
"-m",
"auto-regenerate docs using cog",
external=True,
silent=True,
)


@nox.session
def process_docs(session):
session.run("uv", "run", "docs/processor.py")
session.run("git", "add", "docs/", external=True)
session.run(
"git",
"commit",
"-m",
"process docs from GHFM to mkdocs-style",
external=True,
silent=True,
)


@nox.session
def update_changelog(session):
version = get_version(session)

with open("CHANGELOG.md", "r") as f:
changelog = f.read()

changelog = changelog.replace("## [Unreleased]", f"## [{version}]", 1)
changelog = changelog.replace(
f"## [{version}]", f"## [Unreleased]\n\n## [{version}]"
)

repo_url = session.run("git", "remote", "get-url", "origin", silent=True).strip()
repo_url = repo_url.replace(".git", "")

changelog += f"\n[{version}]: {repo_url}/releases/tag/v{version}"
changelog = re.sub(
r"\[unreleased\]: .+",
f"[unreleased]: {repo_url}/compare/v{version}...HEAD",
changelog,
)

with open("CHANGELOG.md", "w") as f:
f.write(changelog)

session.run("git", "add", "CHANGELOG.md", external=True)
session.run(
"git",
"commit",
"-m",
f"update CHANGELOG for version {version}",
external=True,
silent=True,
)


@nox.session
def update_uvlock(session):
version = get_version(session)

session.run("uv", "lock")

git_status = session.run("git", "status", "--porcelain", external=True, silent=True)
if "uv.lock" not in git_status:
session.log("No changes to uv.lock, skipping commit")
return

session.run("git", "add", "uv.lock", external=True)
session.run(
"git",
"commit",
"-m",
f"update uv.lock for version {version}",
external=True,
silent=True,
)


def get_version(session):
command = ["uv", "run", "bumpver", "update", "--dry", "--no-fetch"]
if session.posargs:
args = []
for arg in session.posargs:
if arg and arg not in ["--dry", "--no-fetch"]:
args.extend(arg.split(" "))
command.extend(args)
output = session.run(*command, silent=True)
match = re.search(r"New Version: (.+)", output)
return to_pep440(match.group(1)) if match else None


@nox.session(requires=["cog", "process_docs", "update_changelog", "update_uvlock"])
def release(session):
command = ["uv", "run", "bumpver", "update"]
if session.posargs:
args = []
for arg in session.posargs:
if arg:
args.extend(arg.split(" "))
command.extend(args)
session.run(*command)


if __name__ == "__main__":
nox.main()
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ build-backend = "maturin"

[dependency-groups]
dev = [
"bumpver>=2024.1130",
"cogapp>=3.4.1",
"django-stubs>=5.1.1",
"maturin>=1.7.8",
"ruff>=0.8.2",
Expand Down Expand Up @@ -78,8 +80,8 @@ Source = "https://github.com/joshuadavidthomas/django-language-server"
commit = true
commit_message = ":bookmark: bump version {old_version} -> {new_version}"
current_version = "5.1.0-alpha.2"
push = false
tag = false
push = true
tag = true
version_pattern = "MAJOR.MINOR.PATCH[-TAG[.NUM]]"

[tool.bumpver.file_patterns]
Expand Down
46 changes: 46 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.