Skip to content

Commit 31b69aa

Browse files
add release and supporting commands to nox (#103)
1 parent a3e559c commit 31b69aa

File tree

3 files changed

+185
-2
lines changed

3 files changed

+185
-2
lines changed

noxfile.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# /// script
33
# requires-python = ">=3.13"
44
# dependencies = [
5+
# "bumpver",
56
# "nox",
67
# ]
78
# ///
@@ -10,9 +11,11 @@
1011

1112
import json
1213
import os
14+
import re
1315
from pathlib import Path
1416

1517
import nox
18+
from bumpver.version import to_pep440
1619

1720
nox.options.default_venv_backend = "uv|virtualenv"
1821
nox.options.reuse_existing_virtualenvs = True
@@ -150,5 +153,137 @@ def gha_matrix(session):
150153
print(matrix)
151154

152155

156+
@nox.session
157+
def cog(session):
158+
COG_FILES = [
159+
"CONTRIBUTING.md",
160+
"README.md",
161+
"pyproject.toml",
162+
]
163+
session.run(
164+
"uv",
165+
"run",
166+
"--with",
167+
"bumpver",
168+
"--with",
169+
"cogapp",
170+
"--with",
171+
"nox",
172+
"cog",
173+
"-r",
174+
*COG_FILES,
175+
)
176+
git_status = session.run("git", "status", "--porcelain", external=True, silent=True)
177+
if not any(cog_file in git_status for cog_file in COG_FILES):
178+
session.log("No changes to documentation files, skipping commit")
179+
return
180+
session.run("git", "add", *COG_FILES, external=True)
181+
session.run(
182+
"git",
183+
"commit",
184+
"-m",
185+
"auto-regenerate docs using cog",
186+
external=True,
187+
silent=True,
188+
)
189+
190+
191+
@nox.session
192+
def process_docs(session):
193+
session.run("uv", "run", "docs/processor.py")
194+
session.run("git", "add", "docs/", external=True)
195+
session.run(
196+
"git",
197+
"commit",
198+
"-m",
199+
"process docs from GHFM to mkdocs-style",
200+
external=True,
201+
silent=True,
202+
)
203+
204+
205+
@nox.session
206+
def update_changelog(session):
207+
version = get_version(session)
208+
209+
with open("CHANGELOG.md", "r") as f:
210+
changelog = f.read()
211+
212+
changelog = changelog.replace("## [Unreleased]", f"## [{version}]", 1)
213+
changelog = changelog.replace(
214+
f"## [{version}]", f"## [Unreleased]\n\n## [{version}]"
215+
)
216+
217+
repo_url = session.run("git", "remote", "get-url", "origin", silent=True).strip()
218+
repo_url = repo_url.replace(".git", "")
219+
220+
changelog += f"\n[{version}]: {repo_url}/releases/tag/v{version}"
221+
changelog = re.sub(
222+
r"\[unreleased\]: .+",
223+
f"[unreleased]: {repo_url}/compare/v{version}...HEAD",
224+
changelog,
225+
)
226+
227+
with open("CHANGELOG.md", "w") as f:
228+
f.write(changelog)
229+
230+
session.run("git", "add", "CHANGELOG.md", external=True)
231+
session.run(
232+
"git",
233+
"commit",
234+
"-m",
235+
f"update CHANGELOG for version {version}",
236+
external=True,
237+
silent=True,
238+
)
239+
240+
241+
@nox.session
242+
def update_uvlock(session):
243+
version = get_version(session)
244+
245+
session.run("uv", "lock")
246+
247+
git_status = session.run("git", "status", "--porcelain", external=True, silent=True)
248+
if "uv.lock" not in git_status:
249+
session.log("No changes to uv.lock, skipping commit")
250+
return
251+
252+
session.run("git", "add", "uv.lock", external=True)
253+
session.run(
254+
"git",
255+
"commit",
256+
"-m",
257+
f"update uv.lock for version {version}",
258+
external=True,
259+
silent=True,
260+
)
261+
262+
263+
def get_version(session):
264+
command = ["uv", "run", "bumpver", "update", "--dry", "--no-fetch"]
265+
if session.posargs:
266+
args = []
267+
for arg in session.posargs:
268+
if arg and arg not in ["--dry", "--no-fetch"]:
269+
args.extend(arg.split(" "))
270+
command.extend(args)
271+
output = session.run(*command, silent=True)
272+
match = re.search(r"New Version: (.+)", output)
273+
return to_pep440(match.group(1)) if match else None
274+
275+
276+
@nox.session(requires=["cog", "process_docs", "update_changelog", "update_uvlock"])
277+
def release(session):
278+
command = ["uv", "run", "bumpver", "update"]
279+
if session.posargs:
280+
args = []
281+
for arg in session.posargs:
282+
if arg:
283+
args.extend(arg.split(" "))
284+
command.extend(args)
285+
session.run(*command)
286+
287+
153288
if __name__ == "__main__":
154289
nox.main()

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ build-backend = "maturin"
44

55
[dependency-groups]
66
dev = [
7+
"bumpver>=2024.1130",
8+
"cogapp>=3.4.1",
79
"django-stubs>=5.1.1",
810
"maturin>=1.7.8",
911
"ruff>=0.8.2",
@@ -78,8 +80,8 @@ Source = "https://github.com/joshuadavidthomas/django-language-server"
7880
commit = true
7981
commit_message = ":bookmark: bump version {old_version} -> {new_version}"
8082
current_version = "5.1.0-alpha.2"
81-
push = false
82-
tag = false
83+
push = true
84+
tag = true
8385
version_pattern = "MAJOR.MINOR.PATCH[-TAG[.NUM]]"
8486

8587
[tool.bumpver.file_patterns]

uv.lock

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)